ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_brdf.c
(Generate patch)

Comparing ray/src/rt/m_brdf.c (file contents):
Revision 1.6 by greg, Tue May 7 17:45:47 1991 UTC vs.
Revision 2.2 by greg, Mon Nov 25 09:51:03 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "otypes.h"
16  
17 + #include  "func.h"
18 +
19   /*
20   *      Arguments to this material include the color and specularity.
21   *  String arguments include the reflection function and files.
# Line 58 | Line 60 | static char SCCSid[] = "$SunId$ LBL";
60   *              CrP, CgP, CbP -         perturbed material color
61   */
62  
61 extern double   funvalue(), varvalue();
62 extern XF  funcxf;
63
63   typedef struct {
64          OBJREC  *mp;            /* material pointer */
65          RAY  *pr;               /* intersected ray */
# Line 122 | Line 121 | double  omega;                 /* light source size */
121          if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY)
122                  return;         /* no specular component */
123                                          /* set up function */
124 <        setfunc(np->mp, np->pr);
124 >        setbrdfunc(np);
125          sa = np->mp->oargs.sarg;
126          errno = 0;
127                                          /* transform light vector */
# Line 132 | Line 131 | double  omega;                 /* light source size */
131                                          /* compute BRTDF */
132          if (np->mp->otype == MAT_BRTDF) {
133                  colval(ctmp,RED) = funvalue(sa[6], 3, ldx);
134 <                if (sa[7] == sa[6])
134 >                if (!strcmp(sa[7],sa[6]))
135                          colval(ctmp,GRN) = colval(ctmp,RED);
136                  else
137                          colval(ctmp,GRN) = funvalue(sa[7], 3, ldx);
138 <                if (sa[8] == sa[6])
138 >                if (!strcmp(sa[8],sa[6]))
139                          colval(ctmp,BLU) = colval(ctmp,RED);
140 <                else if (sa[8] == sa[7])
140 >                else if (!strcmp(sa[8],sa[7]))
141                          colval(ctmp,BLU) = colval(ctmp,GRN);
142                  else
143                          colval(ctmp,BLU) = funvalue(sa[8], 3, ldx);
# Line 153 | Line 152 | double  omega;                 /* light source size */
152                  dtmp = funvalue(sa[0], 1, &dtmp);
153                  setcolor(ctmp, dtmp, dtmp, dtmp);
154          }
155 <        if (errno)
156 <                goto computerr;
155 >        if (errno) {
156 >                objerror(np->mp, WARNING, "compute error");
157 >                return;
158 >        }
159          if (dtmp <= FTINY)
160                  return;
161          if (ldot > 0.0) {
# Line 176 | Line 177 | double  omega;                 /* light source size */
177                  scalecolor(ctmp, dtmp);
178                  addcolor(cval, ctmp);
179          }
179        return;
180 computerr:
181        objerror(np->mp, WARNING, "compute error");
182        return;
180   }
181  
182  
# Line 189 | Line 186 | register RAY  *r;
186   {
187          int  minsa, minfa;
188          BRDFDAT  nd;
189 +        double  transtest, transdist;
190          COLOR  ctmp;
191 <        double  dtmp;
192 <        FVECT  vec;
191 >        double  dtmp, tspect, rspecr;
192 >        MFUNC  *mf;
193          register int  i;
194                                                  /* check arguments */
195          switch (m->otype) {
# Line 236 | Line 234 | register RAY  *r;
234          raytexture(r, m->omod);
235          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
236          multcolor(nd.mcolor, r->pcol);          /* modify material color */
237 <        r->rt = r->rot;                         /* default ray length */
237 >        transtest = 0;
238                                                  /* load auxiliary files */
239 <        if (m->otype == MAT_PDATA || m->otype == MAT_MDATA
242 <                        || m->otype == MAT_TDATA) {
239 >        if (hasdata(m->otype)) {
240                  nd.dp = getdata(m->oargs.sarg[1]);
241 <                for (i = 3; i < m->oargs.nsargs; i++)
242 <                        if (m->oargs.sarg[i][0] == '-')
246 <                                break;
247 <                if (i-3 != nd.dp->nd)
248 <                        objerror(m, USER, "dimension error");
249 <                if (!fundefined(m->oargs.sarg[3]))
250 <                        loadfunc(m->oargs.sarg[2]);
241 >                i = (1 << nd.dp->nd) - 1;
242 >                mf = getfunc(m, 2, i<<3, 0);
243          } else if (m->otype == MAT_BRTDF) {
244                  nd.dp = NULL;
245 <                if (!fundefined(m->oargs.sarg[7]))
254 <                        loadfunc(m->oargs.sarg[9]);
245 >                mf = getfunc(m, 9, 0x3f, 0);
246          } else {
247                  nd.dp = NULL;
248 <                if (!fundefined(m->oargs.sarg[0]))
258 <                        loadfunc(m->oargs.sarg[1]);
248 >                mf = getfunc(m, 1, 0, 0);
249          }
250                                                  /* set special variables */
251 <        setfunc(m, r);
262 <        multv3(vec, nd.pnorm, funcxf.xfm);
263 <        varset("NxP", '=', vec[0]/funcxf.sca);
264 <        varset("NyP", '=', vec[1]/funcxf.sca);
265 <        varset("NzP", '=', vec[2]/funcxf.sca);
266 <        varset("RdotP", '=', nd.pdot);
267 <        varset("CrP", '=', colval(nd.mcolor,RED));
268 <        varset("CgP", '=', colval(nd.mcolor,GRN));
269 <        varset("CbP", '=', colval(nd.mcolor,BLU));
251 >        setbrdfunc(&nd);
252                                                  /* compute transmitted ray */
253 +        tspect = 0.;
254          if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
255                  RAY  sr;
256                  errno = 0;
257 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
258 <                                varvalue(m->oargs.sarg[1]),
259 <                                varvalue(m->oargs.sarg[2]));
260 <                scalecolor(ctmp, nd.tspec);
257 >                setcolor(ctmp, evalue(mf->ep[3]),
258 >                                evalue(mf->ep[4]),
259 >                                evalue(mf->ep[5]));
260 >                scalecolor(ctmp, nd.trans);
261                  if (errno)
262                          objerror(m, WARNING, "compute error");
263 <                else if ((dtmp = bright(ctmp)) > FTINY &&
264 <                                rayorigin(&sr, r, TRANS, dtmp) == 0) {
265 <                        VCOPY(sr.rdir, r->rdir);
263 >                else if ((tspect = bright(ctmp)) > FTINY &&
264 >                                rayorigin(&sr, r, TRANS, tspect) == 0) {
265 >                        if (!(r->crtype & SHADOW) &&
266 >                                        DOT(r->pert,r->pert) > FTINY*FTINY) {
267 >                                for (i = 0; i < 3; i++) /* perturb direction */
268 >                                        sr.rdir[i] = r->rdir[i] -
269 >                                                        .75*r->pert[i];
270 >                                normalize(sr.rdir);
271 >                        } else {
272 >                                VCOPY(sr.rdir, r->rdir);
273 >                                transtest = 2;
274 >                        }
275                          rayvalue(&sr);
276                          multcolor(sr.rcol, ctmp);
277                          addcolor(r->rcol, sr.rcol);
278 <                        if (dtmp > .5)
279 <                                r->rt = r->rot + sr.rt;
278 >                        transtest *= bright(sr.rcol);
279 >                        transdist = r->rot + sr.rt;
280                  }
281          }
282          if (r->crtype & SHADOW)                 /* the rest is shadow */
283                  return;
284                                                  /* compute reflected ray */
285 +        rspecr = 0.;
286          if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
287                  RAY  sr;
288                  errno = 0;
289 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
290 <                                varvalue(m->oargs.sarg[4]),
291 <                                varvalue(m->oargs.sarg[5]));
299 <                scalecolor(ctmp, nd.rspec);
289 >                setcolor(ctmp, evalue(mf->ep[0]),
290 >                                evalue(mf->ep[1]),
291 >                                evalue(mf->ep[2]));
292                  if (errno)
293                          objerror(m, WARNING, "compute error");
294 <                else if ((dtmp = bright(ctmp)) > FTINY &&
295 <                                rayorigin(&sr, r, REFLECTED, dtmp) == 0) {
294 >                else if ((rspecr = bright(ctmp)) > FTINY &&
295 >                                rayorigin(&sr, r, REFLECTED, rspecr) == 0) {
296                          for (i = 0; i < 3; i++)
297                                  sr.rdir[i] = r->rdir[i] +
298                                                  2.0*nd.pdot*nd.pnorm[i];
# Line 310 | Line 302 | register RAY  *r;
302                  }
303          }
304                                                  /* compute ambient */
305 <        if (nd.rdiff > FTINY) {
305 >        if ((dtmp = 1.0-nd.trans-rspecr) > FTINY) {
306                  ambient(ctmp, r);
307 <                if (m->otype == MAT_BRTDF)
316 <                        scalecolor(ctmp, nd.rdiff);
317 <                else
318 <                        scalecolor(ctmp, 1.0-nd.trans);
307 >                scalecolor(ctmp, dtmp);
308                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
309                  addcolor(r->rcol, ctmp);        /* add to returned color */
310          }
311 <        if (nd.tdiff > FTINY) {                 /* from other side */
311 >        if ((dtmp = nd.trans-tspect) > FTINY) { /* from other side */
312                  flipsurface(r);
313                  ambient(ctmp, r);
314 <                if (m->otype == MAT_BRTDF)
326 <                        scalecolor(ctmp, nd.tdiff);
327 <                else
328 <                        scalecolor(ctmp, nd.trans);
314 >                scalecolor(ctmp, dtmp);
315                  multcolor(ctmp, nd.mcolor);
316                  addcolor(r->rcol, ctmp);
317                  flipsurface(r);
318          }
319                                                  /* add direct component */
320          direct(r, dirbrdf, &nd);
321 +                                                /* check distance */
322 +        if (transtest > bright(r->rcol))
323 +                r->rt = transdist;
324 + }
325 +
326 +
327 + setbrdfunc(np)                  /* set up brdf function and variables */
328 + register BRDFDAT  *np;
329 + {
330 +        FVECT  vec;
331 +
332 +        if (setfunc(np->mp, np->pr) == 0)
333 +                return(0);      /* it's OK, setfunc says we're done */
334 +                                /* else (re)assign special variables */
335 +        multv3(vec, np->pnorm, funcxf.xfm);
336 +        varset("NxP", '=', vec[0]/funcxf.sca);
337 +        varset("NyP", '=', vec[1]/funcxf.sca);
338 +        varset("NzP", '=', vec[2]/funcxf.sca);
339 +        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
340 +                        np->pdot >= 1.0 ? 1.0 : np->pdot);
341 +        varset("CrP", '=', colval(np->mcolor,RED));
342 +        varset("CgP", '=', colval(np->mcolor,GRN));
343 +        varset("CbP", '=', colval(np->mcolor,BLU));
344 +        return(1);
345   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines