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.20 by greg, Thu Aug 28 03:22:16 2003 UTC vs.
Revision 2.22 by greg, Thu Sep 9 15:40:02 2004 UTC

# Line 8 | Line 8 | static const char      RCSid[] = "$Id$";
8   #include "copyright.h"
9  
10   #include  "ray.h"
11
11   #include  "ambient.h"
13
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 79 | Line 77 | typedef struct {
77   }  BRDFDAT;             /* BRDF material data */
78  
79  
80 + static srcdirf_t dirbrdf;
81 + static int setbrdfunc(BRDFDAT  *np);
82 +
83 +
84   static void
85 < dirbrdf(cval, np, ldir, omega)          /* compute source contribution */
86 < COLOR  cval;                    /* returned coefficient */
87 < register BRDFDAT  *np;          /* material data */
88 < FVECT  ldir;                    /* light source direction */
89 < double  omega;                  /* light source size */
85 > dirbrdf(                /* compute source contribution */
86 >        COLOR  cval,                    /* returned coefficient */
87 >        void  *nnp,             /* material data */
88 >        FVECT  ldir,                    /* light source direction */
89 >        double  omega                   /* light source size */
90 > )
91   {
92 +        register BRDFDAT *np = nnp;
93          double  ldot;
94          double  dtmp;
95          COLOR  ctmp;
# Line 191 | Line 195 | double  omega;                 /* light source size */
195   }
196  
197  
198 < int
199 < m_brdf(m, r)                    /* color a ray that hit a BRDTfunc material */
200 < register OBJREC  *m;
201 < register RAY  *r;
198 > extern int
199 > m_brdf(                 /* color a ray that hit a BRDTfunc material */
200 >        register OBJREC  *m,
201 >        register RAY  *r
202 > )
203   {
204          int  hitfront = 1;
205          BRDFDAT  nd;
206          RAY  sr;
207 +        double  mirtest=0, mirdist=0;
208          double  transtest, transdist;
209          int  hasrefl, hastrans;
210 +        int  hastexture;
211          COLOR  ctmp;
212          FVECT  vtmp;
213 +        double  d;
214          register MFUNC  *mf;
215          register int  i;
216                                                  /* check arguments */
# Line 228 | Line 236 | register RAY  *r;
236                          m->oargs.farg[8]);
237                                                  /* get modifiers */
238          raytexture(r, m->omod);
239 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
239 >        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
240 >        if (hastexture) {                       /* perturb normal */
241 >                nd.pdot = raynormal(nd.pnorm, r);
242 >        } else {
243 >                VCOPY(nd.pnorm, r->ron);
244 >                nd.pdot = r->rod;
245 >        }
246          if (r->rod < 0.0) {                     /* orient perturbed values */
247                  nd.pdot = -nd.pdot;
248                  for (i = 0; i < 3; i++) {
# Line 247 | Line 261 | register RAY  *r;
261          mf = getfunc(m, 9, 0x3f, 0);
262                                                  /* compute transmitted ray */
263          setbrdfunc(&nd);
250        transtest = 0;
251        transdist = r->rot;
264          errno = 0;
265          setcolor(ctmp, evalue(mf->ep[3]),
266                          evalue(mf->ep[4]),
# Line 256 | Line 268 | register RAY  *r;
268          if (errno == EDOM || errno == ERANGE)
269                  objerror(m, WARNING, "compute error");
270          else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) {
271 <                if (!(r->crtype & SHADOW) &&
260 <                                DOT(r->pert,r->pert) > FTINY*FTINY) {
271 >                if (!(r->crtype & SHADOW) && hastexture) {
272                          for (i = 0; i < 3; i++) /* perturb direction */
273                                  sr.rdir[i] = r->rdir[i] - .75*r->pert[i];
274                          if (normalize(sr.rdir) == 0.0) {
# Line 266 | Line 277 | register RAY  *r;
277                          }
278                  } else {
279                          VCOPY(sr.rdir, r->rdir);
269                        transtest = 2;
280                  }
281                  rayvalue(&sr);
282                  multcolor(sr.rcol, ctmp);
283                  addcolor(r->rcol, sr.rcol);
284 <                transtest *= bright(sr.rcol);
285 <                transdist = r->rot + sr.rt;
284 >                if (!hastexture) {
285 >                        transtest = 2.0*bright(sr.rcol);
286 >                        transdist = r->rot + sr.rt;
287 >                }
288          }
289          if (r->crtype & SHADOW)                 /* the rest is shadow */
290                  return(1);
# Line 290 | Line 302 | register RAY  *r;
302                  rayvalue(&sr);
303                  multcolor(sr.rcol, ctmp);
304                  addcolor(r->rcol, sr.rcol);
305 +                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
306 +                        mirtest = 2.0*bright(sr.rcol);
307 +                        mirdist = r->rot + sr.rt;
308 +                }
309          }
310                                                  /* compute ambient */
311          if (hasrefl) {
# Line 315 | Line 331 | register RAY  *r;
331          }
332          if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
333                  direct(r, dirbrdf, &nd);        /* add direct component */
334 <                                                /* check distance */
335 <        if (transtest > bright(r->rcol))
334 >
335 >        d = bright(r->rcol);                    /* set effective distance */
336 >        if (transtest > d)
337                  r->rt = transdist;
338 +        else if (mirtest > d)
339 +                r->rt = mirdist;
340  
341          return(1);
342   }
343  
344  
345  
346 < int
347 < m_brdf2(m, r)                   /* color a ray that hit a BRDF material */
348 < register OBJREC  *m;
349 < register RAY  *r;
346 > extern int
347 > m_brdf2(                        /* color a ray that hit a BRDF material */
348 >        register OBJREC  *m,
349 >        register RAY  *r
350 > )
351   {
352          BRDFDAT  nd;
353          COLOR  ctmp;
# Line 410 | Line 430 | register RAY  *r;
430   }
431  
432  
433 < int
434 < setbrdfunc(np)                  /* set up brdf function and variables */
435 < register BRDFDAT  *np;
433 > static int
434 > setbrdfunc(                     /* set up brdf function and variables */
435 >        register BRDFDAT  *np
436 > )
437   {
438          FVECT  vec;
439  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines