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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines