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.40 by greg, Tue Jul 9 21:56:44 1996 UTC vs.
Revision 2.44 by gwlarson, Wed Jun 17 13:29:55 1998 UTC

# Line 50 | Line 50 | static int  nunflshed = 0;     /* number of unflushed ambi
50   #endif
51   #endif
52   #ifndef SORT_INTVL
53 < #define SORT_INTVL      (SORT_THRESH<<4)
53 > #define SORT_INTVL      (SORT_THRESH<<1)
54   #endif
55   #ifndef MAX_SORT_INTVL
56 < #define MAX_SORT_INTVL  (SORT_INTVL<<8)
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 144 | Line 147 | char  *afile;
147                  pos += (long)nambvals*AMBVALSIZ;
148                  flen = lseek(fileno(ambfp), 0L, 2);
149                  if (flen != pos) {
150 <                        error(WARNING,
150 >                        sprintf(errmsg,
151                          "ignoring last %ld values in ambient file (corrupted)",
152                                          (flen - pos)/AMBVALSIZ);
153 +                        error(WARNING, errmsg);
154                          fseek(ambfp, pos, 0);
155                          ftruncate(fileno(ambfp), pos);
156                  }
# Line 190 | 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 228 | 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 403 | Line 413 | int  creat;
413          setbuf(ambfp, bmalloc(BUFSIZ+8));
414          if (creat) {                    /* new file */
415                  newheader("RADIANCE", ambfp);
416 <                fprintf(ambfp, "%s -av %g %g %g -ab %d -aa %g ",
416 >                fprintf(ambfp, "%s -av %g %g %g -aw %d -ab %d -aa %g ",
417                                  progname, colval(ambval,RED),
418                                  colval(ambval,GRN), colval(ambval,BLU),
419 <                                ambounce, ambacc);
419 >                                ambvwt, ambounce, ambacc);
420                  fprintf(ambfp, "-ad %d -as %d -ar %d %s\n",
421                                  ambdiv, ambssamp, ambres,
422                                  octname==NULL ? "" : octname);
# Line 442 | 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;
451        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