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.66 by greg, Sat Jan 25 18:27:39 2014 UTC vs.
Revision 2.77 by greg, Tue Nov 13 19:58:33 2018 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 111 | 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 (ambRayInPmap(np->rp))
127 +                return;         /* specular already in photon map */
128 +
129          if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE)) == SP_REFL) {
130                  /*
131                   *  Compute specular reflection coefficient using
# Line 137 | Line 152 | dirnorm(               /* compute source contribution */
152                          addcolor(cval, ctmp);
153                  }
154          }
155 <        if (ldot < -FTINY && ltdiff > FTINY) {
156 <                /*
142 <                 *  Compute diffuse transmission.
143 <                 */
144 <                copycolor(ctmp, np->mcolor);
145 <                dtmp = -ldot * omega * ltdiff * (1.0/PI);
146 <                scalecolor(ctmp, dtmp);
147 <                addcolor(cval, ctmp);
148 <        }
155 >        
156 >
157          if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_PURE)) == SP_TRAN) {
158                  /*
159                   *  Compute specular transmission.  Specular transmission
# Line 174 | Line 182 | m_normal(                      /* color a ray that hit something normal *
182   {
183          NORMDAT  nd;
184          double  fest;
177        double  transtest, transdist;
178        double  mirtest, mirdist;
185          int     hastexture;
186          double  d;
187          COLOR  ctmp;
188          int  i;
189 +
190 +        /* PMAP: skip transmitted shadow ray if accounted for in photon map */
191 +        /* No longer needed?
192 +        if (shadowRayInPmap(r) || ambRayInPmap(r))
193 +                return(1); */          
194 +                
195                                                  /* easy shadow test */
196          if (r->crtype & SHADOW && m->otype != MAT_TRANS)
197                  return(1);
# Line 219 | Line 231 | m_normal(                      /* color a ray that hit something normal *
231          if (nd.pdot < .001)
232                  nd.pdot = .001;                 /* non-zero for dirnorm() */
233          multcolor(nd.mcolor, r->pcol);          /* modify material color */
222        mirtest = transtest = 0;
223        mirdist = transdist = r->rot;
234          nd.rspec = m->oargs.farg[3];
235                                                  /* compute Fresnel approx. */
236          if (nd.specfl & SP_PURE && nd.rspec >= FRESTHRESH) {
# Line 239 | Line 249 | m_normal(                      /* color a ray that hit something normal *
249                          if (!(nd.specfl & SP_PURE) &&
250                                          specthresh >= nd.tspec-FTINY)
251                                  nd.specfl |= SP_TBLT;
252 <                        if (!hastexture || r->crtype & SHADOW) {
252 >                        if (!hastexture || r->crtype & (SHADOW|AMBIENT)) {
253                                  VCOPY(nd.prdir, r->rdir);
244                                transtest = 2;
254                          } else {
255 <                                for (i = 0; i < 3; i++)         /* perturb */
256 <                                        nd.prdir[i] = r->rdir[i] - r->pert[i];
255 >                                                        /* perturb */
256 >                                VSUB(nd.prdir, r->rdir, r->pert);
257                                  if (DOT(nd.prdir, r->ron) < -FTINY)
258                                          normalize(nd.prdir);    /* OK */
259                                  else
# Line 254 | 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 263 | Line 273 | m_normal(                      /* color a ray that hit something normal *
273                          rayvalue(&lr);
274                          multcolor(lr.rcol, lr.rcoef);
275                          addcolor(r->rcol, lr.rcol);
276 <                        transtest *= bright(lr.rcol);
267 <                        transdist = r->rot + lr.rt;
276 >                        r->rxt = r->rot + raydistance(&lr);
277                  }
278 <        } else
270 <                transtest = 0;
278 >        }
279  
280 <        if (r->crtype & SHADOW) {               /* the rest is shadow */
273 <                r->rt = transdist;
280 >        if (r->crtype & SHADOW)                 /* the rest is shadow */
281                  return(1);
275        }
282                                                  /* get specular reflection */
283          if (nd.rspec > FTINY) {
284                  nd.specfl |= SP_REFL;
# Line 305 | Line 311 | m_normal(                      /* color a ray that hit something normal *
311                          VCOPY(lr.rdir, nd.vrefl);
312                          rayvalue(&lr);
313                          multcolor(lr.rcol, lr.rcoef);
314 +                        copycolor(r->mcol, lr.rcol);
315                          addcolor(r->rcol, lr.rcol);
316 <                        if (!hastexture && nd.specfl & SP_FLAT) {
317 <                                mirtest = 2.*bright(lr.rcol);
318 <                                mirdist = r->rot + lr.rt;
312 <                        }
316 >                        if (nd.specfl & SP_FLAT &&
317 >                                        !hastexture | (r->crtype & AMBIENT))
318 >                                r->rmt = r->rot + raydistance(&lr);
319                  }
320          }
321                                                  /* diffuse reflection */
# Line 319 | Line 325 | m_normal(                      /* color a ray that hit something normal *
325                  return(1);                      /* 100% pure specular */
326  
327          if (!(nd.specfl & SP_PURE))
328 <                gaussamp(&nd);          /* checks *BLT flags */
328 >                gaussamp(&nd);                  /* checks *BLT flags */
329  
330          if (nd.rdiff > FTINY) {         /* ambient from this side */
331                  copycolor(ctmp, nd.mcolor);     /* modified by material color */
# Line 349 | Line 355 | m_normal(                      /* color a ray that hit something normal *
355          }
356                                          /* add direct component */
357          direct(r, dirnorm, &nd);
352                                        /* check distance */
353        d = bright(r->rcol);
354        if (transtest > d)
355                r->rt = transdist;
356        else if (mirtest > d)
357                r->rt = mirdist;
358  
359          return(1);
360   }
# Line 377 | Line 377 | gaussamp(                      /* sample Gaussian specular */
377                          (np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN)
378                  return;
379                                          /* set up sample coordinates */
380 <        v[0] = v[1] = v[2] = 0.0;
381 <        for (i = 0; i < 3; i++)
382 <                if (np->pnorm[i] < 0.6 && np->pnorm[i] > -0.6)
383 <                        break;
384 <        v[i] = 1.0;
385 <        fcross(u, v, np->pnorm);
386 <        normalize(u);
380 >        getperpendicular(u, np->pnorm, rand_samp);
381          fcross(v, np->pnorm, u);
382                                          /* compute reflection */
383          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines