--- ray/src/rt/normal.c 1989/06/07 08:35:14 1.3 +++ ray/src/rt/normal.c 1991/10/30 10:59:42 1.13 @@ -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"; @@ -70,9 +70,9 @@ double omega; /* light source size */ if (ldot > FTINY && np->rdiff > FTINY) { /* - * Compute and add diffuse component to returned color. - * The diffuse component will always be modified by the - * color of the material. + * Compute and add diffuse reflected component to returned + * color. The diffuse reflected component will always be + * modified by the color of the material. */ copycolor(ctmp, np->mcolor); dtmp = ldot * omega * np->rdiff / PI; @@ -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); } @@ -107,7 +107,8 @@ double omega; /* light source size */ } if (ldot < -FTINY && np->tspec > FTINY && np->alpha2 > FTINY) { /* - * Compute specular transmission. + * Compute specular transmission. Specular transmission + * is always modified by material color. */ /* roughness + source */ dtmp = np->alpha2 + omega/(2.0*PI); @@ -116,7 +117,7 @@ double omega; /* light source size */ /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->mcolor); - dtmp *= np->tspec * omega; + 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; @@ -155,7 +155,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 */ + transtest = 0; /* get specular component */ nd.rspec = m->oargs.farg[3]; @@ -196,10 +199,22 @@ register RAY *r; if (nd.tspec > FTINY && nd.alpha2 <= FTINY) { RAY lr; if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) { - VCOPY(lr.rdir, r->rdir); + if (!(r->crtype & SHADOW) && + DOT(r->pert,r->pert) > FTINY*FTINY) { + for (i = 0; i < 3; i++) /* perturb direction */ + lr.rdir[i] = r->rdir[i] - + .75*r->pert[i]; + normalize(lr.rdir); + } else { + VCOPY(lr.rdir, r->rdir); + transtest = 2; + } rayvalue(&lr); scalecolor(lr.rcol, nd.tspec); + multcolor(lr.rcol, nd.mcolor); /* modified by color */ addcolor(r->rcol, lr.rcol); + transtest *= bright(lr.rcol); + transdist = r->rot + lr.rt; } } if (r->crtype & SHADOW) /* the rest is shadow */ @@ -226,10 +241,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; }