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 2.10 by greg, Wed Jan 12 16:46:35 1994 UTC vs.
Revision 2.18 by greg, Wed Mar 5 16:16:53 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  Shading for materials with arbitrary BRDF's
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "ray.h"
11  
12   #include  "data.h"
# Line 78 | Line 77 | typedef struct {
77   }  BRDFDAT;             /* BRDF material data */
78  
79  
80 + static void
81   dirbrdf(cval, np, ldir, omega)          /* compute source contribution */
82   COLOR  cval;                    /* returned coefficient */
83   register BRDFDAT  *np;          /* material data */
# Line 88 | Line 88 | double  omega;                 /* light source size */
88          double  dtmp;
89          COLOR  ctmp;
90          FVECT  ldx;
91 <        double  lddx[3], pt[MAXDIM];
92 <        double  vldx[4];
91 >        static double  vldx[5], pt[MAXDIM];
92          register char   **sa;
93          register int    i;
94 + #define lddx (vldx+1)
95  
96          setcolor(cval, 0.0, 0.0, 0.0);
97          
# Line 132 | Line 132 | double  omega;                 /* light source size */
132          multv3(ldx, ldir, funcxf.xfm);
133          for (i = 0; i < 3; i++)
134                  lddx[i] = ldx[i]/funcxf.sca;
135 +        lddx[3] = omega;
136                                          /* compute BRTDF */
137          if (np->mp->otype == MAT_BRTDF) {
138                  if (sa[6][0] == '0')            /* special case */
139                          colval(ctmp,RED) = 0.0;
140                  else
141 <                        colval(ctmp,RED) = funvalue(sa[6], 3, lddx);
141 >                        colval(ctmp,RED) = funvalue(sa[6], 4, lddx);
142                  if (!strcmp(sa[7],sa[6]))
143                          colval(ctmp,GRN) = colval(ctmp,RED);
144                  else
145 <                        colval(ctmp,GRN) = funvalue(sa[7], 3, lddx);
145 >                        colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
146                  if (!strcmp(sa[8],sa[6]))
147                          colval(ctmp,BLU) = colval(ctmp,RED);
148                  else if (!strcmp(sa[8],sa[7]))
149                          colval(ctmp,BLU) = colval(ctmp,GRN);
150                  else
151 <                        colval(ctmp,BLU) = funvalue(sa[8], 3, lddx);
151 >                        colval(ctmp,BLU) = funvalue(sa[8], 4, lddx);
152                  dtmp = bright(ctmp);
153          } else if (np->dp == NULL) {
154 <                dtmp = funvalue(sa[0], 3, lddx);
154 >                dtmp = funvalue(sa[0], 4, lddx);
155                  setcolor(ctmp, dtmp, dtmp, dtmp);
156          } else {
157                  for (i = 0; i < np->dp->nd; i++)
158 <                        pt[i] = funvalue(sa[3+i], 3, lddx);
158 >                        pt[i] = funvalue(sa[3+i], 4, lddx);
159                  vldx[0] = datavalue(np->dp, pt);
160 <                vldx[1] = lddx[0]; vldx[2] = lddx[1]; vldx[3] = lddx[2];
160 <                dtmp = funvalue(sa[0], 4, vldx);
160 >                dtmp = funvalue(sa[0], 5, vldx);
161                  setcolor(ctmp, dtmp, dtmp, dtmp);
162          }
163 <        if (errno) {
163 >        if (errno == EDOM || errno == ERANGE) {
164                  objerror(np->mp, WARNING, "compute error");
165                  return;
166          }
# Line 185 | Line 185 | double  omega;                 /* light source size */
185                  scalecolor(ctmp, dtmp);
186                  addcolor(cval, ctmp);
187          }
188 + #undef lddx
189   }
190  
191  
192 < m_brdf(m, r)                    /* color a ray which hit a BRDTF material */
192 > int
193 > m_brdf(m, r)                    /* color a ray that hit a BRDTfunc material */
194   register OBJREC  *m;
195   register RAY  *r;
196   {
197 +        int  hitfront = 1;
198          BRDFDAT  nd;
199          RAY  sr;
200          double  transtest, transdist;
201          int  hasrefl, hastrans;
202          COLOR  ctmp;
203 +        FVECT  vtmp;
204          register MFUNC  *mf;
205          register int  i;
206                                                  /* check arguments */
# Line 220 | Line 224 | register RAY  *r;
224          setcolor(nd.tdiff, m->oargs.farg[6],
225                          m->oargs.farg[7],
226                          m->oargs.farg[8]);
227 <                                        /* get modifiers */
227 >                                                /* get modifiers */
228          raytexture(r, m->omod);
229          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
230          if (r->rod < 0.0) {                     /* orient perturbed values */
# Line 229 | Line 233 | register RAY  *r;
233                          nd.pnorm[i] = -nd.pnorm[i];
234                          r->pert[i] = -r->pert[i];
235                  }
236 +                hitfront = 0;
237          }
238          copycolor(nd.mcolor, r->pcol);          /* get pattern color */
239          multcolor(nd.rdiff, nd.mcolor);         /* modify diffuse values */
# Line 246 | Line 251 | register RAY  *r;
251          setcolor(ctmp, evalue(mf->ep[3]),
252                          evalue(mf->ep[4]),
253                          evalue(mf->ep[5]));
254 <        if (errno)
254 >        if (errno == EDOM || errno == ERANGE)
255                  objerror(m, WARNING, "compute error");
256          else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) {
257                  if (!(r->crtype & SHADOW) &&
# Line 275 | Line 280 | register RAY  *r;
280          setcolor(ctmp, evalue(mf->ep[0]),
281                          evalue(mf->ep[1]),
282                          evalue(mf->ep[2]));
283 <        if (errno)
283 >        if (errno == EDOM || errno == ERANGE)
284                  objerror(m, WARNING, "compute error");
285          else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) {
286                  for (i = 0; i < 3; i++)
# Line 286 | Line 291 | register RAY  *r;
291          }
292                                                  /* compute ambient */
293          if (hasrefl) {
294 <                if (nd.pdot < 0.0)
294 >                if (!hitfront)
295                          flipsurface(r);
296 <                ambient(ctmp, r);
296 >                ambient(ctmp, r, nd.pnorm);
297                  multcolor(ctmp, nd.rdiff);
298                  addcolor(r->rcol, ctmp);        /* add to returned color */
299 <                if (nd.pdot < 0.0)
299 >                if (!hitfront)
300                          flipsurface(r);
301          }
302          if (hastrans) {                         /* from other side */
303 <                if (nd.pdot > 0.0)
303 >                if (hitfront)
304                          flipsurface(r);
305 <                ambient(ctmp, r);
305 >                vtmp[0] = -nd.pnorm[0];
306 >                vtmp[1] = -nd.pnorm[1];
307 >                vtmp[2] = -nd.pnorm[2];
308 >                ambient(ctmp, r, vtmp);
309                  multcolor(ctmp, nd.tdiff);
310                  addcolor(r->rcol, ctmp);
311 <                if (nd.pdot > 0.0)
311 >                if (hitfront)
312                          flipsurface(r);
313          }
314          if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
# Line 314 | Line 322 | register RAY  *r;
322  
323  
324  
325 < m_brdf2(m, r)                   /* color a ray which hit a BRDF material */
325 > int
326 > m_brdf2(m, r)                   /* color a ray that hit a BRDF material */
327   register OBJREC  *m;
328   register RAY  *r;
329   {
330          BRDFDAT  nd;
331          COLOR  ctmp;
332 +        FVECT  vtmp;
333          double  dtmp;
334                                                  /* always a shadow */
335          if (r->crtype & SHADOW)
# Line 328 | Line 338 | register RAY  *r;
338          if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs <
339                          (m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4))
340                  objerror(m, USER, "bad # arguments");
341 +                                                /* check for back side */
342 +        if (r->rod < 0.0) {
343 +                if (!backvis && m->otype != MAT_TFUNC
344 +                                && m->otype != MAT_TDATA) {
345 +                        raytrans(r);
346 +                        return(1);
347 +                }
348 +                raytexture(r, m->omod);
349 +                flipsurface(r);                 /* reorient if backvis */
350 +        } else
351 +                raytexture(r, m->omod);
352 +
353          nd.mp = m;
354          nd.pr = r;
355                                                  /* get material color */
# Line 349 | Line 371 | register RAY  *r;
371                                                  /* compute reflectance */
372          dtmp = 1.0 - nd.trans - nd.rspec;
373          setcolor(nd.rdiff, dtmp, dtmp, dtmp);
352                                                /* fix orientation */
353        if (r->rod < 0.0)
354                flipsurface(r);
355                                                /* get modifiers */
356        raytexture(r, m->omod);
374          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
375          multcolor(nd.mcolor, r->pcol);          /* modify material color */
376          multcolor(nd.rdiff, nd.mcolor);
# Line 368 | Line 385 | register RAY  *r;
385          }
386                                                  /* compute ambient */
387          if (nd.trans < 1.0-FTINY) {
388 <                ambient(ctmp, r);
388 >                ambient(ctmp, r, nd.pnorm);
389                  scalecolor(ctmp, 1.0-nd.trans);
390                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
391                  addcolor(r->rcol, ctmp);        /* add to returned color */
392          }
393          if (nd.trans > FTINY) {         /* from other side */
394                  flipsurface(r);
395 <                ambient(ctmp, r);
395 >                vtmp[0] = -nd.pnorm[0];
396 >                vtmp[1] = -nd.pnorm[1];
397 >                vtmp[2] = -nd.pnorm[2];
398 >                ambient(ctmp, r, vtmp);
399                  scalecolor(ctmp, nd.trans);
400                  multcolor(ctmp, nd.mcolor);
401                  addcolor(r->rcol, ctmp);
# Line 388 | Line 408 | register RAY  *r;
408   }
409  
410  
411 + int
412   setbrdfunc(np)                  /* set up brdf function and variables */
413   register BRDFDAT  *np;
414   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines