--- ray/src/rt/m_brdf.c 2013/08/07 05:10:09 2.30 +++ ray/src/rt/m_brdf.c 2018/01/10 17:45:11 2.35 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: m_brdf.c,v 2.30 2013/08/07 05:10:09 greg Exp $"; +static const char RCSid[] = "$Id: m_brdf.c,v 2.35 2018/01/10 17:45:11 greg Exp $"; #endif /* * Shading for materials with arbitrary BRDF's @@ -14,6 +14,7 @@ static const char RCSid[] = "$Id: m_brdf.c,v 2.30 2013 #include "otypes.h" #include "rtotypes.h" #include "func.h" +#include "pmapmat.h" /* * Arguments to this material include the color and specularity. @@ -127,7 +128,8 @@ dirbrdf( /* compute source contribution */ scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } - if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) + if ((ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) || + ambRayInPmap(np->pr)) return; /* diffuse only */ /* set up function */ setbrdfunc(np); @@ -140,17 +142,19 @@ dirbrdf( /* compute source contribution */ lddx[3] = omega; /* compute BRTDF */ if (np->mp->otype == MAT_BRTDF) { - if (sa[6][0] == '0') /* special case */ + if (sa[6][0] == '0' && !sa[6][1]) /* special case */ colval(ctmp,RED) = 0.0; else colval(ctmp,RED) = funvalue(sa[6], 4, lddx); - if (sa[7][0] == '0') + if (sa[7][0] == '0' && !sa[7][1]) colval(ctmp,GRN) = 0.0; else if (!strcmp(sa[7],sa[6])) colval(ctmp,GRN) = colval(ctmp,RED); else colval(ctmp,GRN) = funvalue(sa[7], 4, lddx); - if (!strcmp(sa[8],sa[6])) + if (sa[8][0] == '0' && !sa[8][1]) + colval(ctmp,BLU) = 0.0; + else if (!strcmp(sa[8],sa[6])) colval(ctmp,BLU) = colval(ctmp,RED); else if (!strcmp(sa[8],sa[7])) colval(ctmp,BLU) = colval(ctmp,GRN); @@ -205,8 +209,8 @@ m_brdf( /* color a ray that hit a BRDTfunc material int hitfront = 1; BRDFDAT nd; RAY sr; - double mirtest=0, mirdist=0; - double transtest=0, transdist=0; + double mirtest=0, mirdist; + double transtest=0, transdist; int hasrefl, hastrans; int hastexture; COLOR ctmp; @@ -237,7 +241,7 @@ m_brdf( /* color a ray that hit a BRDTfunc material m->oargs.farg[8]); /* get modifiers */ raytexture(r, m->omod); - hastexture = DOT(r->pert,r->pert) > FTINY*FTINY; + hastexture = (DOT(r->pert,r->pert) > FTINY*FTINY); if (hastexture) { /* perturb normal */ nd.pdot = raynormal(nd.pnorm, r); } else { @@ -255,8 +259,9 @@ m_brdf( /* color a ray that hit a BRDTfunc material copycolor(nd.mcolor, r->pcol); /* get pattern color */ multcolor(nd.rdiff, nd.mcolor); /* modify diffuse values */ multcolor(nd.tdiff, nd.mcolor); - hasrefl = bright(nd.rdiff) > FTINY; - hastrans = bright(nd.tdiff) > FTINY; + hasrefl = (bright(nd.rdiff) > FTINY); + hastrans = (bright(nd.tdiff) > FTINY); + mirdist = transdist = r->rot; /* load cal file */ nd.dp = NULL; mf = getfunc(m, 9, 0x3f, 0); @@ -269,9 +274,9 @@ m_brdf( /* color a ray that hit a BRDTfunc material if ((errno == EDOM) | (errno == ERANGE)) objerror(m, WARNING, "compute error"); else if (rayorigin(&sr, TRANS, r, ctmp) == 0) { - if (!(r->crtype & SHADOW) && hastexture) { + if (hastexture && !(r->crtype & (SHADOW|AMBIENT))) { /* perturb direction */ - VSUM(sr.rdir, r->rdir, r->pert, -.75); + VSUB(sr.rdir, r->rdir, r->pert); if (normalize(sr.rdir) == 0.0) { objerror(m, WARNING, "illegal perturbation"); VCOPY(sr.rdir, r->rdir); @@ -282,13 +287,15 @@ m_brdf( /* color a ray that hit a BRDTfunc material rayvalue(&sr); multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); - if (!hastexture) { + if (!hastexture || r->crtype & (SHADOW|AMBIENT)) { transtest = 2.0*bright(sr.rcol); transdist = r->rot + sr.rt; } } - if (r->crtype & SHADOW) /* the rest is shadow */ + if (r->crtype & SHADOW) { /* the rest is shadow */ + r->rt = transdist; return(1); + } /* compute reflected ray */ setbrdfunc(&nd); errno = 0; @@ -363,8 +370,7 @@ m_brdf2( /* color a ray that hit a BRDF material */ objerror(m, USER, "bad # arguments"); /* check for back side */ if (r->rod < 0.0) { - if (!backvis && m->otype != MAT_TFUNC - && m->otype != MAT_TDATA) { + if (!backvis) { raytrans(r); return(1); }