--- ray/src/rt/m_brdf.c 1991/06/13 13:58:16 1.9 +++ ray/src/rt/m_brdf.c 1991/06/28 10:04:02 1.12 @@ -122,7 +122,7 @@ double omega; /* light source size */ if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) return; /* no specular component */ /* set up function */ - setfunc(np->mp, np->pr); + setbrdfunc(np); sa = np->mp->oargs.sarg; errno = 0; /* transform light vector */ @@ -192,7 +192,6 @@ register RAY *r; double transtest, transdist; COLOR ctmp; double dtmp; - FVECT vec; register int i; /* check arguments */ switch (m->otype) { @@ -259,22 +258,14 @@ register RAY *r; loadfunc(m->oargs.sarg[1]); } /* set special variables */ - setfunc(m, r); - multv3(vec, nd.pnorm, funcxf.xfm); - varset("NxP", '=', vec[0]/funcxf.sca); - varset("NyP", '=', vec[1]/funcxf.sca); - varset("NzP", '=', vec[2]/funcxf.sca); - varset("RdotP", '=', nd.pdot); - varset("CrP", '=', colval(nd.mcolor,RED)); - varset("CgP", '=', colval(nd.mcolor,GRN)); - varset("CbP", '=', colval(nd.mcolor,BLU)); + setbrdfunc(&nd); /* compute transmitted ray */ if (m->otype == MAT_BRTDF && nd.tspec > FTINY) { RAY sr; errno = 0; - setcolor(ctmp, varvalue(m->oargs.sarg[0]), - varvalue(m->oargs.sarg[1]), - varvalue(m->oargs.sarg[2])); + setcolor(ctmp, varvalue(m->oargs.sarg[3]), + varvalue(m->oargs.sarg[4]), + varvalue(m->oargs.sarg[5])); scalecolor(ctmp, nd.tspec); if (errno) objerror(m, WARNING, "compute error"); @@ -302,9 +293,9 @@ register RAY *r; if (m->otype == MAT_BRTDF && nd.rspec > FTINY) { RAY sr; errno = 0; - setcolor(ctmp, varvalue(m->oargs.sarg[3]), - varvalue(m->oargs.sarg[4]), - varvalue(m->oargs.sarg[5])); + setcolor(ctmp, varvalue(m->oargs.sarg[0]), + varvalue(m->oargs.sarg[1]), + varvalue(m->oargs.sarg[2])); scalecolor(ctmp, nd.rspec); if (errno) objerror(m, WARNING, "compute error"); @@ -344,4 +335,25 @@ register RAY *r; /* check distance */ if (transtest > bright(r->rcol)) r->rt = transdist; +} + + +setbrdfunc(np) /* set up brdf function and variables */ +register BRDFDAT *np; +{ + FVECT vec; + + if (setfunc(np->mp, np->pr) == 0) + 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 : + np->pdot >= 1.0 ? 1.0 : np->pdot); + varset("CrP", '=', colval(np->mcolor,RED)); + varset("CgP", '=', colval(np->mcolor,GRN)); + varset("CbP", '=', colval(np->mcolor,BLU)); + return(1); }