ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/normal.c
(Generate patch)

Comparing ray/src/rt/normal.c (file contents):
Revision 2.49 by greg, Wed Jan 5 19:34:11 2005 UTC vs.
Revision 2.51 by greg, Thu Dec 8 17:56:38 2005 UTC

# Line 25 | Line 25 | static const char RCSid[] = "$Id$";
25   #endif
26                                          /* estimate of Fresnel function */
27   #define  FRESNE(ci)     (exp(-5.85*(ci)) - 0.00287989916)
28 + #define  FRESTHRESH     0.017999        /* minimum specularity for approx. */
29  
30  
31   /*
# Line 93 | Line 94 | dirnorm(               /* compute source contribution */
94                                  /* Fresnel estimate */
95          lrdiff = np->rdiff;
96          ltdiff = np->tdiff;
97 <        if (np->specfl & SP_PURE && np->rspec > FTINY &&
97 >        if (np->specfl & SP_PURE && np->rspec >= FRESTHRESH &&
98                          (lrdiff > FTINY) | (ltdiff > FTINY)) {
99                  dtmp = 1. - FRESNE(fabs(ldot));
100                  lrdiff *= dtmp;
# Line 225 | Line 226 | m_normal(                      /* color a ray that hit something normal *
226          mirdist = transdist = r->rot;
227          nd.rspec = m->oargs.farg[3];
228                                                  /* compute Fresnel approx. */
229 <        if (nd.specfl & SP_PURE && nd.rspec > FTINY) {
229 >        if (nd.specfl & SP_PURE && nd.rspec >= FRESTHRESH) {
230                  fest = FRESNE(r->rod);
231                  nd.rspec += fest*(1. - nd.rspec);
232          } else
# Line 258 | Line 259 | m_normal(                      /* color a ray that hit something normal *
259                                                  /* transmitted ray */
260          if ((nd.specfl&(SP_TRAN|SP_PURE|SP_TBLT)) == (SP_TRAN|SP_PURE)) {
261                  RAY  lr;
262 <                if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) {
262 >                copycolor(lr.rcoef, nd.mcolor); /* modified by color */
263 >                scalecolor(lr.rcoef, nd.tspec);
264 >                if (rayorigin(&lr, TRANS, r, lr.rcoef) == 0) {
265                          VCOPY(lr.rdir, nd.prdir);
266                          rayvalue(&lr);
267 <                        scalecolor(lr.rcol, nd.tspec);
265 <                        multcolor(lr.rcol, nd.mcolor);  /* modified by color */
267 >                        multcolor(lr.rcol, lr.rcoef);
268                          addcolor(r->rcol, lr.rcol);
269                          transtest *= bright(lr.rcol);
270                          transdist = r->rot + lr.rt;
# Line 302 | Line 304 | m_normal(                      /* color a ray that hit something normal *
304                                                  /* reflected ray */
305          if ((nd.specfl&(SP_REFL|SP_PURE|SP_RBLT)) == (SP_REFL|SP_PURE)) {
306                  RAY  lr;
307 <                if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
307 >                if (rayorigin(&lr, REFLECTED, r, nd.scolor) == 0) {
308                          VCOPY(lr.rdir, nd.vrefl);
309                          rayvalue(&lr);
310 <                        multcolor(lr.rcol, nd.scolor);
310 >                        multcolor(lr.rcol, lr.rcoef);
311                          addcolor(r->rcol, lr.rcol);
312                          if (!hastexture && nd.specfl & SP_FLAT) {
313                                  mirtest = 2.*bright(lr.rcol);
# Line 323 | Line 325 | m_normal(                      /* color a ray that hit something normal *
325                  gaussamp(r, &nd);               /* checks *BLT flags */
326  
327          if (nd.rdiff > FTINY) {         /* ambient from this side */
328 <                ambient(ctmp, r, hastexture?nd.pnorm:r->ron);
328 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
329                  if (nd.specfl & SP_RBLT)
330                          scalecolor(ctmp, 1.0-nd.trans);
331                  else
332                          scalecolor(ctmp, nd.rdiff);
333 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
333 >                multambient(ctmp, r, hastexture ? nd.pnorm : r->ron);
334                  addcolor(r->rcol, ctmp);        /* add to returned color */
335          }
336          if (nd.tdiff > FTINY) {         /* ambient from other side */
337 +                copycolor(ctmp, nd.mcolor);     /* modified by color */
338 +                if (nd.specfl & SP_TBLT)
339 +                        scalecolor(ctmp, nd.trans);
340 +                else
341 +                        scalecolor(ctmp, nd.tdiff);
342                  flipsurface(r);
343                  if (hastexture) {
344                          FVECT  bnorm;
345                          bnorm[0] = -nd.pnorm[0];
346                          bnorm[1] = -nd.pnorm[1];
347                          bnorm[2] = -nd.pnorm[2];
348 <                        ambient(ctmp, r, bnorm);
348 >                        multambient(ctmp, r, bnorm);
349                  } else
350 <                        ambient(ctmp, r, r->ron);
344 <                if (nd.specfl & SP_TBLT)
345 <                        scalecolor(ctmp, nd.trans);
346 <                else
347 <                        scalecolor(ctmp, nd.tdiff);
348 <                multcolor(ctmp, nd.mcolor);     /* modified by color */
350 >                        multambient(ctmp, r, r->ron);
351                  addcolor(r->rcol, ctmp);
352                  flipsurface(r);
353          }
# Line 389 | Line 391 | gaussamp(                      /* sample gaussian specular */
391          fcross(v, np->pnorm, u);
392                                          /* compute reflection */
393          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
394 <                        rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
394 >                        rayorigin(&sr, SPECULAR, r, np->scolor) == 0) {
395                  dimlist[ndims++] = (int)np->mp;
396                  for (niter = 0; niter < MAXITER; niter++) {
397                          if (niter)
# Line 412 | Line 414 | gaussamp(                      /* sample gaussian specular */
414                                  sr.rdir[i] = r->rdir[i] + d*h[i];
415                          if (DOT(sr.rdir, r->ron) > FTINY) {
416                                  rayvalue(&sr);
417 <                                multcolor(sr.rcol, np->scolor);
417 >                                multcolor(sr.rcol, sr.rcoef);
418                                  addcolor(r->rcol, sr.rcol);
419                                  break;
420                          }
# Line 420 | Line 422 | gaussamp(                      /* sample gaussian specular */
422                  ndims--;
423          }
424                                          /* compute transmission */
425 +        copycolor(sr.rcoef, np->mcolor);        /* modified by color */
426 +        scalecolor(sr.rcoef, np->tspec);
427          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
428 <                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
428 >                        rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) {
429                  dimlist[ndims++] = (int)np->mp;
430                  for (niter = 0; niter < MAXITER; niter++) {
431                          if (niter)
# Line 442 | Line 446 | gaussamp(                      /* sample gaussian specular */
446                          if (DOT(sr.rdir, r->ron) < -FTINY) {
447                                  normalize(sr.rdir);     /* OK, normalize */
448                                  rayvalue(&sr);
449 <                                scalecolor(sr.rcol, np->tspec);
446 <                                multcolor(sr.rcol, np->mcolor); /* modified */
449 >                                multcolor(sr.rcol, sr.rcoef);
450                                  addcolor(r->rcol, sr.rcol);
451                                  break;
452                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines