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.59 by greg, Wed Oct 13 15:29:02 2010 UTC vs.
Revision 2.71 by greg, Tue May 26 13:21:07 2015 UTC

# Line 19 | Line 19 | static const char RCSid[] = "$Id$";
19   #include  "otypes.h"
20   #include  "rtotypes.h"
21   #include  "random.h"
22 + #include  "pmapmat.h"
23  
24   #ifndef  MAXITER
25   #define  MAXITER        10              /* maximum # specular ray attempts */
# Line 65 | Line 66 | typedef struct {
66          double  pdot;           /* perturbed dot product */
67   }  NORMDAT;             /* normal material data */
68  
69 < static srcdirf_t dirnorm;
69 < static void gaussamp(RAY  *r, NORMDAT  *np);
69 > static void gaussamp(NORMDAT  *np);
70  
71  
72   static void
73   dirnorm(                /* compute source contribution */
74          COLOR  cval,                    /* returned coefficient */
75 <        void  *nnp,             /* material data */
75 >        void  *nnp,                     /* material data */
76          FVECT  ldir,                    /* light source direction */
77          double  omega                   /* light source size */
78   )
79   {
80 <        register NORMDAT *np = nnp;
80 >        NORMDAT *np = nnp;
81          double  ldot;
82          double  lrdiff, ltdiff;
83          double  dtmp, d2, d3, d4;
# Line 112 | Line 112 | dirnorm(               /* compute source contribution */
112                  scalecolor(ctmp, dtmp);
113                  addcolor(cval, ctmp);
114          }
115 +        
116 +        if (ldot < -FTINY && ltdiff > FTINY) {
117 +                /*
118 +                 *  Compute diffuse transmission.
119 +                 */
120 +                copycolor(ctmp, np->mcolor);
121 +                dtmp = -ldot * omega * ltdiff * (1.0/PI);
122 +                scalecolor(ctmp, dtmp);
123 +                addcolor(cval, ctmp);
124 +        }
125 +        
126          if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE)) == SP_REFL) {
127                  /*
128                   *  Compute specular reflection coefficient using
# Line 123 | Line 134 | dirnorm(               /* compute source contribution */
134                  if (np->specfl & SP_FLAT)
135                          dtmp += omega * (0.25/PI);
136                                                  /* half vector */
137 <                vtmp[0] = ldir[0] - np->rp->rdir[0];
127 <                vtmp[1] = ldir[1] - np->rp->rdir[1];
128 <                vtmp[2] = ldir[2] - np->rp->rdir[2];
137 >                VSUB(vtmp, ldir, np->rp->rdir);
138                  d2 = DOT(vtmp, np->pnorm);
139                  d2 *= d2;
140                  d3 = DOT(vtmp,vtmp);
# Line 140 | Line 149 | dirnorm(               /* compute source contribution */
149                          addcolor(cval, ctmp);
150                  }
151          }
152 <        if (ldot < -FTINY && ltdiff > FTINY) {
153 <                /*
145 <                 *  Compute diffuse transmission.
146 <                 */
147 <                copycolor(ctmp, np->mcolor);
148 <                dtmp = -ldot * omega * ltdiff * (1.0/PI);
149 <                scalecolor(ctmp, dtmp);
150 <                addcolor(cval, ctmp);
151 <        }
152 >        
153 >
154          if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_PURE)) == SP_TRAN) {
155                  /*
156                   *  Compute specular transmission.  Specular transmission
# Line 169 | Line 171 | dirnorm(               /* compute source contribution */
171   }
172  
173  
174 < extern int
174 > int
175   m_normal(                       /* color a ray that hit something normal */
176 <        register OBJREC  *m,
177 <        register RAY  *r
176 >        OBJREC  *m,
177 >        RAY  *r
178   )
179   {
180          NORMDAT  nd;
# Line 182 | Line 184 | m_normal(                      /* color a ray that hit something normal *
184          int     hastexture;
185          double  d;
186          COLOR  ctmp;
187 <        register int  i;
187 >        int  i;
188 >
189 >        /* PMAP: skip transmitted shadow ray if accounted for in photon map */
190 >        if (shadowRayInPmap(r))
191 >                return(1);
192                                                  /* easy shadow test */
193          if (r->crtype & SHADOW && m->otype != MAT_TRANS)
194                  return(1);
# Line 191 | Line 197 | m_normal(                      /* color a ray that hit something normal *
197                  objerror(m, USER, "bad number of arguments");
198                                                  /* check for back side */
199          if (r->rod < 0.0) {
200 <                if (!backvis && m->otype != MAT_TRANS) {
200 >                if (!backvis) {
201                          raytrans(r);
202                          return(1);
203                  }
# Line 227 | Line 233 | m_normal(                      /* color a ray that hit something normal *
233          nd.rspec = m->oargs.farg[3];
234                                                  /* compute Fresnel approx. */
235          if (nd.specfl & SP_PURE && nd.rspec >= FRESTHRESH) {
236 <                fest = FRESNE(r->rod);
236 >                fest = FRESNE(nd.pdot);
237                  nd.rspec += fest*(1. - nd.rspec);
238          } else
239                  fest = 0.;
# Line 242 | Line 248 | m_normal(                      /* color a ray that hit something normal *
248                          if (!(nd.specfl & SP_PURE) &&
249                                          specthresh >= nd.tspec-FTINY)
250                                  nd.specfl |= SP_TBLT;
251 <                        if (!hastexture || r->crtype & SHADOW) {
251 >                        if (!hastexture || r->crtype & (SHADOW|AMBIENT)) {
252                                  VCOPY(nd.prdir, r->rdir);
253                                  transtest = 2;
254                          } else {
# Line 257 | Line 263 | m_normal(                      /* color a ray that hit something normal *
263          } else
264                  nd.tdiff = nd.tspec = nd.trans = 0.0;
265                                                  /* transmitted ray */
266 +
267          if ((nd.specfl&(SP_TRAN|SP_PURE|SP_TBLT)) == (SP_TRAN|SP_PURE)) {
268                  RAY  lr;
269                  copycolor(lr.rcoef, nd.mcolor); /* modified by color */
# Line 283 | Line 290 | m_normal(                      /* color a ray that hit something normal *
290                  if (m->otype != MAT_METAL) {
291                          setcolor(nd.scolor, nd.rspec, nd.rspec, nd.rspec);
292                  } else if (fest > FTINY) {
293 <                        d = nd.rspec*(1. - fest);
293 >                        d = m->oargs.farg[3]*(1. - fest);
294                          for (i = 0; i < 3; i++)
295 <                                nd.scolor[i] = fest + nd.mcolor[i]*d;
295 >                                colval(nd.scolor,i) = fest +
296 >                                                colval(nd.mcolor,i)*d;
297                  } else {
298                          copycolor(nd.scolor, nd.mcolor);
299                          scalecolor(nd.scolor, nd.rspec);
# Line 308 | Line 316 | m_normal(                      /* color a ray that hit something normal *
316                          rayvalue(&lr);
317                          multcolor(lr.rcol, lr.rcoef);
318                          addcolor(r->rcol, lr.rcol);
319 <                        if (!hastexture && nd.specfl & SP_FLAT) {
319 >                        if (nd.specfl & SP_FLAT &&
320 >                                        !hastexture | (r->crtype & AMBIENT)) {
321                                  mirtest = 2.*bright(lr.rcol);
322                                  mirdist = r->rot + lr.rt;
323                          }
# Line 321 | Line 330 | m_normal(                      /* color a ray that hit something normal *
330                  return(1);                      /* 100% pure specular */
331  
332          if (!(nd.specfl & SP_PURE))
333 <                gaussamp(r, &nd);               /* checks *BLT flags */
333 >                gaussamp(&nd);                  /* checks *BLT flags */
334  
335          if (nd.rdiff > FTINY) {         /* ambient from this side */
336                  copycolor(ctmp, nd.mcolor);     /* modified by material color */
337 <                if (nd.specfl & SP_RBLT)
338 <                        scalecolor(ctmp, 1.0-nd.trans);
339 <                else
331 <                        scalecolor(ctmp, nd.rdiff);
337 >                scalecolor(ctmp, nd.rdiff);
338 >                if (nd.specfl & SP_RBLT)        /* add in specular as well? */
339 >                        addcolor(ctmp, nd.scolor);
340                  multambient(ctmp, r, hastexture ? nd.pnorm : r->ron);
341                  addcolor(r->rcol, ctmp);        /* add to returned color */
342          }
# Line 365 | Line 373 | m_normal(                      /* color a ray that hit something normal *
373  
374   static void
375   gaussamp(                       /* sample Gaussian specular */
376 <        RAY  *r,
369 <        register NORMDAT  *np
376 >        NORMDAT  *np
377   )
378   {
379          RAY  sr;
380          FVECT  u, v, h;
381          double  rv[2];
382          double  d, sinp, cosp;
383 <        COLOR   scol;
383 >        COLOR  scol;
384          int  maxiter, ntrials, nstarget, nstaken;
385 <        register int  i;
385 >        int  i;
386                                          /* quick test */
387          if ((np->specfl & (SP_REFL|SP_RBLT)) != SP_REFL &&
388                          (np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN)
389                  return;
390                                          /* set up sample coordinates */
391 <        v[0] = v[1] = v[2] = 0.0;
385 <        for (i = 0; i < 3; i++)
386 <                if (np->pnorm[i] < 0.6 && np->pnorm[i] > -0.6)
387 <                        break;
388 <        v[i] = 1.0;
389 <        fcross(u, v, np->pnorm);
390 <        normalize(u);
391 >        getperpendicular(u, np->pnorm, rand_samp);
392          fcross(v, np->pnorm, u);
393                                          /* compute reflection */
394          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
395 <                        rayorigin(&sr, SPECULAR, r, np->scolor) == 0) {
395 >                        rayorigin(&sr, SPECULAR, np->rp, np->scolor) == 0) {
396                  nstarget = 1;
397                  if (specjitter > 1.5) { /* multiple samples? */
398 <                        nstarget = specjitter*r->rweight + .5;
398 >                        nstarget = specjitter*np->rp->rweight + .5;
399                          if (sr.rweight <= minweight*nstarget)
400                                  nstarget = sr.rweight/minweight;
401                          if (nstarget > 1) {
# Line 405 | Line 406 | gaussamp(                      /* sample Gaussian specular */
406                                  nstarget = 1;
407                  }
408                  setcolor(scol, 0., 0., 0.);
409 <                dimlist[ndims++] = (int)np->mp;
409 >                dimlist[ndims++] = (int)(size_t)np->mp;
410                  maxiter = MAXITER*nstarget;
411                  for (nstaken = ntrials = 0; nstaken < nstarget &&
412                                                  ntrials < maxiter; ntrials++) {
# Line 425 | Line 426 | gaussamp(                      /* sample Gaussian specular */
426                                  d = sqrt( np->alpha2 * -log(rv[1]) );
427                          for (i = 0; i < 3; i++)
428                                  h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
429 <                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
430 <                        VSUM(sr.rdir, r->rdir, h, d);
429 >                        d = -2.0 * DOT(h, np->rp->rdir) / (1.0 + d*d);
430 >                        VSUM(sr.rdir, np->rp->rdir, h, d);
431                                                  /* sample rejection test */
432 <                        if ((d = DOT(sr.rdir, r->ron)) <= FTINY)
432 >                        if ((d = DOT(sr.rdir, np->rp->ron)) <= FTINY)
433                                  continue;
434                          checknorm(sr.rdir);
435                          if (nstarget > 1) {     /* W-G-M-D adjustment */
436                                  if (nstaken) rayclear(&sr);
437                                  rayvalue(&sr);
438 <                                d = 2./(1. + r->rod/d);
438 >                                d = 2./(1. + np->rp->rod/d);
439                                  scalecolor(sr.rcol, d);
440                                  addcolor(scol, sr.rcol);
441                          } else {
442                                  rayvalue(&sr);
443                                  multcolor(sr.rcol, sr.rcoef);
444 <                                addcolor(r->rcol, sr.rcol);
444 >                                addcolor(np->rp->rcol, sr.rcol);
445                          }
446                          ++nstaken;
447                  }
# Line 448 | Line 449 | gaussamp(                      /* sample Gaussian specular */
449                          multcolor(scol, sr.rcoef);
450                          d = (double)nstarget/ntrials;
451                          scalecolor(scol, d);
452 <                        addcolor(r->rcol, scol);
452 >                        addcolor(np->rp->rcol, scol);
453                  }
454                  ndims--;
455          }
# Line 456 | Line 457 | gaussamp(                      /* sample Gaussian specular */
457          copycolor(sr.rcoef, np->mcolor);        /* modified by color */
458          scalecolor(sr.rcoef, np->tspec);
459          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
460 <                        rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) {
460 >                        rayorigin(&sr, SPECULAR, np->rp, sr.rcoef) == 0) {
461                  nstarget = 1;
462                  if (specjitter > 1.5) { /* multiple samples? */
463 <                        nstarget = specjitter*r->rweight + .5;
463 >                        nstarget = specjitter*np->rp->rweight + .5;
464                          if (sr.rweight <= minweight*nstarget)
465                                  nstarget = sr.rweight/minweight;
466                          if (nstarget > 1) {
# Line 469 | Line 470 | gaussamp(                      /* sample Gaussian specular */
470                          } else
471                                  nstarget = 1;
472                  }
473 <                dimlist[ndims++] = (int)np->mp;
473 >                dimlist[ndims++] = (int)(size_t)np->mp;
474                  maxiter = MAXITER*nstarget;
475                  for (nstaken = ntrials = 0; nstaken < nstarget &&
476                                                  ntrials < maxiter; ntrials++) {
# Line 490 | Line 491 | gaussamp(                      /* sample Gaussian specular */
491                          for (i = 0; i < 3; i++)
492                                  sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
493                                                  /* sample rejection test */
494 <                        if (DOT(sr.rdir, r->ron) >= -FTINY)
494 >                        if (DOT(sr.rdir, np->rp->ron) >= -FTINY)
495                                  continue;
496                          normalize(sr.rdir);     /* OK, normalize */
497                          if (nstaken)            /* multi-sampling */
498                                  rayclear(&sr);
499                          rayvalue(&sr);
500                          multcolor(sr.rcol, sr.rcoef);
501 <                        addcolor(r->rcol, sr.rcol);
501 >                        addcolor(np->rp->rcol, sr.rcol);
502                          ++nstaken;
503                  }
504                  ndims--;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines