--- ray/src/rt/m_brdf.c 2007/09/07 15:25:01 2.25 +++ ray/src/rt/m_brdf.c 2015/09/02 18:59:01 2.33 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: m_brdf.c,v 2.25 2007/09/07 15:25:01 greg Exp $"; +static const char RCSid[] = "$Id: m_brdf.c,v 2.33 2015/09/02 18:59:01 greg Exp $"; #endif /* * Shading for materials with arbitrary BRDF's @@ -14,6 +14,7 @@ static const char RCSid[] = "$Id: m_brdf.c,v 2.25 2007 #include "otypes.h" #include "rtotypes.h" #include "func.h" +#include "pmapmat.h" /* * Arguments to this material include the color and specularity. @@ -38,12 +39,12 @@ static const char RCSid[] = "$Id: m_brdf.c,v 2.25 2007 * Arguments for MAT_TFUNC are: * 2+ func funcfile transform * 0 - * 4+ red grn blu rspec trans tspec A7 .. + * 6+ red grn blu rspec trans tspec A7 .. * * Arguments for MAT_TDATA are: * 4+ func datafile funcfile v0 .. transform * 0 - * 4+ red grn blu rspec trans tspec A7 .. + * 6+ red grn blu rspec trans tspec A7 .. * * Arguments for the more general MAT_BRTDF are: * 10+ rrefl grefl brefl @@ -77,8 +78,7 @@ typedef struct { } BRDFDAT; /* BRDF material data */ -static srcdirf_t dirbrdf; -static int setbrdfunc(BRDFDAT *np); +static int setbrdfunc(BRDFDAT *np); static void @@ -89,14 +89,14 @@ dirbrdf( /* compute source contribution */ double omega /* light source size */ ) { - register BRDFDAT *np = nnp; + BRDFDAT *np = nnp; double ldot; double dtmp; COLOR ctmp; FVECT ldx; static double vldx[5], pt[MAXDIM]; - register char **sa; - register int i; + char **sa; + int i; #define lddx (vldx+1) setcolor(cval, 0.0, 0.0, 0.0); @@ -128,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); @@ -141,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); @@ -197,24 +200,24 @@ dirbrdf( /* compute source contribution */ } -extern int +int m_brdf( /* color a ray that hit a BRDTfunc material */ - register OBJREC *m, - register RAY *r + OBJREC *m, + RAY *r ) { int hitfront = 1; BRDFDAT nd; RAY sr; double mirtest=0, mirdist=0; - double transtest, transdist; + double transtest=0, transdist=0; int hasrefl, hastrans; int hastexture; COLOR ctmp; FVECT vtmp; double d; - register MFUNC *mf; - register int i; + MFUNC *mf; + int i; /* check arguments */ if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9)) objerror(m, USER, "bad # arguments"); @@ -271,8 +274,8 @@ m_brdf( /* color a ray that hit a BRDTfunc material objerror(m, WARNING, "compute error"); else if (rayorigin(&sr, TRANS, r, ctmp) == 0) { if (!(r->crtype & SHADOW) && hastexture) { - for (i = 0; i < 3; i++) /* perturb direction */ - sr.rdir[i] = r->rdir[i] - .75*r->pert[i]; + /* perturb direction */ + VSUM(sr.rdir, r->rdir, r->pert, -.75); if (normalize(sr.rdir) == 0.0) { objerror(m, WARNING, "illegal perturbation"); VCOPY(sr.rdir, r->rdir); @@ -299,8 +302,8 @@ m_brdf( /* color a ray that hit a BRDTfunc material if ((errno == EDOM) | (errno == ERANGE)) objerror(m, WARNING, "compute error"); else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) { - for (i = 0; i < 3; i++) - sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i]; + VSUM(sr.rdir, r->rdir, nd.pnorm, 2.*nd.pdot); + checknorm(sr.rdir); rayvalue(&sr); multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); @@ -345,10 +348,10 @@ m_brdf( /* color a ray that hit a BRDTfunc material -extern int +int m_brdf2( /* color a ray that hit a BRDF material */ - register OBJREC *m, - register RAY *r + OBJREC *m, + RAY *r ) { BRDFDAT nd; @@ -364,8 +367,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); } @@ -434,7 +436,7 @@ m_brdf2( /* color a ray that hit a BRDF material */ static int setbrdfunc( /* set up brdf function and variables */ - register BRDFDAT *np + BRDFDAT *np ) { FVECT vec;