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.42 by greg, Thu Jan 2 09:37:13 1997 UTC vs.
Revision 2.44 by gwlarson, Wed Jun 17 13:29:55 1998 UTC

# Line 56 | Line 56 | static int  nunflshed = 0;     /* number of unflushed ambi
56   #define MAX_SORT_INTVL  (SORT_INTVL<<6)
57   #endif
58  
59 < static COLOR  avsum = BLKCOLOR;         /* computed ambient value sum */
59 > static double  avsum = 0.;              /* computed ambient value sum (log) */
60 > static unsigned int  navsum = 0;        /* number of values in avsum */
61   static unsigned int  nambvals = 0;      /* total number of indirect values */
62   static unsigned int  nambshare = 0;     /* number of values from file */
63   static unsigned long  ambclock = 0;     /* ambient access clock */
# Line 69 | Line 70 | static long  sortintvl = SORT_INTVL;   /* time until nex
70           * through memory on a multiprocessor, when we want to avoid
71           * claiming our own memory (copy on write).  Go ahead anyway
72           * if more than two thirds of our values are unshared.
73 +         * Compile with -Dtracktime=0 to turn this code off.
74           */
75 + #ifndef tracktime
76   #define tracktime       (shm_boundary == NULL || nambvals > 3*nambshare)
77 + #endif
78  
79   #define  AMBFLUSH       (BUFSIZ/AMBVALSIZ)
80  
81   #define  newambval()    (AMBVAL *)bmalloc(sizeof(AMBVAL))
82  
79 extern long  ftell(), lseek();
83   static int  initambfile(), avsave(), avinsert(), sortambvals(), avlmemi();
84   static AMBVAL  *avstore();
85   #ifdef  F_SETLKW
# Line 191 | Line 194 | register RAY  *r;
194   FVECT  nrm;
195   {
196          static int  rdepth = 0;                 /* ambient recursion */
197 <        double  d;
197 >        double  d, l;
198  
199          if (ambdiv <= 0)                        /* no ambient calculation */
200                  goto dumbamb;
# Line 229 | Line 232 | FVECT  nrm;
232                  return;
233   dumbamb:                                        /* return global value */
234          copycolor(acol, ambval);
235 <        if (ambvwt <= 0 | nambvals == 0)
235 >        if (ambvwt <= 0 | navsum == 0)
236                  return;
237 <        scalecolor(acol, (double)ambvwt);
238 <        addcolor(acol, avsum);                  /* average in computations */
239 <        d = 1.0/(ambvwt+nambvals);
240 <        scalecolor(acol, d);
237 >        l = bright(ambval);                     /* average in computations */
238 >        if (l > FTINY) {
239 >                d = (log(l)*(double)ambvwt + avsum) /
240 >                                (double)(ambvwt + navsum);
241 >                d = exp(d) / l;
242 >                scalecolor(acol, d);            /* apply color of ambval */
243 >        } else {
244 >                d = exp( avsum / (double)navsum );
245 >                setcolor(acol, d, d, d);        /* neutral color */
246 >        }
247   }
248  
249  
# Line 443 | Line 452 | avstore(aval)                          /* allocate memory and store aval */
452   register AMBVAL  *aval;
453   {
454          register AMBVAL  *av;
455 +        double  d;
456  
457          if ((av = newambval()) == NULL)
458                  error(SYSTEM, "out of memory in avstore");
459          copystruct(av, aval);
460          av->latick = ambclock;
461          av->next = NULL;
452        addcolor(avsum, av->val);       /* add to sum for averaging */
462          nambvals++;
463 +        d = bright(av->val);
464 +        if (d > FTINY) {                /* add to log sum for averaging */
465 +                avsum += log(d);
466 +                navsum++;
467 +        }
468          return(av);
469   }
470  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines