--- ray/src/rt/m_brdf.c 2015/09/02 18:59:01 2.33 +++ ray/src/rt/m_brdf.c 2019/04/19 19:01:32 2.39 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: m_brdf.c,v 2.33 2015/09/02 18:59:01 greg Exp $"; +static const char RCSid[] = "$Id: m_brdf.c,v 2.39 2019/04/19 19:01:32 greg Exp $"; #endif /* * Shading for materials with arbitrary BRDF's @@ -209,8 +209,6 @@ 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; int hasrefl, hastrans; int hastexture; COLOR ctmp; @@ -241,7 +239,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 { @@ -259,8 +257,8 @@ 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); /* load cal file */ nd.dp = NULL; mf = getfunc(m, 9, 0x3f, 0); @@ -273,9 +271,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); @@ -286,13 +284,13 @@ m_brdf( /* color a ray that hit a BRDTfunc material rayvalue(&sr); multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); - if (!hastexture) { - transtest = 2.0*bright(sr.rcol); - transdist = r->rot + sr.rt; - } + if ((!hastexture || r->crtype & (SHADOW|AMBIENT)) && + nd.tspec > bright(nd.tdiff) + bright(nd.rdiff)) + r->rxt = r->rot + raydistance(&sr); } if (r->crtype & SHADOW) /* the rest is shadow */ return(1); + /* compute reflected ray */ setbrdfunc(&nd); errno = 0; @@ -306,11 +304,12 @@ m_brdf( /* color a ray that hit a BRDTfunc material checknorm(sr.rdir); rayvalue(&sr); multcolor(sr.rcol, sr.rcoef); + copycolor(r->mcol, sr.rcol); addcolor(r->rcol, sr.rcol); - if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) { - mirtest = 2.0*bright(sr.rcol); - mirdist = r->rot + sr.rt; - } + r->rmt = r->rot; + if (r->ro != NULL && isflat(r->ro->otype) && + !hastexture | (r->crtype & AMBIENT)) + r->rmt += raydistance(&sr); } /* compute ambient */ if (hasrefl) { @@ -337,12 +336,6 @@ m_brdf( /* color a ray that hit a BRDTfunc material if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0') direct(r, dirbrdf, &nd); /* add direct component */ - d = bright(r->rcol); /* set effective distance */ - if (transtest > d) - r->rt = transdist; - else if (mirtest > d) - r->rt = mirdist; - return(1); } @@ -416,7 +409,7 @@ m_brdf2( /* color a ray that hit a BRDF material */ multambient(ctmp, r, nd.pnorm); addcolor(r->rcol, ctmp); /* add to returned color */ } - if (nd.trans > FTINY) { /* from other side */ + if (nd.trans > FTINY) { /* from other side */ flipsurface(r); vtmp[0] = -nd.pnorm[0]; vtmp[1] = -nd.pnorm[1]; @@ -445,10 +438,10 @@ setbrdfunc( /* set up brdf function and variables */ return(0); /* it's OK, setfunc says we're done */ /* else (re)assign special variables */ multv3(vec, np->pnorm, funcxf.xfm); - varset("NxP", '=', vec[0]/funcxf.sca); - varset("NyP", '=', vec[1]/funcxf.sca); - varset("NzP", '=', vec[2]/funcxf.sca); - varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 : + varset("NxP`", '=', vec[0]/funcxf.sca); + varset("NyP`", '=', vec[1]/funcxf.sca); + varset("NzP`", '=', vec[2]/funcxf.sca); + varset("RdotP`", '=', np->pdot <= -1.0 ? -1.0 : np->pdot >= 1.0 ? 1.0 : np->pdot); varset("CrP", '=', colval(np->mcolor,RED)); varset("CgP", '=', colval(np->mcolor,GRN));