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.24 by greg, Wed Aug 22 21:21:51 2007 UTC

# Line 129 | Line 129 | dirbrdf(               /* compute source contribution */
129                  addcolor(cval, ctmp);
130          }
131          if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY)
132 <                return;         /* no specular component */
132 >                return;         /* diffuse only */
133                                          /* set up function */
134          setbrdfunc(np);
135          sa = np->mp->oargs.sarg;
# Line 145 | Line 145 | dirbrdf(               /* compute source contribution */
145                          colval(ctmp,RED) = 0.0;
146                  else
147                          colval(ctmp,RED) = funvalue(sa[6], 4, lddx);
148 <                if (!strcmp(sa[7],sa[6]))
148 >                if (sa[7][0] == '0')
149 >                        colval(ctmp,GRN) = 0.0;
150 >                else if (!strcmp(sa[7],sa[6]))
151                          colval(ctmp,GRN) = colval(ctmp,RED);
152                  else
153                          colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
# Line 204 | Line 206 | m_brdf(                        /* color a ray that hit a BRDTfunc material
206          int  hitfront = 1;
207          BRDFDAT  nd;
208          RAY  sr;
209 +        double  mirtest=0, mirdist=0;
210          double  transtest, transdist;
211          int  hasrefl, hastrans;
212 +        int  hastexture;
213          COLOR  ctmp;
214          FVECT  vtmp;
215 +        double  d;
216          register MFUNC  *mf;
217          register int  i;
218                                                  /* check arguments */
# Line 233 | Line 238 | m_brdf(                        /* color a ray that hit a BRDTfunc material
238                          m->oargs.farg[8]);
239                                                  /* get modifiers */
240          raytexture(r, m->omod);
241 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
241 >        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
242 >        if (hastexture) {                       /* perturb normal */
243 >                nd.pdot = raynormal(nd.pnorm, r);
244 >        } else {
245 >                VCOPY(nd.pnorm, r->ron);
246 >                nd.pdot = r->rod;
247 >        }
248          if (r->rod < 0.0) {                     /* orient perturbed values */
249                  nd.pdot = -nd.pdot;
250                  for (i = 0; i < 3; i++) {
# Line 252 | Line 263 | m_brdf(                        /* color a ray that hit a BRDTfunc material
263          mf = getfunc(m, 9, 0x3f, 0);
264                                                  /* compute transmitted ray */
265          setbrdfunc(&nd);
255        transtest = 0;
256        transdist = r->rot;
266          errno = 0;
267          setcolor(ctmp, evalue(mf->ep[3]),
268                          evalue(mf->ep[4]),
269                          evalue(mf->ep[5]));
270          if (errno == EDOM || errno == ERANGE)
271                  objerror(m, WARNING, "compute error");
272 <        else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) {
273 <                if (!(r->crtype & SHADOW) &&
265 <                                DOT(r->pert,r->pert) > FTINY*FTINY) {
272 >        else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
273 >                if (!(r->crtype & SHADOW) && hastexture) {
274                          for (i = 0; i < 3; i++) /* perturb direction */
275                                  sr.rdir[i] = r->rdir[i] - .75*r->pert[i];
276                          if (normalize(sr.rdir) == 0.0) {
# Line 271 | Line 279 | m_brdf(                        /* color a ray that hit a BRDTfunc material
279                          }
280                  } else {
281                          VCOPY(sr.rdir, r->rdir);
274                        transtest = 2;
282                  }
283                  rayvalue(&sr);
284 <                multcolor(sr.rcol, ctmp);
284 >                multcolor(sr.rcol, sr.rcoef);
285                  addcolor(r->rcol, sr.rcol);
286 <                transtest *= bright(sr.rcol);
287 <                transdist = r->rot + sr.rt;
286 >                if (!hastexture) {
287 >                        transtest = 2.0*bright(sr.rcol);
288 >                        transdist = r->rot + sr.rt;
289 >                }
290          }
291          if (r->crtype & SHADOW)                 /* the rest is shadow */
292                  return(1);
# Line 289 | Line 298 | m_brdf(                        /* color a ray that hit a BRDTfunc material
298                          evalue(mf->ep[2]));
299          if (errno == EDOM || errno == ERANGE)
300                  objerror(m, WARNING, "compute error");
301 <        else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) {
301 >        else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) {
302                  for (i = 0; i < 3; i++)
303                          sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
304                  rayvalue(&sr);
305 <                multcolor(sr.rcol, ctmp);
305 >                multcolor(sr.rcol, sr.rcoef);
306                  addcolor(r->rcol, sr.rcol);
307 +                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
308 +                        mirtest = 2.0*bright(sr.rcol);
309 +                        mirdist = r->rot + sr.rt;
310 +                }
311          }
312                                                  /* compute ambient */
313          if (hasrefl) {
314                  if (!hitfront)
315                          flipsurface(r);
316 <                ambient(ctmp, r, nd.pnorm);
317 <                multcolor(ctmp, nd.rdiff);
316 >                copycolor(ctmp, nd.rdiff);
317 >                multambient(ctmp, r, nd.pnorm);
318                  addcolor(r->rcol, ctmp);        /* add to returned color */
319                  if (!hitfront)
320                          flipsurface(r);
# Line 312 | Line 325 | m_brdf(                        /* color a ray that hit a BRDTfunc material
325                  vtmp[0] = -nd.pnorm[0];
326                  vtmp[1] = -nd.pnorm[1];
327                  vtmp[2] = -nd.pnorm[2];
328 <                ambient(ctmp, r, vtmp);
329 <                multcolor(ctmp, nd.tdiff);
328 >                copycolor(ctmp, nd.tdiff);
329 >                multambient(ctmp, r, vtmp);
330                  addcolor(r->rcol, ctmp);
331                  if (hitfront)
332                          flipsurface(r);
333          }
334          if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
335                  direct(r, dirbrdf, &nd);        /* add direct component */
336 <                                                /* check distance */
337 <        if (transtest > bright(r->rcol))
336 >
337 >        d = bright(r->rcol);                    /* set effective distance */
338 >        if (transtest > d)
339                  r->rt = transdist;
340 +        else if (mirtest > d)
341 +                r->rt = mirdist;
342  
343          return(1);
344   }
# Line 393 | Line 409 | m_brdf2(                       /* color a ray that hit a BRDF material */
409          }
410                                                  /* compute ambient */
411          if (nd.trans < 1.0-FTINY) {
412 <                ambient(ctmp, r, nd.pnorm);
412 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
413                  scalecolor(ctmp, 1.0-nd.trans);
414 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
414 >                multambient(ctmp, r, nd.pnorm);
415                  addcolor(r->rcol, ctmp);        /* add to returned color */
416          }
417          if (nd.trans > FTINY) {         /* from other side */
# Line 403 | Line 419 | m_brdf2(                       /* color a ray that hit a BRDF material */
419                  vtmp[0] = -nd.pnorm[0];
420                  vtmp[1] = -nd.pnorm[1];
421                  vtmp[2] = -nd.pnorm[2];
422 <                ambient(ctmp, r, vtmp);
422 >                copycolor(ctmp, nd.mcolor);
423                  scalecolor(ctmp, nd.trans);
424 <                multcolor(ctmp, nd.mcolor);
424 >                multambient(ctmp, r, vtmp);
425                  addcolor(r->rcol, ctmp);
426                  flipsurface(r);
427          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines