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

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.93 by greg, Fri Nov 21 00:53:52 2014 UTC vs.
Revision 2.94 by greg, Tue Feb 24 19:39:26 2015 UTC

# Line 1 | Line 1
1 #ifndef lint
1   static const char       RCSid[] = "$Id$";
3 #endif
2   /*
3   *  ambient.c - routines dealing with ambient (inter-reflected) component.
4   *
# Line 17 | Line 15 | static const char      RCSid[] = "$Id$";
15   #include  "resolu.h"
16   #include  "ambient.h"
17   #include  "random.h"
18 + #include  "pmapamb.h"
19  
20   #ifndef  OCTSCALE
21   #define  OCTSCALE       1.0     /* ceil((valid rad.)/(cube size)) */
# Line 282 | Line 281 | multambient(           /* compute ambient component & multiply
281   )
282   {
283          static int  rdepth = 0;                 /* ambient recursion */
284 <        COLOR   acol;
284 >        COLOR   acol, caustic;
285          int     ok;
286          double  d, l;
287  
288 +        /* PMAP: Factor in ambient from photon map, if enabled and ray is
289 +         * ambient. Return as all ambient components accounted for, else
290 +         * continue. */
291 +        if (ambPmap(aval, r, rdepth))
292 +                return;
293 +
294 +        /* PMAP: Factor in specular-diffuse ambient (caustics) from photon
295 +         * map, if enabled and ray is primary, else caustic is zero.  Continue
296 +         * with RADIANCE ambient calculation */
297 +        copycolor(caustic, aval);
298 +        ambPmapCaustic(caustic, r, rdepth);
299 +        
300          if (ambdiv <= 0)                        /* no ambient calculation */
301                  goto dumbamb;
302                                                  /* check number of bounces */
# Line 305 | Line 316 | multambient(           /* compute ambient component & multiply
316                  if (!ok)
317                          goto dumbamb;
318                  copycolor(aval, acol);
319 +
320 +                /* PMAP: add in caustic */
321 +                addcolor(aval, caustic);
322                  return;
323          }
324  
# Line 314 | Line 328 | multambient(           /* compute ambient component & multiply
328          setcolor(acol, 0.0, 0.0, 0.0);
329          d = sumambient(acol, r, nrm, rdepth,
330                          &atrunk, thescene.cuorg, thescene.cusize);
331 +                        
332          if (d > FTINY) {
333                  d = 1.0/d;
334                  scalecolor(acol, d);
335                  multcolor(aval, acol);
336 +
337 +                /* PMAP: add in caustic */
338 +                addcolor(aval, caustic);
339                  return;
340          }
341 +        
342          rdepth++;                               /* need to cache new value */
343          ok = makeambient(acol, r, nrm, rdepth-1);
344          rdepth--;
345 +        
346          if (ok) {
347                  multcolor(aval, acol);          /* computed new value */
348 +
349 +                /* PMAP: add in caustic */
350 +                addcolor(aval, caustic);
351                  return;
352          }
353 +        
354   dumbamb:                                        /* return global value */
355          if ((ambvwt <= 0) | (navsum == 0)) {
356                  multcolor(aval, ambval);
357 +                
358 +                /* PMAP: add in caustic */
359 +                addcolor(aval, caustic);
360                  return;
361          }
362 <        l = bright(ambval);                     /* average in computations */
362 >        
363 >        l = bright(ambval);                     /* average in computations */  
364          if (l > FTINY) {
365                  d = (log(l)*(double)ambvwt + avsum) /
366                                  (double)(ambvwt + navsum);
# Line 634 | Line 662 | multambient(           /* compute ambient component & multiply
662   )
663   {
664          static int  rdepth = 0;                 /* ambient recursion */
665 <        COLOR   acol;
665 >        COLOR   acol, caustic;
666          double  d, l;
667  
668 +        /* PMAP: Factor in ambient from global photon map (if enabled) and return
669 +         * as all ambient components accounted for */
670 +        if (ambGlobalPmap(aval, r, rdepth))
671 +                return;
672 +
673 +        /* PMAP: Otherwise factor in ambient from caustic photon map
674 +         * (ambCausticPmap() returns zero if caustic photons disabled) and
675 +         * continue with RADIANCE ambient calculation */
676 +        copycolor(caustic, aval);
677 +        ambCausticPmap(caustic, r, rdepth);
678 +        
679          if (ambdiv <= 0)                        /* no ambient calculation */
680                  goto dumbamb;
681                                                  /* check number of bounces */
# Line 654 | Line 693 | multambient(           /* compute ambient component & multiply
693                  rdepth--;
694                  if (d <= FTINY)
695                          goto dumbamb;
696 <                copycolor(aval, acol);
696 >                copycolor(aval, acol);          
697 >        
698 >           /* PMAP: add in caustic */
699 >                addcolor(aval, caustic);        
700                  return;
701          }
702  
# Line 664 | Line 706 | multambient(           /* compute ambient component & multiply
706          setcolor(acol, 0.0, 0.0, 0.0);
707          d = sumambient(acol, r, nrm, rdepth,
708                          &atrunk, thescene.cuorg, thescene.cusize);
709 +                        
710          if (d > FTINY) {
711                  d = 1.0/d;
712                  scalecolor(acol, d);
713                  multcolor(aval, acol);
714 +                
715 +                /* PMAP: add in caustic */
716 +                addcolor(aval, caustic);        
717                  return;
718          }
719 +        
720          rdepth++;                               /* need to cache new value */
721          d = makeambient(acol, r, nrm, rdepth-1);
722          rdepth--;
723 +        
724          if (d > FTINY) {
725                  multcolor(aval, acol);          /* got new value */
726 +
727 +                /* PMAP: add in caustic */
728 +                addcolor(aval, caustic);                        
729                  return;
730          }
731 +        
732   dumbamb:                                        /* return global value */
733          if ((ambvwt <= 0) | (navsum == 0)) {
734                  multcolor(aval, ambval);
735 +
736 +                /* PMAP: add in caustic */
737 +                addcolor(aval, caustic);        
738                  return;
739          }
740 +        
741          l = bright(ambval);                     /* average in computations */
742          if (l > FTINY) {
743                  d = (log(l)*(double)ambvwt + avsum) /

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines