--- ray/src/rt/normal.c 2005/04/19 01:15:06 2.50 +++ ray/src/rt/normal.c 2010/09/26 15:51:15 2.53 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: normal.c,v 2.50 2005/04/19 01:15:06 greg Exp $"; +static const char RCSid[] = "$Id: normal.c,v 2.53 2010/09/26 15:51:15 greg Exp $"; #endif /* * normal.c - shading function for normal materials. @@ -25,6 +25,7 @@ static const char RCSid[] = "$Id: normal.c,v 2.50 2005 #endif /* estimate of Fresnel function */ #define FRESNE(ci) (exp(-5.85*(ci)) - 0.00287989916) +#define FRESTHRESH 0.017999 /* minimum specularity for approx. */ /* @@ -93,7 +94,7 @@ dirnorm( /* compute source contribution */ /* Fresnel estimate */ lrdiff = np->rdiff; ltdiff = np->tdiff; - if (np->specfl & SP_PURE && np->rspec > FTINY && + if (np->specfl & SP_PURE && np->rspec >= FRESTHRESH && (lrdiff > FTINY) | (ltdiff > FTINY)) { dtmp = 1. - FRESNE(fabs(ldot)); lrdiff *= dtmp; @@ -155,12 +156,11 @@ dirnorm( /* compute source contribution */ /* roughness + source */ dtmp = np->alpha2 + omega*(1.0/PI); /* gaussian */ - dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp) / - (PI*np->pdot*dtmp); + dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->mcolor); - dtmp *= np->tspec * omega; + dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot); scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -225,7 +225,7 @@ m_normal( /* color a ray that hit something normal * mirdist = transdist = r->rot; nd.rspec = m->oargs.farg[3]; /* compute Fresnel approx. */ - if (nd.specfl & SP_PURE && nd.rspec > FTINY) { + if (nd.specfl & SP_PURE && nd.rspec >= FRESTHRESH) { fest = FRESNE(r->rod); nd.rspec += fest*(1. - nd.rspec); } else @@ -299,6 +299,7 @@ m_normal( /* color a ray that hit something normal * if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY) for (i = 0; i < 3; i++) /* safety measure */ nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; + checknorm(nd.vrefl); } /* reflected ray */ if ((nd.specfl&(SP_REFL|SP_PURE|SP_RBLT)) == (SP_REFL|SP_PURE)) {