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.54 by greg, Fri Oct 1 18:11:18 2010 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 79 | Line 80 | dirnorm(               /* compute source contribution */
80          register NORMDAT *np = nnp;
81          double  ldot;
82          double  lrdiff, ltdiff;
83 <        double  dtmp, d2;
83 >        double  dtmp, d2, d3, d4;
84          FVECT  vtmp;
85          COLOR  ctmp;
86  
# 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 114 | Line 115 | dirnorm(               /* compute source contribution */
115          if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE)) == SP_REFL) {
116                  /*
117                   *  Compute specular reflection coefficient using
118 <                 *  gaussian distribution model.
118 >                 *  Gaussian distribution model.
119                   */
120                                                  /* roughness */
121                  dtmp = np->alpha2;
# Line 127 | Line 128 | dirnorm(               /* compute source contribution */
128                  vtmp[2] = ldir[2] - np->rp->rdir[2];
129                  d2 = DOT(vtmp, np->pnorm);
130                  d2 *= d2;
131 <                d2 = (DOT(vtmp,vtmp) - d2) / d2;
132 <                                                /* gaussian */
133 <                dtmp = exp(-d2/dtmp)/(4.*PI * np->pdot * dtmp);
131 >                d3 = DOT(vtmp,vtmp);
132 >                d4 = (d3 - d2) / d2;
133 >                                                /* new W-G-M-D model */
134 >                dtmp = exp(-d4/dtmp) * d3 / (PI * d2*d2 * dtmp);
135                                                  /* worth using? */
136                  if (dtmp > FTINY) {
137                          copycolor(ctmp, np->scolor);
138 <                        dtmp *= omega;
138 >                        dtmp *= ldot * omega;
139                          scalecolor(ctmp, dtmp);
140                          addcolor(cval, ctmp);
141                  }
# Line 154 | Line 156 | dirnorm(               /* compute source contribution */
156                   */
157                                                  /* roughness + source */
158                  dtmp = np->alpha2 + omega*(1.0/PI);
159 <                                                /* gaussian */
160 <                dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp) /
159 <                                        (PI*np->pdot*dtmp);
159 >                                                /* Gaussian */
160 >                dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp);
161                                                  /* worth using? */
162                  if (dtmp > FTINY) {
163                          copycolor(ctmp, np->mcolor);
164 <                        dtmp *= np->tspec * omega;
164 >                        dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot);
165                          scalecolor(ctmp, dtmp);
166                          addcolor(cval, ctmp);
167                  }
# 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 298 | Line 300 | m_normal(                      /* color a ray that hit something normal *
300                  if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY)
301                          for (i = 0; i < 3; i++)         /* safety measure */
302                                  nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
303 +                checknorm(nd.vrefl);
304          }
305                                                  /* reflected ray */
306          if ((nd.specfl&(SP_REFL|SP_PURE|SP_RBLT)) == (SP_REFL|SP_PURE)) {
307                  RAY  lr;
308 <                if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
308 >                if (rayorigin(&lr, REFLECTED, r, nd.scolor) == 0) {
309                          VCOPY(lr.rdir, nd.vrefl);
310                          rayvalue(&lr);
311 <                        multcolor(lr.rcol, nd.scolor);
311 >                        multcolor(lr.rcol, lr.rcoef);
312                          addcolor(r->rcol, lr.rcol);
313                          if (!hastexture && nd.specfl & SP_FLAT) {
314                                  mirtest = 2.*bright(lr.rcol);
# Line 323 | Line 326 | m_normal(                      /* color a ray that hit something normal *
326                  gaussamp(r, &nd);               /* checks *BLT flags */
327  
328          if (nd.rdiff > FTINY) {         /* ambient from this side */
329 <                ambient(ctmp, r, hastexture?nd.pnorm:r->ron);
329 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
330                  if (nd.specfl & SP_RBLT)
331                          scalecolor(ctmp, 1.0-nd.trans);
332                  else
333                          scalecolor(ctmp, nd.rdiff);
334 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
334 >                multambient(ctmp, r, hastexture ? nd.pnorm : r->ron);
335                  addcolor(r->rcol, ctmp);        /* add to returned color */
336          }
337          if (nd.tdiff > FTINY) {         /* ambient from other side */
338 +                copycolor(ctmp, nd.mcolor);     /* modified by color */
339 +                if (nd.specfl & SP_TBLT)
340 +                        scalecolor(ctmp, nd.trans);
341 +                else
342 +                        scalecolor(ctmp, nd.tdiff);
343                  flipsurface(r);
344                  if (hastexture) {
345                          FVECT  bnorm;
346                          bnorm[0] = -nd.pnorm[0];
347                          bnorm[1] = -nd.pnorm[1];
348                          bnorm[2] = -nd.pnorm[2];
349 <                        ambient(ctmp, r, bnorm);
349 >                        multambient(ctmp, r, bnorm);
350                  } else
351 <                        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 */
351 >                        multambient(ctmp, r, r->ron);
352                  addcolor(r->rcol, ctmp);
353                  flipsurface(r);
354          }
# Line 363 | Line 366 | m_normal(                      /* color a ray that hit something normal *
366  
367  
368   static void
369 < gaussamp(                       /* sample gaussian specular */
369 > gaussamp(                       /* sample Gaussian specular */
370          RAY  *r,
371          register NORMDAT  *np
372   )
# Line 389 | Line 392 | gaussamp(                      /* sample gaussian specular */
392          fcross(v, np->pnorm, u);
393                                          /* compute reflection */
394          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
395 <                        rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
395 >                        rayorigin(&sr, SPECULAR, r, np->scolor) == 0) {
396                  dimlist[ndims++] = (int)np->mp;
397                  for (niter = 0; niter < MAXITER; niter++) {
398                          if (niter)
# Line 412 | Line 415 | gaussamp(                      /* sample gaussian specular */
415                                  sr.rdir[i] = r->rdir[i] + d*h[i];
416                          if (DOT(sr.rdir, r->ron) > FTINY) {
417                                  rayvalue(&sr);
418 <                                multcolor(sr.rcol, np->scolor);
418 >                                multcolor(sr.rcol, sr.rcoef);
419                                  addcolor(r->rcol, sr.rcol);
420                                  break;
421                          }
# Line 420 | Line 423 | gaussamp(                      /* sample gaussian specular */
423                  ndims--;
424          }
425                                          /* compute transmission */
426 +        copycolor(sr.rcoef, np->mcolor);        /* modified by color */
427 +        scalecolor(sr.rcoef, np->tspec);
428          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
429 <                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
429 >                        rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) {
430                  dimlist[ndims++] = (int)np->mp;
431                  for (niter = 0; niter < MAXITER; niter++) {
432                          if (niter)
# Line 442 | Line 447 | gaussamp(                      /* sample gaussian specular */
447                          if (DOT(sr.rdir, r->ron) < -FTINY) {
448                                  normalize(sr.rdir);     /* OK, normalize */
449                                  rayvalue(&sr);
450 <                                scalecolor(sr.rcol, np->tspec);
446 <                                multcolor(sr.rcol, np->mcolor); /* modified */
450 >                                multcolor(sr.rcol, sr.rcoef);
451                                  addcolor(r->rcol, sr.rcol);
452                                  break;
453                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines