--- ray/src/rt/normal.c 1990/03/27 11:40:02 1.5 +++ ray/src/rt/normal.c 1991/11/12 17:09:11 2.1 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -38,10 +38,10 @@ extern double exp(); typedef struct { OBJREC *mp; /* material pointer */ - RAY *pr; /* intersected ray */ COLOR mcolor; /* color of this material */ COLOR scolor; /* color of specular component */ FVECT vrefl; /* vector in direction of reflected ray */ + FVECT prdir; /* vector in transmitted direction */ double alpha2; /* roughness squared times 2 */ double rdiff, rspec; /* reflected specular, diffuse */ double trans; /* transmissivity */ @@ -91,7 +91,7 @@ double omega; /* light source size */ /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->scolor); - dtmp *= omega; + dtmp *= omega / np->pdot; scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -108,16 +108,17 @@ double omega; /* light source size */ if (ldot < -FTINY && np->tspec > FTINY && np->alpha2 > FTINY) { /* * Compute specular transmission. Specular transmission - * is unaffected by material color. + * is always modified by material color. */ /* roughness + source */ dtmp = np->alpha2 + omega/(2.0*PI); /* gaussian */ - dtmp = exp((DOT(np->pr->rdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp; + dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp; /* worth using? */ if (dtmp > FTINY) { - dtmp *= np->tspec * omega; - setcolor(ctmp, dtmp, dtmp, dtmp); + copycolor(ctmp, np->mcolor); + dtmp *= np->tspec * omega / np->pdot; + scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } } @@ -129,8 +130,7 @@ register OBJREC *m; register RAY *r; { NORMDAT nd; - double ldot; - double omega; + double transtest, transdist; double dtmp; COLOR ctmp; register int i; @@ -141,7 +141,6 @@ register RAY *r; if (r->crtype & SHADOW && m->otype != MAT_TRANS) return; nd.mp = m; - nd.pr = r; /* get material color */ setcolor(nd.mcolor, m->oargs.farg[0], m->oargs.farg[1], @@ -155,8 +154,10 @@ register RAY *r; /* get modifiers */ raytexture(r, m->omod); nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ + if (nd.pdot < .001) + nd.pdot = .001; /* non-zero for dirnorm() */ multcolor(nd.mcolor, r->pcol); /* modify material color */ - r->rt = r->rot; /* default ray length */ + transtest = 0; /* get specular component */ nd.rspec = m->oargs.farg[3]; @@ -183,8 +184,6 @@ register RAY *r; rayvalue(&lr); multcolor(lr.rcol, nd.scolor); addcolor(r->rcol, lr.rcol); - if (nd.rspec > 0.5 && m->omod == OVOID) - r->rt = r->rot + lr.rt; } } } @@ -193,18 +192,27 @@ register RAY *r; nd.trans = m->oargs.farg[5]*(1.0 - nd.rspec); nd.tspec = nd.trans * m->oargs.farg[6]; nd.tdiff = nd.trans - nd.tspec; + if (r->crtype & SHADOW || DOT(r->pert,r->pert) <= FTINY*FTINY) { + VCOPY(nd.prdir, r->rdir); + transtest = 2; + } else { + for (i = 0; i < 3; i++) /* perturb direction */ + nd.prdir[i] = r->rdir[i] - .75*r->pert[i]; + normalize(nd.prdir); + } } else nd.tdiff = nd.tspec = nd.trans = 0.0; /* transmitted ray */ if (nd.tspec > FTINY && nd.alpha2 <= FTINY) { RAY lr; if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) { - VCOPY(lr.rdir, r->rdir); + VCOPY(lr.rdir, nd.prdir); rayvalue(&lr); scalecolor(lr.rcol, nd.tspec); + multcolor(lr.rcol, nd.mcolor); /* modified by color */ addcolor(r->rcol, lr.rcol); - if (nd.tspec > .5) - r->rt = r->rot + lr.rt; + transtest *= bright(lr.rcol); + transdist = r->rot + lr.rt; } } if (r->crtype & SHADOW) /* the rest is shadow */ @@ -231,10 +239,13 @@ register RAY *r; scalecolor(ctmp, nd.tdiff); else scalecolor(ctmp, nd.trans); - multcolor(ctmp, nd.mcolor); + multcolor(ctmp, nd.mcolor); /* modified by color */ addcolor(r->rcol, ctmp); flipsurface(r); } /* add direct component */ direct(r, dirnorm, &nd); + /* check distance */ + if (transtest > bright(r->rcol)) + r->rt = transdist; }