--- ray/src/rt/m_brdf.c 1993/05/27 15:28:01 2.6 +++ ray/src/rt/m_brdf.c 1995/11/06 12:03:22 2.13 @@ -16,12 +16,15 @@ 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. * The BRDF is currently used just for the specular component to light * sources. Reflectance values or data coordinates are functions - * of the direction to the light source. + * of the direction to the light source. (Data modification functions + * are passed the source direction as args 2-4.) * We orient the surface towards the incoming ray, so a single * surface can be used to represent an infinitely thin object. * @@ -87,9 +90,10 @@ double omega; /* light source size */ double dtmp; COLOR ctmp; FVECT ldx; - double lddx[3], pt[MAXDIM]; + static double vldx[5], pt[MAXDIM]; register char **sa; register int i; +#define lddx (vldx+1) setcolor(cval, 0.0, 0.0, 0.0); @@ -130,31 +134,32 @@ double omega; /* light source size */ multv3(ldx, ldir, funcxf.xfm); for (i = 0; i < 3; i++) lddx[i] = ldx[i]/funcxf.sca; + lddx[3] = omega; /* compute BRTDF */ if (np->mp->otype == MAT_BRTDF) { if (sa[6][0] == '0') /* special case */ colval(ctmp,RED) = 0.0; else - colval(ctmp,RED) = funvalue(sa[6], 3, lddx); + colval(ctmp,RED) = funvalue(sa[6], 4, lddx); if (!strcmp(sa[7],sa[6])) colval(ctmp,GRN) = colval(ctmp,RED); else - colval(ctmp,GRN) = funvalue(sa[7], 3, lddx); + colval(ctmp,GRN) = funvalue(sa[7], 4, lddx); 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); else - colval(ctmp,BLU) = funvalue(sa[8], 3, lddx); + colval(ctmp,BLU) = funvalue(sa[8], 4, lddx); dtmp = bright(ctmp); } else if (np->dp == NULL) { - dtmp = funvalue(sa[0], 3, lddx); + dtmp = funvalue(sa[0], 4, lddx); setcolor(ctmp, dtmp, dtmp, dtmp); } else { for (i = 0; i < np->dp->nd; i++) - pt[i] = funvalue(sa[3+i], 3, lddx); - dtmp = datavalue(np->dp, pt); - dtmp = funvalue(sa[0], 1, &dtmp); + pt[i] = funvalue(sa[3+i], 4, lddx); + vldx[0] = datavalue(np->dp, pt); + dtmp = funvalue(sa[0], 5, vldx); setcolor(ctmp, dtmp, dtmp, dtmp); } if (errno) { @@ -182,10 +187,11 @@ double omega; /* light source size */ scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } +#undef lddx } -m_brdf(m, r) /* color a ray which hit a BRDTF material */ +m_brdf(m, r) /* color a ray which hit a BRDTfunc material */ register OBJREC *m; register RAY *r; { @@ -194,7 +200,6 @@ register RAY *r; double transtest, transdist; int hasrefl, hastrans; COLOR ctmp; - double dtmp; register MFUNC *mf; register int i; /* check arguments */ @@ -239,6 +244,7 @@ register RAY *r; /* compute transmitted ray */ setbrdfunc(&nd); transtest = 0; + transdist = r->rot; errno = 0; setcolor(ctmp, evalue(mf->ep[3]), evalue(mf->ep[4]), @@ -265,7 +271,7 @@ register RAY *r; transdist = r->rot + sr.rt; } if (r->crtype & SHADOW) /* the rest is shadow */ - return; + return(1); /* compute reflected ray */ setbrdfunc(&nd); errno = 0; @@ -285,7 +291,7 @@ register RAY *r; if (hasrefl) { if (nd.pdot < 0.0) flipsurface(r); - ambient(ctmp, r); + ambient(ctmp, r, nd.pnorm); multcolor(ctmp, nd.rdiff); addcolor(r->rcol, ctmp); /* add to returned color */ if (nd.pdot < 0.0) @@ -294,7 +300,7 @@ register RAY *r; if (hastrans) { /* from other side */ if (nd.pdot > 0.0) flipsurface(r); - ambient(ctmp, r); + ambient(ctmp, r, nd.pnorm); multcolor(ctmp, nd.tdiff); addcolor(r->rcol, ctmp); if (nd.pdot > 0.0) @@ -305,6 +311,8 @@ register RAY *r; /* check distance */ if (transtest > bright(r->rcol)) r->rt = transdist; + + return(1); } @@ -318,7 +326,7 @@ register RAY *r; double dtmp; /* always a shadow */ if (r->crtype & SHADOW) - return; + return(1); /* check arguments */ if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs < (m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4)) @@ -344,9 +352,15 @@ register RAY *r; /* compute reflectance */ dtmp = 1.0 - nd.trans - nd.rspec; setcolor(nd.rdiff, dtmp, dtmp, dtmp); - /* fix orientation */ - if (r->rod < 0.0) - flipsurface(r); + /* 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 */ @@ -363,14 +377,14 @@ register RAY *r; } /* compute ambient */ if (nd.trans < 1.0-FTINY) { - ambient(ctmp, r); + ambient(ctmp, r, nd.pnorm); scalecolor(ctmp, 1.0-nd.trans); multcolor(ctmp, nd.mcolor); /* modified by material color */ addcolor(r->rcol, ctmp); /* add to returned color */ } if (nd.trans > FTINY) { /* from other side */ flipsurface(r); - ambient(ctmp, r); + ambient(ctmp, r, nd.pnorm); scalecolor(ctmp, nd.trans); multcolor(ctmp, nd.mcolor); addcolor(r->rcol, ctmp); @@ -378,6 +392,8 @@ register RAY *r; } /* add direct component */ direct(r, dirbrdf, &nd); + + return(1); }