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.98 by greg, Sun Aug 23 00:17:12 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 197 | Line 196 | setambient(void)                               /* initialize calculation */
196                  sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile);
197                  error(SYSTEM, errmsg);
198          }
200 #ifdef getc_unlocked
201        flockfile(ambfp);                       /* application-level lock */
202 #endif
199   #ifdef  F_SETLKW
200          aflock(F_UNLCK);                        /* release file */
201   #endif
# Line 282 | Line 278 | multambient(           /* compute ambient component & multiply
278   )
279   {
280          static int  rdepth = 0;                 /* ambient recursion */
281 <        COLOR   acol;
281 >        COLOR   acol, caustic;
282          int     ok;
283          double  d, l;
284  
285 +        /* PMAP: Factor in ambient from photon map, if enabled and ray is
286 +         * ambient. Return as all ambient components accounted for, else
287 +         * continue. */
288 +        if (ambPmap(aval, r, rdepth))
289 +                return;
290 +
291 +        /* PMAP: Factor in specular-diffuse ambient (caustics) from photon
292 +         * map, if enabled and ray is primary, else caustic is zero.  Continue
293 +         * with RADIANCE ambient calculation */
294 +        copycolor(caustic, aval);
295 +        ambPmapCaustic(caustic, r, rdepth);
296 +        
297          if (ambdiv <= 0)                        /* no ambient calculation */
298                  goto dumbamb;
299                                                  /* check number of bounces */
# Line 305 | Line 313 | multambient(           /* compute ambient component & multiply
313                  if (!ok)
314                          goto dumbamb;
315                  copycolor(aval, acol);
316 +
317 +                /* PMAP: add in caustic */
318 +                addcolor(aval, caustic);
319                  return;
320          }
321  
# Line 314 | Line 325 | multambient(           /* compute ambient component & multiply
325          setcolor(acol, 0.0, 0.0, 0.0);
326          d = sumambient(acol, r, nrm, rdepth,
327                          &atrunk, thescene.cuorg, thescene.cusize);
328 +                        
329          if (d > FTINY) {
330                  d = 1.0/d;
331                  scalecolor(acol, d);
332                  multcolor(aval, acol);
333 +
334 +                /* PMAP: add in caustic */
335 +                addcolor(aval, caustic);
336                  return;
337          }
338 +        
339          rdepth++;                               /* need to cache new value */
340          ok = makeambient(acol, r, nrm, rdepth-1);
341          rdepth--;
342 +        
343          if (ok) {
344                  multcolor(aval, acol);          /* computed new value */
345 +
346 +                /* PMAP: add in caustic */
347 +                addcolor(aval, caustic);
348                  return;
349          }
350 +        
351   dumbamb:                                        /* return global value */
352          if ((ambvwt <= 0) | (navsum == 0)) {
353                  multcolor(aval, ambval);
354 +                
355 +                /* PMAP: add in caustic */
356 +                addcolor(aval, caustic);
357                  return;
358          }
359 <        l = bright(ambval);                     /* average in computations */
359 >        
360 >        l = bright(ambval);                     /* average in computations */  
361          if (l > FTINY) {
362                  d = (log(l)*(double)ambvwt + avsum) /
363                                  (double)(ambvwt + navsum);
# Line 634 | Line 659 | multambient(           /* compute ambient component & multiply
659   )
660   {
661          static int  rdepth = 0;                 /* ambient recursion */
662 <        COLOR   acol;
662 >        COLOR   acol, caustic;
663          double  d, l;
664  
665 +        /* PMAP: Factor in ambient from global photon map (if enabled) and return
666 +         * as all ambient components accounted for */
667 +        if (ambPmap(aval, r, rdepth))
668 +                return;
669 +
670 +        /* PMAP: Otherwise factor in ambient from caustic photon map
671 +         * (ambPmapCaustic() returns zero if caustic photons disabled) and
672 +         * continue with RADIANCE ambient calculation */
673 +        copycolor(caustic, aval);
674 +        ambPmapCaustic(caustic, r, rdepth);
675 +        
676          if (ambdiv <= 0)                        /* no ambient calculation */
677                  goto dumbamb;
678                                                  /* check number of bounces */
# Line 654 | Line 690 | multambient(           /* compute ambient component & multiply
690                  rdepth--;
691                  if (d <= FTINY)
692                          goto dumbamb;
693 <                copycolor(aval, acol);
693 >                copycolor(aval, acol);          
694 >        
695 >           /* PMAP: add in caustic */
696 >                addcolor(aval, caustic);        
697                  return;
698          }
699  
# Line 664 | Line 703 | multambient(           /* compute ambient component & multiply
703          setcolor(acol, 0.0, 0.0, 0.0);
704          d = sumambient(acol, r, nrm, rdepth,
705                          &atrunk, thescene.cuorg, thescene.cusize);
706 +                        
707          if (d > FTINY) {
708                  d = 1.0/d;
709                  scalecolor(acol, d);
710                  multcolor(aval, acol);
711 +                
712 +                /* PMAP: add in caustic */
713 +                addcolor(aval, caustic);        
714                  return;
715          }
716 +        
717          rdepth++;                               /* need to cache new value */
718          d = makeambient(acol, r, nrm, rdepth-1);
719          rdepth--;
720 +        
721          if (d > FTINY) {
722                  multcolor(aval, acol);          /* got new value */
723 +
724 +                /* PMAP: add in caustic */
725 +                addcolor(aval, caustic);                        
726                  return;
727          }
728 +        
729   dumbamb:                                        /* return global value */
730          if ((ambvwt <= 0) | (navsum == 0)) {
731                  multcolor(aval, ambval);
732 +
733 +                /* PMAP: add in caustic */
734 +                addcolor(aval, caustic);        
735                  return;
736          }
737 +        
738          l = bright(ambval);                     /* average in computations */
739          if (l > FTINY) {
740                  d = (log(l)*(double)ambvwt + avsum) /

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines