--- ray/src/rt/m_brdf.c 1995/11/22 09:27:53 2.14 +++ ray/src/rt/m_brdf.c 2003/03/03 00:10:51 2.17 @@ -1,13 +1,12 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: m_brdf.c,v 2.17 2003/03/03 00:10:51 greg Exp $"; #endif - /* * Shading for materials with arbitrary BRDF's */ +#include "copyright.h" + #include "ray.h" #include "data.h" @@ -16,8 +15,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include "func.h" -extern int backvis; /* back faces visible? */ - /* * Arguments to this material include the color and specularity. * String arguments include the reflection function and files. @@ -80,6 +77,7 @@ typedef struct { } BRDFDAT; /* BRDF material data */ +static void dirbrdf(cval, np, ldir, omega) /* compute source contribution */ COLOR cval; /* returned coefficient */ register BRDFDAT *np; /* material data */ @@ -191,10 +189,12 @@ double omega; /* light source size */ } -m_brdf(m, r) /* color a ray which hit a BRDTfunc material */ +int +m_brdf(m, r) /* color a ray that hit a BRDTfunc material */ register OBJREC *m; register RAY *r; { + int hitfront = 1; BRDFDAT nd; RAY sr; double transtest, transdist; @@ -224,7 +224,7 @@ register RAY *r; setcolor(nd.tdiff, m->oargs.farg[6], m->oargs.farg[7], m->oargs.farg[8]); - /* get modifiers */ + /* get modifiers */ raytexture(r, m->omod); nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ if (r->rod < 0.0) { /* orient perturbed values */ @@ -233,6 +233,7 @@ register RAY *r; nd.pnorm[i] = -nd.pnorm[i]; r->pert[i] = -r->pert[i]; } + hitfront = 0; } copycolor(nd.mcolor, r->pcol); /* get pattern color */ multcolor(nd.rdiff, nd.mcolor); /* modify diffuse values */ @@ -290,31 +291,24 @@ register RAY *r; } /* compute ambient */ if (hasrefl) { - if (nd.pdot < 0.0) { + if (!hitfront) flipsurface(r); - vtmp[0] = -nd.pnorm[0]; - vtmp[1] = -nd.pnorm[1]; - vtmp[2] = -nd.pnorm[2]; - } else - VCOPY(vtmp, nd.pnorm); - ambient(ctmp, r, vtmp); + ambient(ctmp, r, nd.pnorm); multcolor(ctmp, nd.rdiff); addcolor(r->rcol, ctmp); /* add to returned color */ - if (nd.pdot < 0.0) + if (!hitfront) flipsurface(r); } if (hastrans) { /* from other side */ - if (nd.pdot > 0.0) { + if (hitfront) flipsurface(r); - vtmp[0] = -nd.pnorm[0]; - vtmp[1] = -nd.pnorm[1]; - vtmp[2] = -nd.pnorm[2]; - } else - VCOPY(vtmp, nd.pnorm); + vtmp[0] = -nd.pnorm[0]; + vtmp[1] = -nd.pnorm[1]; + vtmp[2] = -nd.pnorm[2]; ambient(ctmp, r, vtmp); multcolor(ctmp, nd.tdiff); addcolor(r->rcol, ctmp); - if (nd.pdot > 0.0) + if (hitfront) flipsurface(r); } if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0') @@ -328,7 +322,8 @@ register RAY *r; -m_brdf2(m, r) /* color a ray which hit a BRDF material */ +int +m_brdf2(m, r) /* color a ray that hit a BRDF material */ register OBJREC *m; register RAY *r; { @@ -343,6 +338,18 @@ register RAY *r; if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs < (m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4)) objerror(m, USER, "bad # arguments"); + /* check for back side */ + if (r->rod < 0.0) { + if (!backvis && m->otype != MAT_TFUNC + && m->otype != MAT_TDATA) { + raytrans(r); + return(1); + } + raytexture(r, m->omod); + flipsurface(r); /* reorient if backvis */ + } else + raytexture(r, m->omod); + nd.mp = m; nd.pr = r; /* get material color */ @@ -364,17 +371,6 @@ register RAY *r; /* compute reflectance */ dtmp = 1.0 - nd.trans - nd.rspec; setcolor(nd.rdiff, dtmp, dtmp, dtmp); - /* check for back side */ - if (r->rod < 0.0) { - if (!backvis && m->otype != MAT_TFUNC - && m->otype != MAT_TDATA) { - raytrans(r); - return(1); - } - flipsurface(r); /* reorient if backvis */ - } - /* get modifiers */ - raytexture(r, m->omod); nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ multcolor(nd.mcolor, r->pcol); /* modify material color */ multcolor(nd.rdiff, nd.mcolor); @@ -412,6 +408,7 @@ register RAY *r; } +int setbrdfunc(np) /* set up brdf function and variables */ register BRDFDAT *np; {