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.21 by schorsch, Tue Mar 30 16:13:01 2004 UTC vs.
Revision 2.23 by greg, Tue Apr 19 01:15:06 2005 UTC

# Line 204 | Line 204 | m_brdf(                        /* color a ray that hit a BRDTfunc material
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 233 | Line 236 | m_brdf(                        /* color a ray that hit a BRDTfunc material
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 252 | Line 261 | m_brdf(                        /* color a ray that hit a BRDTfunc material
261          mf = getfunc(m, 9, 0x3f, 0);
262                                                  /* compute transmitted ray */
263          setbrdfunc(&nd);
255        transtest = 0;
256        transdist = r->rot;
264          errno = 0;
265          setcolor(ctmp, evalue(mf->ep[3]),
266                          evalue(mf->ep[4]),
267                          evalue(mf->ep[5]));
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) &&
265 <                                DOT(r->pert,r->pert) > FTINY*FTINY) {
270 >        else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
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 271 | Line 277 | m_brdf(                        /* color a ray that hit a BRDTfunc material
277                          }
278                  } else {
279                          VCOPY(sr.rdir, r->rdir);
274                        transtest = 2;
280                  }
281                  rayvalue(&sr);
282 <                multcolor(sr.rcol, ctmp);
282 >                multcolor(sr.rcol, sr.rcoef);
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 289 | Line 296 | m_brdf(                        /* color a ray that hit a BRDTfunc material
296                          evalue(mf->ep[2]));
297          if (errno == EDOM || errno == ERANGE)
298                  objerror(m, WARNING, "compute error");
299 <        else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) {
299 >        else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) {
300                  for (i = 0; i < 3; i++)
301                          sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
302                  rayvalue(&sr);
303 <                multcolor(sr.rcol, ctmp);
303 >                multcolor(sr.rcol, sr.rcoef);
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) {
312                  if (!hitfront)
313                          flipsurface(r);
314 <                ambient(ctmp, r, nd.pnorm);
315 <                multcolor(ctmp, nd.rdiff);
314 >                copycolor(ctmp, nd.rdiff);
315 >                multambient(ctmp, r, nd.pnorm);
316                  addcolor(r->rcol, ctmp);        /* add to returned color */
317                  if (!hitfront)
318                          flipsurface(r);
# Line 312 | Line 323 | m_brdf(                        /* color a ray that hit a BRDTfunc material
323                  vtmp[0] = -nd.pnorm[0];
324                  vtmp[1] = -nd.pnorm[1];
325                  vtmp[2] = -nd.pnorm[2];
326 <                ambient(ctmp, r, vtmp);
327 <                multcolor(ctmp, nd.tdiff);
326 >                copycolor(ctmp, nd.tdiff);
327 >                multambient(ctmp, r, vtmp);
328                  addcolor(r->rcol, ctmp);
329                  if (hitfront)
330                          flipsurface(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   }
# Line 393 | Line 407 | m_brdf2(                       /* color a ray that hit a BRDF material */
407          }
408                                                  /* compute ambient */
409          if (nd.trans < 1.0-FTINY) {
410 <                ambient(ctmp, r, nd.pnorm);
410 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
411                  scalecolor(ctmp, 1.0-nd.trans);
412 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
412 >                multambient(ctmp, r, nd.pnorm);
413                  addcolor(r->rcol, ctmp);        /* add to returned color */
414          }
415          if (nd.trans > FTINY) {         /* from other side */
# Line 403 | Line 417 | m_brdf2(                       /* color a ray that hit a BRDF material */
417                  vtmp[0] = -nd.pnorm[0];
418                  vtmp[1] = -nd.pnorm[1];
419                  vtmp[2] = -nd.pnorm[2];
420 <                ambient(ctmp, r, vtmp);
420 >                copycolor(ctmp, nd.mcolor);
421                  scalecolor(ctmp, nd.trans);
422 <                multcolor(ctmp, nd.mcolor);
422 >                multambient(ctmp, r, vtmp);
423                  addcolor(r->rcol, ctmp);
424                  flipsurface(r);
425          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines