--- ray/src/rt/normal.c 2014/05/10 17:43:01 2.67 +++ ray/src/rt/normal.c 2018/01/10 04:08:50 2.76 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: normal.c,v 2.67 2014/05/10 17:43:01 greg Exp $"; +static const char RCSid[] = "$Id: normal.c,v 2.76 2018/01/10 04:08:50 greg Exp $"; #endif /* * normal.c - shading function for normal materials. @@ -19,6 +19,7 @@ static const char RCSid[] = "$Id: normal.c,v 2.67 2014 #include "otypes.h" #include "rtotypes.h" #include "random.h" +#include "pmapmat.h" #ifndef MAXITER #define MAXITER 10 /* maximum # specular ray attempts */ @@ -111,6 +112,20 @@ dirnorm( /* compute source contribution */ scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } + + if (ldot < -FTINY && ltdiff > FTINY) { + /* + * Compute diffuse transmission. + */ + copycolor(ctmp, np->mcolor); + dtmp = -ldot * omega * ltdiff * (1.0/PI); + scalecolor(ctmp, dtmp); + addcolor(cval, ctmp); + } + + if (ambRayInPmap(np->rp)) + return; /* specular already in photon map */ + if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE)) == SP_REFL) { /* * Compute specular reflection coefficient using @@ -137,15 +152,8 @@ dirnorm( /* compute source contribution */ addcolor(cval, ctmp); } } - if (ldot < -FTINY && ltdiff > FTINY) { - /* - * Compute diffuse transmission. - */ - copycolor(ctmp, np->mcolor); - dtmp = -ldot * omega * ltdiff * (1.0/PI); - scalecolor(ctmp, dtmp); - addcolor(cval, ctmp); - } + + if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_PURE)) == SP_TRAN) { /* * Compute specular transmission. Specular transmission @@ -180,6 +188,12 @@ m_normal( /* color a ray that hit something normal * double d; COLOR ctmp; int i; + + /* PMAP: skip transmitted shadow ray if accounted for in photon map */ + /* No longer needed? + if (shadowRayInPmap(r) || ambRayInPmap(r)) + return(1); */ + /* easy shadow test */ if (r->crtype & SHADOW && m->otype != MAT_TRANS) return(1); @@ -243,8 +257,8 @@ m_normal( /* color a ray that hit something normal * VCOPY(nd.prdir, r->rdir); transtest = 2; } else { - for (i = 0; i < 3; i++) /* perturb */ - nd.prdir[i] = r->rdir[i] - r->pert[i]; + /* perturb */ + VSUB(nd.prdir, r->rdir, r->pert); if (DOT(nd.prdir, r->ron) < -FTINY) normalize(nd.prdir); /* OK */ else @@ -254,6 +268,7 @@ m_normal( /* color a ray that hit something normal * } else nd.tdiff = nd.tspec = nd.trans = 0.0; /* transmitted ray */ + if ((nd.specfl&(SP_TRAN|SP_PURE|SP_TBLT)) == (SP_TRAN|SP_PURE)) { RAY lr; copycolor(lr.rcoef, nd.mcolor); /* modified by color */ @@ -316,11 +331,15 @@ m_normal( /* color a ray that hit something normal * /* diffuse reflection */ nd.rdiff = 1.0 - nd.trans - nd.rspec; - if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) + if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) { + if (mirtest > transtest+FTINY) + r->rt = mirdist; + else if (transtest > FTINY) + r->rt = transdist; return(1); /* 100% pure specular */ - + } if (!(nd.specfl & SP_PURE)) - gaussamp(&nd); /* checks *BLT flags */ + gaussamp(&nd); /* checks *BLT flags */ if (nd.rdiff > FTINY) { /* ambient from this side */ copycolor(ctmp, nd.mcolor); /* modified by material color */ @@ -378,13 +397,7 @@ gaussamp( /* sample Gaussian specular */ (np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN) return; /* set up sample coordinates */ - v[0] = v[1] = v[2] = 0.0; - for (i = 0; i < 3; i++) - if (np->pnorm[i] < 0.6 && np->pnorm[i] > -0.6) - break; - v[i] = 1.0; - fcross(u, v, np->pnorm); - normalize(u); + getperpendicular(u, np->pnorm, rand_samp); fcross(v, np->pnorm, u); /* compute reflection */ if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&