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.17 by greg, Mon Mar 3 00:10:51 2003 UTC vs.
Revision 2.28 by greg, Sun Jul 29 21:56:16 2012 UTC

# Line 8 | Line 8 | static const char      RCSid[] = "$Id$";
8   #include "copyright.h"
9  
10   #include  "ray.h"
11 <
11 > #include  "ambient.h"
12   #include  "data.h"
13 <
13 > #include  "source.h"
14   #include  "otypes.h"
15 <
15 > #include  "rtotypes.h"
16   #include  "func.h"
17  
18   /*
# Line 77 | Line 77 | typedef struct {
77   }  BRDFDAT;             /* BRDF material data */
78  
79  
80 + static int setbrdfunc(BRDFDAT *np);
81 +
82 +
83   static void
84 < dirbrdf(cval, np, ldir, omega)          /* compute source contribution */
85 < COLOR  cval;                    /* returned coefficient */
86 < register BRDFDAT  *np;          /* material data */
87 < FVECT  ldir;                    /* light source direction */
88 < double  omega;                  /* light source size */
84 > dirbrdf(                /* compute source contribution */
85 >        COLOR  cval,                    /* returned coefficient */
86 >        void  *nnp,             /* material data */
87 >        FVECT  ldir,                    /* light source direction */
88 >        double  omega                   /* light source size */
89 > )
90   {
91 +        BRDFDAT *np = nnp;
92          double  ldot;
93          double  dtmp;
94          COLOR  ctmp;
95          FVECT  ldx;
96          static double  vldx[5], pt[MAXDIM];
97 <        register char   **sa;
98 <        register int    i;
97 >        char    **sa;
98 >        int     i;
99   #define lddx (vldx+1)
100  
101          setcolor(cval, 0.0, 0.0, 0.0);
# Line 123 | Line 128 | double  omega;                 /* light source size */
128                  addcolor(cval, ctmp);
129          }
130          if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY)
131 <                return;         /* no specular component */
131 >                return;         /* diffuse only */
132                                          /* set up function */
133          setbrdfunc(np);
134          sa = np->mp->oargs.sarg;
# Line 139 | Line 144 | double  omega;                 /* light source size */
144                          colval(ctmp,RED) = 0.0;
145                  else
146                          colval(ctmp,RED) = funvalue(sa[6], 4, lddx);
147 <                if (!strcmp(sa[7],sa[6]))
147 >                if (sa[7][0] == '0')
148 >                        colval(ctmp,GRN) = 0.0;
149 >                else if (!strcmp(sa[7],sa[6]))
150                          colval(ctmp,GRN) = colval(ctmp,RED);
151                  else
152                          colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
# Line 160 | Line 167 | double  omega;                 /* light source size */
167                  dtmp = funvalue(sa[0], 5, vldx);
168                  setcolor(ctmp, dtmp, dtmp, dtmp);
169          }
170 <        if (errno) {
170 >        if ((errno == EDOM) | (errno == ERANGE)) {
171                  objerror(np->mp, WARNING, "compute error");
172                  return;
173          }
# Line 170 | Line 177 | double  omega;                 /* light source size */
177                  /*
178                   *  Compute reflected non-diffuse component.
179                   */
180 <                if (np->mp->otype == MAT_MFUNC | np->mp->otype == MAT_MDATA)
180 >                if ((np->mp->otype == MAT_MFUNC) | (np->mp->otype == MAT_MDATA))
181                          multcolor(ctmp, np->mcolor);
182                  dtmp = ldot * omega * np->rspec;
183                  scalecolor(ctmp, dtmp);
# Line 179 | Line 186 | double  omega;                 /* light source size */
186                  /*
187                   *  Compute transmitted non-diffuse component.
188                   */
189 <                if (np->mp->otype == MAT_TFUNC | np->mp->otype == MAT_TDATA)
189 >                if ((np->mp->otype == MAT_TFUNC) | (np->mp->otype == MAT_TDATA))
190                          multcolor(ctmp, np->mcolor);
191                  dtmp = -ldot * omega * np->tspec;
192                  scalecolor(ctmp, dtmp);
# Line 190 | Line 197 | double  omega;                 /* light source size */
197  
198  
199   int
200 < m_brdf(m, r)                    /* color a ray that hit a BRDTfunc material */
201 < register OBJREC  *m;
202 < register RAY  *r;
200 > m_brdf(                 /* color a ray that hit a BRDTfunc material */
201 >        OBJREC  *m,
202 >        RAY  *r
203 > )
204   {
205          int  hitfront = 1;
206          BRDFDAT  nd;
207          RAY  sr;
208 +        double  mirtest=0, mirdist=0;
209          double  transtest, transdist;
210          int  hasrefl, hastrans;
211 +        int  hastexture;
212          COLOR  ctmp;
213          FVECT  vtmp;
214 <        register MFUNC  *mf;
215 <        register int  i;
214 >        double  d;
215 >        MFUNC  *mf;
216 >        int  i;
217                                                  /* check arguments */
218 <        if (m->oargs.nsargs < 10 | m->oargs.nfargs < 9)
218 >        if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9))
219                  objerror(m, USER, "bad # arguments");
220          nd.mp = m;
221          nd.pr = r;
# Line 226 | Line 237 | register RAY  *r;
237                          m->oargs.farg[8]);
238                                                  /* get modifiers */
239          raytexture(r, m->omod);
240 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
240 >        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
241 >        if (hastexture) {                       /* perturb normal */
242 >                nd.pdot = raynormal(nd.pnorm, r);
243 >        } else {
244 >                VCOPY(nd.pnorm, r->ron);
245 >                nd.pdot = r->rod;
246 >        }
247          if (r->rod < 0.0) {                     /* orient perturbed values */
248                  nd.pdot = -nd.pdot;
249                  for (i = 0; i < 3; i++) {
# Line 245 | Line 262 | register RAY  *r;
262          mf = getfunc(m, 9, 0x3f, 0);
263                                                  /* compute transmitted ray */
264          setbrdfunc(&nd);
248        transtest = 0;
249        transdist = r->rot;
265          errno = 0;
266          setcolor(ctmp, evalue(mf->ep[3]),
267                          evalue(mf->ep[4]),
268                          evalue(mf->ep[5]));
269 <        if (errno)
269 >        if ((errno == EDOM) | (errno == ERANGE))
270                  objerror(m, WARNING, "compute error");
271 <        else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) {
272 <                if (!(r->crtype & SHADOW) &&
273 <                                DOT(r->pert,r->pert) > FTINY*FTINY) {
274 <                        for (i = 0; i < 3; i++) /* perturb direction */
260 <                                sr.rdir[i] = r->rdir[i] - .75*r->pert[i];
271 >        else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
272 >                if (!(r->crtype & SHADOW) && hastexture) {
273 >                                                /* perturb direction */
274 >                        VSUM(sr.rdir, r->rdir, r->pert, -.75);
275                          if (normalize(sr.rdir) == 0.0) {
276                                  objerror(m, WARNING, "illegal perturbation");
277                                  VCOPY(sr.rdir, r->rdir);
278                          }
279                  } else {
280                          VCOPY(sr.rdir, r->rdir);
267                        transtest = 2;
281                  }
282                  rayvalue(&sr);
283 <                multcolor(sr.rcol, ctmp);
283 >                multcolor(sr.rcol, sr.rcoef);
284                  addcolor(r->rcol, sr.rcol);
285 <                transtest *= bright(sr.rcol);
286 <                transdist = r->rot + sr.rt;
285 >                if (!hastexture) {
286 >                        transtest = 2.0*bright(sr.rcol);
287 >                        transdist = r->rot + sr.rt;
288 >                }
289          }
290          if (r->crtype & SHADOW)                 /* the rest is shadow */
291                  return(1);
# Line 280 | Line 295 | register RAY  *r;
295          setcolor(ctmp, evalue(mf->ep[0]),
296                          evalue(mf->ep[1]),
297                          evalue(mf->ep[2]));
298 <        if (errno)
298 >        if ((errno == EDOM) | (errno == ERANGE))
299                  objerror(m, WARNING, "compute error");
300 <        else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) {
301 <                for (i = 0; i < 3; i++)
302 <                        sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
300 >        else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) {
301 >                VSUM(sr.rdir, r->rdir, nd.pnorm, 2.*nd.pdot);
302 >                checknorm(sr.rdir);
303                  rayvalue(&sr);
304 <                multcolor(sr.rcol, ctmp);
304 >                multcolor(sr.rcol, sr.rcoef);
305                  addcolor(r->rcol, sr.rcol);
306 +                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
307 +                        mirtest = 2.0*bright(sr.rcol);
308 +                        mirdist = r->rot + sr.rt;
309 +                }
310          }
311                                                  /* compute ambient */
312          if (hasrefl) {
313                  if (!hitfront)
314                          flipsurface(r);
315 <                ambient(ctmp, r, nd.pnorm);
316 <                multcolor(ctmp, nd.rdiff);
315 >                copycolor(ctmp, nd.rdiff);
316 >                multambient(ctmp, r, nd.pnorm);
317                  addcolor(r->rcol, ctmp);        /* add to returned color */
318                  if (!hitfront)
319                          flipsurface(r);
# Line 305 | Line 324 | register RAY  *r;
324                  vtmp[0] = -nd.pnorm[0];
325                  vtmp[1] = -nd.pnorm[1];
326                  vtmp[2] = -nd.pnorm[2];
327 <                ambient(ctmp, r, vtmp);
328 <                multcolor(ctmp, nd.tdiff);
327 >                copycolor(ctmp, nd.tdiff);
328 >                multambient(ctmp, r, vtmp);
329                  addcolor(r->rcol, ctmp);
330                  if (hitfront)
331                          flipsurface(r);
332          }
333          if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
334                  direct(r, dirbrdf, &nd);        /* add direct component */
335 <                                                /* check distance */
336 <        if (transtest > bright(r->rcol))
335 >
336 >        d = bright(r->rcol);                    /* set effective distance */
337 >        if (transtest > d)
338                  r->rt = transdist;
339 +        else if (mirtest > d)
340 +                r->rt = mirdist;
341  
342          return(1);
343   }
# Line 323 | Line 345 | register RAY  *r;
345  
346  
347   int
348 < m_brdf2(m, r)                   /* color a ray that hit a BRDF material */
349 < register OBJREC  *m;
350 < register RAY  *r;
348 > m_brdf2(                        /* color a ray that hit a BRDF material */
349 >        OBJREC  *m,
350 >        RAY  *r
351 > )
352   {
353          BRDFDAT  nd;
354          COLOR  ctmp;
# Line 335 | Line 358 | register RAY  *r;
358          if (r->crtype & SHADOW)
359                  return(1);
360                                                  /* check arguments */
361 <        if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs <
362 <                        (m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4))
361 >        if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
362 >                        ((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
363                  objerror(m, USER, "bad # arguments");
364                                                  /* check for back side */
365          if (r->rod < 0.0) {
# Line 359 | Line 382 | register RAY  *r;
382                                                  /* get specular component */
383          nd.rspec = m->oargs.farg[3];
384                                                  /* compute transmittance */
385 <        if (m->otype == MAT_TFUNC | m->otype == MAT_TDATA) {
385 >        if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) {
386                  nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
387                  nd.tspec = nd.trans * m->oargs.farg[5];
388                  dtmp = nd.trans - nd.tspec;
# Line 385 | Line 408 | register RAY  *r;
408          }
409                                                  /* compute ambient */
410          if (nd.trans < 1.0-FTINY) {
411 <                ambient(ctmp, r, nd.pnorm);
411 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
412                  scalecolor(ctmp, 1.0-nd.trans);
413 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
413 >                multambient(ctmp, r, nd.pnorm);
414                  addcolor(r->rcol, ctmp);        /* add to returned color */
415          }
416          if (nd.trans > FTINY) {         /* from other side */
# Line 395 | Line 418 | register RAY  *r;
418                  vtmp[0] = -nd.pnorm[0];
419                  vtmp[1] = -nd.pnorm[1];
420                  vtmp[2] = -nd.pnorm[2];
421 <                ambient(ctmp, r, vtmp);
421 >                copycolor(ctmp, nd.mcolor);
422                  scalecolor(ctmp, nd.trans);
423 <                multcolor(ctmp, nd.mcolor);
423 >                multambient(ctmp, r, vtmp);
424                  addcolor(r->rcol, ctmp);
425                  flipsurface(r);
426          }
# Line 408 | Line 431 | register RAY  *r;
431   }
432  
433  
434 < int
435 < setbrdfunc(np)                  /* set up brdf function and variables */
436 < register BRDFDAT  *np;
434 > static int
435 > setbrdfunc(                     /* set up brdf function and variables */
436 >        BRDFDAT  *np
437 > )
438   {
439          FVECT  vec;
440  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines