--- ray/src/rt/normal.c 2015/05/26 13:21:07 2.71 +++ 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.71 2015/05/26 13:21:07 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. @@ -112,7 +112,7 @@ dirnorm( /* compute source contribution */ scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } - + if (ldot < -FTINY && ltdiff > FTINY) { /* * Compute diffuse transmission. @@ -122,7 +122,10 @@ dirnorm( /* compute source contribution */ 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 @@ -187,8 +190,10 @@ m_normal( /* color a ray that hit something normal * int i; /* PMAP: skip transmitted shadow ray if accounted for in photon map */ - if (shadowRayInPmap(r)) - return(1); + /* No longer needed? + if (shadowRayInPmap(r) || ambRayInPmap(r)) + return(1); */ + /* easy shadow test */ if (r->crtype & SHADOW && m->otype != MAT_TRANS) return(1); @@ -252,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 @@ -326,9 +331,13 @@ 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 */