--- ray/src/rt/normal.c 2004/03/30 16:13:01 2.47 +++ ray/src/rt/normal.c 2005/01/05 19:34:11 2.49 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: normal.c,v 2.47 2004/03/30 16:13:01 schorsch Exp $"; +static const char RCSid[] = "$Id: normal.c,v 2.49 2005/01/05 19:34:11 greg Exp $"; #endif /* * normal.c - shading function for normal materials. @@ -78,7 +78,7 @@ dirnorm( /* compute source contribution */ { register NORMDAT *np = nnp; double ldot; - double ldiff; + double lrdiff, ltdiff; double dtmp, d2; FVECT vtmp; COLOR ctmp; @@ -91,18 +91,23 @@ dirnorm( /* compute source contribution */ return; /* wrong side */ /* Fresnel estimate */ - ldiff = np->rdiff; - if (np->specfl & SP_PURE && (np->rspec > FTINY) & (ldiff > FTINY)) - ldiff *= 1. - FRESNE(fabs(ldot)); + lrdiff = np->rdiff; + ltdiff = np->tdiff; + if (np->specfl & SP_PURE && np->rspec > FTINY && + (lrdiff > FTINY) | (ltdiff > FTINY)) { + dtmp = 1. - FRESNE(fabs(ldot)); + lrdiff *= dtmp; + ltdiff *= dtmp; + } - if (ldot > FTINY && ldiff > FTINY) { + if (ldot > FTINY && lrdiff > FTINY) { /* * 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 * ldiff / PI; + dtmp = ldot * omega * lrdiff * (1.0/PI); scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -115,7 +120,7 @@ dirnorm( /* compute source contribution */ dtmp = np->alpha2; /* + source if flat */ if (np->specfl & SP_FLAT) - dtmp += omega/(4.0*PI); + dtmp += omega * (0.25/PI); /* half vector */ vtmp[0] = ldir[0] - np->rp->rdir[0]; vtmp[1] = ldir[1] - np->rp->rdir[1]; @@ -124,21 +129,21 @@ dirnorm( /* compute source contribution */ d2 *= d2; d2 = (DOT(vtmp,vtmp) - d2) / d2; /* gaussian */ - dtmp = exp(-d2/dtmp)/(4.*PI*dtmp); + dtmp = exp(-d2/dtmp)/(4.*PI * np->pdot * dtmp); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->scolor); - dtmp *= omega * sqrt(ldot/np->pdot); + dtmp *= omega; scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } } - if (ldot < -FTINY && np->tdiff > FTINY) { + if (ldot < -FTINY && ltdiff > FTINY) { /* * Compute diffuse transmission. */ copycolor(ctmp, np->mcolor); - dtmp = -ldot * omega * np->tdiff / PI; + dtmp = -ldot * omega * ltdiff * (1.0/PI); scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -148,13 +153,14 @@ dirnorm( /* compute source contribution */ * is always modified by material color. */ /* roughness + source */ - dtmp = np->alpha2 + omega/PI; + dtmp = np->alpha2 + omega*(1.0/PI); /* gaussian */ - dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp); + dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp) / + (PI*np->pdot*dtmp); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->mcolor); - dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot); + dtmp *= np->tspec * omega; scalecolor(ctmp, dtmp); addcolor(cval, ctmp); }