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

Comparing ray/src/rt/aniso.c (file contents):
Revision 2.54 by greg, Sun Jul 29 19:01:39 2012 UTC vs.
Revision 2.58 by greg, Tue Feb 24 19:39:26 2015 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14   #include  "source.h"
15   #include  "func.h"
16   #include  "random.h"
17 + #include  "pmapmat.h"
18  
19   #ifndef  MAXITER
20   #define  MAXITER        10              /* maximum # specular ray attempts */
# Line 41 | Line 42 | static const char RCSid[] = "$Id$";
42   #define  SP_FLAT        04              /* reflecting surface is flat */
43   #define  SP_RBLT        010             /* reflection below sample threshold */
44   #define  SP_TBLT        020             /* transmission below threshold */
44 #define  SP_BADU        040             /* bad u direction calculation */
45  
46   typedef struct {
47          OBJREC  *mp;            /* material pointer */
# Line 61 | Line 61 | typedef struct {
61          double  pdot;           /* perturbed dot product */
62   }  ANISODAT;            /* anisotropic material data */
63  
64 < static void getacoords(RAY  *r, ANISODAT  *np);
65 < static void agaussamp(RAY  *r, ANISODAT  *np);
64 > static void getacoords(ANISODAT  *np);
65 > static void agaussamp(ANISODAT  *np);
66  
67  
68   static void
# Line 98 | Line 98 | diraniso(              /* compute source contribution */
98                  scalecolor(ctmp, dtmp);
99                  addcolor(cval, ctmp);
100          }
101 <        if (ldot > FTINY && (np->specfl&(SP_REFL|SP_BADU)) == SP_REFL) {
101 >
102 >        if ((ldot < -FTINY) & (np->tdiff > FTINY)) {
103                  /*
104 +                 *  Compute diffuse transmission.
105 +                 */
106 +                copycolor(ctmp, np->mcolor);
107 +                dtmp = -ldot * omega * np->tdiff * (1.0/PI);
108 +                scalecolor(ctmp, dtmp);
109 +                addcolor(cval, ctmp);
110 +        }
111 +
112 +        /* PMAP: skip direct specular refl via ambient bounce if already
113 +         * accounted for in photon map */
114 +        if (ambRayInPmap(np->rp))
115 +                return;
116 +        
117 +        if (ldot > FTINY && np->specfl&SP_REFL) {
118 +                /*
119                   *  Compute specular reflection coefficient using
120                   *  anisotropic Gaussian distribution model.
121                   */
# Line 131 | Line 147 | diraniso(              /* compute source contribution */
147                          addcolor(cval, ctmp);
148                  }
149          }
150 <        if ((ldot < -FTINY) & (np->tdiff > FTINY)) {
150 >        
151 >        if (ldot < -FTINY && np->specfl&SP_TRAN) {
152                  /*
136                 *  Compute diffuse transmission.
137                 */
138                copycolor(ctmp, np->mcolor);
139                dtmp = -ldot * omega * np->tdiff * (1.0/PI);
140                scalecolor(ctmp, dtmp);
141                addcolor(cval, ctmp);
142        }
143        if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_BADU)) == SP_TRAN) {
144                /*
153                   *  Compute specular transmission.  Specular transmission
154                   *  is always modified by material color.
155                   */
# Line 194 | Line 202 | m_aniso(                       /* shade ray that hit something anisotropic
202                  objerror(m, USER, "bad number of real arguments");
203                                                  /* check for back side */
204          if (r->rod < 0.0) {
205 <                if (!backvis && m->otype != MAT_TRANS2) {
205 >                if (!backvis) {
206                          raytrans(r);
207                          return(1);
208                  }
# Line 266 | Line 274 | m_aniso(                       /* shade ray that hit something anisotropic
274          if (r->ro != NULL && isflat(r->ro->otype))
275                  nd.specfl |= SP_FLAT;
276  
277 <        getacoords(r, &nd);                     /* set up coordinates */
277 >        getacoords(&nd);                        /* set up coordinates */
278  
279 <        if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_BADU))
280 <                agaussamp(r, &nd);
279 >        /* PMAP: skip indirect specular via ambient bounce if already accounted
280 >         * for in photon map */
281 >        if (!ambRayInPmap(r) && nd.specfl & (SP_REFL|SP_TRAN))
282 >                agaussamp(&nd);
283  
284          if (nd.rdiff > FTINY) {         /* ambient from this side */
285                  copycolor(ctmp, nd.mcolor);     /* modified by material color */
# Line 279 | Line 289 | m_aniso(                       /* shade ray that hit something anisotropic
289                  multambient(ctmp, r, nd.pnorm);
290                  addcolor(r->rcol, ctmp);        /* add to returned color */
291          }
292 +        
293          if (nd.tdiff > FTINY) {         /* ambient from other side */
294                  FVECT  bnorm;
295  
# Line 301 | Line 312 | m_aniso(                       /* shade ray that hit something anisotropic
312          return(1);
313   }
314  
304
315   static void
316   getacoords(             /* set up coordinate system */
307        RAY  *r,
317          ANISODAT  *np
318   )
319   {
# Line 312 | Line 321 | getacoords(            /* set up coordinate system */
321          int  i;
322  
323          mf = getfunc(np->mp, 3, 0x7, 1);
324 <        setfunc(np->mp, r);
324 >        setfunc(np->mp, np->rp);
325          errno = 0;
326          for (i = 0; i < 3; i++)
327                  np->u[i] = evalue(mf->ep[i]);
328 <        if ((errno == EDOM) | (errno == ERANGE)) {
329 <                objerror(np->mp, WARNING, "compute error");
321 <                np->specfl |= SP_BADU;
322 <                return;
323 <        }
328 >        if ((errno == EDOM) | (errno == ERANGE))
329 >                np->u[0] = np->u[1] = np->u[2] = 0.0;
330          if (mf->fxp != &unitxf)
331                  multv3(np->u, np->u, mf->fxp->xfm);
332          fcross(np->v, np->pnorm, np->u);
333          if (normalize(np->v) == 0.0) {
334 <                objerror(np->mp, WARNING, "illegal orientation vector");
335 <                np->specfl |= SP_BADU;
336 <                return;
337 <        }
338 <        fcross(np->u, np->v, np->pnorm);
334 >                if (fabs(np->u_alpha - np->v_alpha) > 0.001)
335 >                        objerror(np->mp, WARNING, "illegal orientation vector");
336 >                getperpendicular(np->u, np->pnorm);     /* punting */
337 >                fcross(np->v, np->pnorm, np->u);
338 >                np->u_alpha = np->v_alpha = sqrt( 0.5 *
339 >                        (np->u_alpha*np->u_alpha + np->v_alpha*np->v_alpha) );
340 >        } else
341 >                fcross(np->u, np->v, np->pnorm);
342   }
343  
344  
345   static void
346   agaussamp(              /* sample anisotropic Gaussian specular */
338        RAY  *r,
347          ANISODAT  *np
348   )
349   {
# Line 348 | Line 356 | agaussamp(             /* sample anisotropic Gaussian specular */
356          int  i;
357                                          /* compute reflection */
358          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
359 <                        rayorigin(&sr, SPECULAR, r, np->scolor) == 0) {
359 >                        rayorigin(&sr, SPECULAR, np->rp, np->scolor) == 0) {
360                  nstarget = 1;
361                  if (specjitter > 1.5) { /* multiple samples? */
362 <                        nstarget = specjitter*r->rweight + .5;
362 >                        nstarget = specjitter*np->rp->rweight + .5;
363                          if (sr.rweight <= minweight*nstarget)
364                                  nstarget = sr.rweight/minweight;
365                          if (nstarget > 1) {
# Line 388 | Line 396 | agaussamp(             /* sample anisotropic Gaussian specular */
396                          for (i = 0; i < 3; i++)
397                                  h[i] = np->pnorm[i] +
398                                          d*(cosp*np->u[i] + sinp*np->v[i]);
399 <                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
400 <                        VSUM(sr.rdir, r->rdir, h, d);
399 >                        d = -2.0 * DOT(h, np->rp->rdir) / (1.0 + d*d);
400 >                        VSUM(sr.rdir, np->rp->rdir, h, d);
401                                                  /* sample rejection test */
402 <                        if ((d = DOT(sr.rdir, r->ron)) <= FTINY)
402 >                        if ((d = DOT(sr.rdir, np->rp->ron)) <= FTINY)
403                                  continue;
404                          checknorm(sr.rdir);
405                          if (nstarget > 1) {     /* W-G-M-D adjustment */
406                                  if (nstaken) rayclear(&sr);
407                                  rayvalue(&sr);
408 <                                d = 2./(1. + r->rod/d);
408 >                                d = 2./(1. + np->rp->rod/d);
409                                  scalecolor(sr.rcol, d);
410                                  addcolor(scol, sr.rcol);
411                          } else {
412                                  rayvalue(&sr);
413                                  multcolor(sr.rcol, sr.rcoef);
414 <                                addcolor(r->rcol, sr.rcol);
414 >                                addcolor(np->rp->rcol, sr.rcol);
415                          }
416                          ++nstaken;
417                  }
# Line 411 | Line 419 | agaussamp(             /* sample anisotropic Gaussian specular */
419                          multcolor(scol, sr.rcoef);
420                          d = (double)nstarget/ntrials;
421                          scalecolor(scol, d);
422 <                        addcolor(r->rcol, scol);
422 >                        addcolor(np->rp->rcol, scol);
423                  }
424                  ndims--;
425          }
# Line 419 | Line 427 | agaussamp(             /* sample anisotropic Gaussian specular */
427          copycolor(sr.rcoef, np->mcolor);                /* modify by material color */
428          scalecolor(sr.rcoef, np->tspec);
429          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
430 <                        rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) {
430 >                        rayorigin(&sr, SPECULAR, np->rp, sr.rcoef) == 0) {
431                  nstarget = 1;
432                  if (specjitter > 1.5) { /* multiple samples? */
433 <                        nstarget = specjitter*r->rweight + .5;
433 >                        nstarget = specjitter*np->rp->rweight + .5;
434                          if (sr.rweight <= minweight*nstarget)
435                                  nstarget = sr.rweight/minweight;
436                          if (nstarget > 1) {
# Line 458 | Line 466 | agaussamp(             /* sample anisotropic Gaussian specular */
466                          for (i = 0; i < 3; i++)
467                                  sr.rdir[i] = np->prdir[i] +
468                                                  d*(cosp*np->u[i] + sinp*np->v[i]);
469 <                        if (DOT(sr.rdir, r->ron) >= -FTINY)
469 >                        if (DOT(sr.rdir, np->rp->ron) >= -FTINY)
470                                  continue;
471                          normalize(sr.rdir);     /* OK, normalize */
472                          if (nstaken)            /* multi-sampling */
473                                  rayclear(&sr);
474                          rayvalue(&sr);
475                          multcolor(sr.rcol, sr.rcoef);
476 <                        addcolor(r->rcol, sr.rcol);
476 >                        addcolor(np->rp->rcol, sr.rcol);
477                          ++nstaken;
478                  }
479                  ndims--;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines