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.89 by greg, Sun May 11 19:03:37 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 263 | Line 262 | ambnotify(                     /* record new modifier */
262  
263   /************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/
264  
265 < #ifdef NEWAMB
265 > #ifndef OLDAMB
266  
267   #define tfunc(lwr, x, upr)      (((x)-(lwr))/((upr)-(lwr)))
268  
# Line 271 | Line 270 | static int     plugaleak(RAY *r, AMBVAL *ap, FVECT anorm,
270   static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
271                                  AMBTREE *at, FVECT c0, double s);
272   static int      makeambient(COLOR acol, RAY *r, FVECT rn, int al);
273 < static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
273 > static int      extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
274                                  FVECT uvw[3]);
275  
276   void
# 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 486 | Line 514 | sumambient(            /* get interpolated ambient value */
514                  /*
515                   *  Extrapolate value and compute final weight (hat function)
516                   */
517 <                extambient(ct, av, r->rop, rn, uvw);
517 >                if (!extambient(ct, av, r->rop, rn, uvw))
518 >                        continue;
519                  d = tfunc(maxangle, sqrt(delta_r2), 0.0) *
520                          tfunc(ambacc, sqrt(delta_t2), 0.0);
521                  scalecolor(ct, d);
# Line 537 | Line 566 | makeambient(           /* make a new ambient value for storage
566   }
567  
568  
569 < static void
569 > static int
570   extambient(             /* extrapolate value at pv, nv */
571          COLOR  cr,
572          AMBVAL   *ap,
# Line 546 | Line 575 | extambient(            /* extrapolate value at pv, nv */
575          FVECT  uvw[3]
576   )
577   {
578 +        const double    min_d = 0.05;
579          static FVECT    my_uvw[3];
580          FVECT           v1;
581          int             i;
# Line 565 | Line 595 | extambient(            /* extrapolate value at pv, nv */
595          for (i = 3; i--; )
596                  d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]);
597          
598 <        if (d <= 0.0) {
599 <                setcolor(cr, 0.0, 0.0, 0.0);
570 <                return;
571 <        }
598 >        if (d < min_d)                  /* should not use if we can avoid it */
599 >                d = min_d;
600          copycolor(cr, ap->val);
601          scalecolor(cr, d);
602 +        return(d > min_d);
603   }
604  
605  
# Line 633 | 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 653 | 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 663 | 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) /
# Line 1194 | Line 1251 | sortambvals(                   /* resort ambient values */
1251                  if (i_avlist < nambvals)
1252                          error(CONSISTENCY, "missing ambient values in sortambvals");
1253   #endif
1254 <                qsort((char *)avlist1, nambvals, sizeof(struct avl), &alatcmp);
1255 <                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), &aposcmp);
1254 >                qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp);
1255 >                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp);
1256                  for (i = 0; i < nambvals; i++) {
1257                          if (avlist1[i].p == NULL)
1258                                  continue;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines