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.12 by greg, Wed May 17 17:31:39 1995 UTC vs.
Revision 2.20 by greg, Thu Aug 28 03:22:16 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  "ambient.h"
13 +
14   #include  "data.h"
15  
16   #include  "otypes.h"
17  
18   #include  "func.h"
19  
19 extern int  backvis;                    /* back faces visible? */
20
20   /*
21   *      Arguments to this material include the color and specularity.
22   *  String arguments include the reflection function and files.
# Line 80 | Line 79 | typedef struct {
79   }  BRDFDAT;             /* BRDF material data */
80  
81  
82 + static void
83   dirbrdf(cval, np, ldir, omega)          /* compute source contribution */
84   COLOR  cval;                    /* returned coefficient */
85   register BRDFDAT  *np;          /* material data */
# Line 162 | Line 162 | double  omega;                 /* light source size */
162                  dtmp = funvalue(sa[0], 5, vldx);
163                  setcolor(ctmp, dtmp, dtmp, dtmp);
164          }
165 <        if (errno) {
165 >        if (errno == EDOM || errno == ERANGE) {
166                  objerror(np->mp, WARNING, "compute error");
167                  return;
168          }
# Line 172 | Line 172 | double  omega;                 /* light source size */
172                  /*
173                   *  Compute reflected non-diffuse component.
174                   */
175 <                if (np->mp->otype == MAT_MFUNC | np->mp->otype == MAT_MDATA)
175 >                if ((np->mp->otype == MAT_MFUNC) | (np->mp->otype == MAT_MDATA))
176                          multcolor(ctmp, np->mcolor);
177                  dtmp = ldot * omega * np->rspec;
178                  scalecolor(ctmp, dtmp);
# Line 181 | Line 181 | double  omega;                 /* light source size */
181                  /*
182                   *  Compute transmitted non-diffuse component.
183                   */
184 <                if (np->mp->otype == MAT_TFUNC | np->mp->otype == MAT_TDATA)
184 >                if ((np->mp->otype == MAT_TFUNC) | (np->mp->otype == MAT_TDATA))
185                          multcolor(ctmp, np->mcolor);
186                  dtmp = -ldot * omega * np->tspec;
187                  scalecolor(ctmp, dtmp);
# Line 191 | Line 191 | double  omega;                 /* light source size */
191   }
192  
193  
194 < m_brdf(m, r)                    /* color a ray which hit a BRDTF material */
194 > int
195 > m_brdf(m, r)                    /* color a ray that hit a BRDTfunc material */
196   register OBJREC  *m;
197   register RAY  *r;
198   {
199 +        int  hitfront = 1;
200          BRDFDAT  nd;
201          RAY  sr;
202          double  transtest, transdist;
203          int  hasrefl, hastrans;
204          COLOR  ctmp;
205 +        FVECT  vtmp;
206          register MFUNC  *mf;
207          register int  i;
208                                                  /* check arguments */
209 <        if (m->oargs.nsargs < 10 | m->oargs.nfargs < 9)
209 >        if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9))
210                  objerror(m, USER, "bad # arguments");
211          nd.mp = m;
212          nd.pr = r;
# Line 223 | Line 226 | register RAY  *r;
226          setcolor(nd.tdiff, m->oargs.farg[6],
227                          m->oargs.farg[7],
228                          m->oargs.farg[8]);
229 <                                        /* get modifiers */
229 >                                                /* get modifiers */
230          raytexture(r, m->omod);
231          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
232          if (r->rod < 0.0) {                     /* orient perturbed values */
# Line 232 | Line 235 | register RAY  *r;
235                          nd.pnorm[i] = -nd.pnorm[i];
236                          r->pert[i] = -r->pert[i];
237                  }
238 +                hitfront = 0;
239          }
240          copycolor(nd.mcolor, r->pcol);          /* get pattern color */
241          multcolor(nd.rdiff, nd.mcolor);         /* modify diffuse values */
# Line 249 | Line 253 | register RAY  *r;
253          setcolor(ctmp, evalue(mf->ep[3]),
254                          evalue(mf->ep[4]),
255                          evalue(mf->ep[5]));
256 <        if (errno)
256 >        if (errno == EDOM || errno == ERANGE)
257                  objerror(m, WARNING, "compute error");
258          else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) {
259                  if (!(r->crtype & SHADOW) &&
# Line 278 | Line 282 | register RAY  *r;
282          setcolor(ctmp, evalue(mf->ep[0]),
283                          evalue(mf->ep[1]),
284                          evalue(mf->ep[2]));
285 <        if (errno)
285 >        if (errno == EDOM || errno == ERANGE)
286                  objerror(m, WARNING, "compute error");
287          else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) {
288                  for (i = 0; i < 3; i++)
# Line 289 | Line 293 | register RAY  *r;
293          }
294                                                  /* compute ambient */
295          if (hasrefl) {
296 <                if (nd.pdot < 0.0)
296 >                if (!hitfront)
297                          flipsurface(r);
298 <                ambient(ctmp, r);
298 >                ambient(ctmp, r, nd.pnorm);
299                  multcolor(ctmp, nd.rdiff);
300                  addcolor(r->rcol, ctmp);        /* add to returned color */
301 <                if (nd.pdot < 0.0)
301 >                if (!hitfront)
302                          flipsurface(r);
303          }
304          if (hastrans) {                         /* from other side */
305 <                if (nd.pdot > 0.0)
305 >                if (hitfront)
306                          flipsurface(r);
307 <                ambient(ctmp, r);
307 >                vtmp[0] = -nd.pnorm[0];
308 >                vtmp[1] = -nd.pnorm[1];
309 >                vtmp[2] = -nd.pnorm[2];
310 >                ambient(ctmp, r, vtmp);
311                  multcolor(ctmp, nd.tdiff);
312                  addcolor(r->rcol, ctmp);
313 <                if (nd.pdot > 0.0)
313 >                if (hitfront)
314                          flipsurface(r);
315          }
316          if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
# Line 317 | Line 324 | register RAY  *r;
324  
325  
326  
327 < m_brdf2(m, r)                   /* color a ray which hit a BRDF material */
327 > int
328 > m_brdf2(m, r)                   /* color a ray that hit a BRDF material */
329   register OBJREC  *m;
330   register RAY  *r;
331   {
332          BRDFDAT  nd;
333          COLOR  ctmp;
334 +        FVECT  vtmp;
335          double  dtmp;
336                                                  /* always a shadow */
337          if (r->crtype & SHADOW)
338                  return(1);
339                                                  /* check arguments */
340 <        if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs <
341 <                        (m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4))
340 >        if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
341 >                        ((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
342                  objerror(m, USER, "bad # arguments");
343 +                                                /* check for back side */
344 +        if (r->rod < 0.0) {
345 +                if (!backvis && m->otype != MAT_TFUNC
346 +                                && m->otype != MAT_TDATA) {
347 +                        raytrans(r);
348 +                        return(1);
349 +                }
350 +                raytexture(r, m->omod);
351 +                flipsurface(r);                 /* reorient if backvis */
352 +        } else
353 +                raytexture(r, m->omod);
354 +
355          nd.mp = m;
356          nd.pr = r;
357                                                  /* get material color */
# Line 340 | Line 361 | register RAY  *r;
361                                                  /* get specular component */
362          nd.rspec = m->oargs.farg[3];
363                                                  /* compute transmittance */
364 <        if (m->otype == MAT_TFUNC | m->otype == MAT_TDATA) {
364 >        if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) {
365                  nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
366                  nd.tspec = nd.trans * m->oargs.farg[5];
367                  dtmp = nd.trans - nd.tspec;
# Line 352 | Line 373 | register RAY  *r;
373                                                  /* compute reflectance */
374          dtmp = 1.0 - nd.trans - nd.rspec;
375          setcolor(nd.rdiff, dtmp, dtmp, dtmp);
355                                                /* check for back side */
356        if (r->rod < 0.0) {
357                if (!backvis && m->otype != MAT_TFUNC
358                                && m->otype != MAT_TDATA) {
359                        raytrans(r);
360                        return(1);
361                }
362                flipsurface(r);                 /* reorient if backvis */
363        }
364                                                /* get modifiers */
365        raytexture(r, m->omod);
376          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
377          multcolor(nd.mcolor, r->pcol);          /* modify material color */
378          multcolor(nd.rdiff, nd.mcolor);
# Line 377 | Line 387 | register RAY  *r;
387          }
388                                                  /* compute ambient */
389          if (nd.trans < 1.0-FTINY) {
390 <                ambient(ctmp, r);
390 >                ambient(ctmp, r, nd.pnorm);
391                  scalecolor(ctmp, 1.0-nd.trans);
392                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
393                  addcolor(r->rcol, ctmp);        /* add to returned color */
394          }
395          if (nd.trans > FTINY) {         /* from other side */
396                  flipsurface(r);
397 <                ambient(ctmp, r);
397 >                vtmp[0] = -nd.pnorm[0];
398 >                vtmp[1] = -nd.pnorm[1];
399 >                vtmp[2] = -nd.pnorm[2];
400 >                ambient(ctmp, r, vtmp);
401                  scalecolor(ctmp, nd.trans);
402                  multcolor(ctmp, nd.mcolor);
403                  addcolor(r->rcol, ctmp);
# Line 397 | Line 410 | register RAY  *r;
410   }
411  
412  
413 + int
414   setbrdfunc(np)                  /* set up brdf function and variables */
415   register BRDFDAT  *np;
416   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines