--- ray/src/rt/m_brdf.c 2005/04/19 01:15:06 2.23 +++ ray/src/rt/m_brdf.c 2012/07/29 21:56:16 2.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: m_brdf.c,v 2.23 2005/04/19 01:15:06 greg Exp $"; +static const char RCSid[] = "$Id: m_brdf.c,v 2.28 2012/07/29 21:56:16 greg Exp $"; #endif /* * Shading for materials with arbitrary BRDF's @@ -77,8 +77,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 +88,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); @@ -129,7 +128,7 @@ dirbrdf( /* compute source contribution */ addcolor(cval, ctmp); } if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) - return; /* no specular component */ + return; /* diffuse only */ /* set up function */ setbrdfunc(np); sa = np->mp->oargs.sarg; @@ -145,7 +144,9 @@ dirbrdf( /* compute source contribution */ colval(ctmp,RED) = 0.0; else colval(ctmp,RED) = funvalue(sa[6], 4, lddx); - if (!strcmp(sa[7],sa[6])) + if (sa[7][0] == '0') + 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); @@ -166,7 +167,7 @@ dirbrdf( /* compute source contribution */ dtmp = funvalue(sa[0], 5, vldx); setcolor(ctmp, dtmp, dtmp, dtmp); } - if (errno == EDOM || errno == ERANGE) { + if ((errno == EDOM) | (errno == ERANGE)) { objerror(np->mp, WARNING, "compute error"); return; } @@ -195,10 +196,10 @@ 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; @@ -211,8 +212,8 @@ m_brdf( /* color a ray that hit a BRDTfunc material 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"); @@ -265,12 +266,12 @@ m_brdf( /* color a ray that hit a BRDTfunc material setcolor(ctmp, evalue(mf->ep[3]), evalue(mf->ep[4]), evalue(mf->ep[5])); - if (errno == EDOM || errno == ERANGE) + if ((errno == EDOM) | (errno == ERANGE)) 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); @@ -294,11 +295,11 @@ m_brdf( /* color a ray that hit a BRDTfunc material setcolor(ctmp, evalue(mf->ep[0]), evalue(mf->ep[1]), evalue(mf->ep[2])); - if (errno == EDOM || errno == ERANGE) + 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); @@ -343,10 +344,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; @@ -432,7 +433,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;