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.27 by greg, Sat Apr 29 10:51:28 1995 UTC vs.
Revision 2.32 by greg, Tue Oct 17 18:22:47 1995 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "random.h"
20  
21 < #define  OCTSCALE       0.5     /* ceil((valid rad.)/(cube size)) */
21 > #ifndef  OCTSCALE
22 > #define  OCTSCALE       1.0     /* ceil((valid rad.)/(cube size)) */
23 > #endif
24 > #ifndef  AMBVWT
25 > #define  AMBVWT         250     /* relative ambient value weight (# calcs) */
26 > #endif
27  
28   typedef struct ambtree {
29          AMBVAL  *alist;         /* ambient value list */
# Line 48 | Line 53 | static int  nunflshed = 0;     /* number of unflushed ambi
53   #endif
54   #endif
55   #ifndef SORT_INTVL
56 < #define SORT_INTVL      (SORT_THRESH*8)
56 > #define SORT_INTVL      (SORT_THRESH*256)
57   #endif
58 + #ifndef MAX_SORT_INTVL
59 + #define MAX_SORT_INTVL  (SORT_INTVL<<4)
60 + #endif
61  
62 + static COLOR  avsum = BLKCOLOR;         /* computed ambient value sum */
63 + static unsigned int  nambvals = 0;      /* number of computed ambient values */
64   static unsigned long  ambclock = 0;     /* ambient access clock */
55 static unsigned int  nambvals = 0;      /* number of stored ambient values */
65   static unsigned long  lastsort = 0;     /* time of last value sort */
66   static long  sortintvl = SORT_INTVL;    /* time until next sort */
67  
# Line 63 | Line 72 | static long  sortintvl = SORT_INTVL;   /* time until nex
72           * claiming our own memory (copy on write).
73           */
74   #define tracktime       (shm_boundary == NULL || ambfp == NULL)
66 #define checksort()     if (ambclock > lastsort+sortintvl && \
67                        nambvals > SORT_THRESH) sortambvals(0)
75  
76   #define  AMBFLUSH       (BUFSIZ/AMBVALSIZ)
77  
# Line 88 | Line 95 | int  ar;
95                  maxarad = thescene.cusize / 2.0;
96          } else {
97                  minarad = thescene.cusize / ar;
98 <                maxarad = 16 * minarad;                 /* heuristic */
98 >                maxarad = 64 * minarad;                 /* heuristic */
99                  if (maxarad > thescene.cusize / 2.0)
100                          maxarad = thescene.cusize / 2.0;
101          }
# Line 195 | Line 202 | register RAY  *r;
202                  rdepth++;
203                  d = doambient(acol, r, r->rweight, NULL, NULL);
204                  rdepth--;
205 <                if (d == 0.0)
205 >                if (d <= FTINY)
206                          goto dumbamb;
207                  return;
208          }
209                                                  /* resort memory? */
210 <        checksort();
210 >        sortambvals(0);
211                                                  /* get ambient value */
212          setcolor(acol, 0.0, 0.0, 0.0);
213          d = sumambient(acol, r, rdepth,
214                          &atrunk, thescene.cuorg, thescene.cusize);
215 <        if (d > FTINY)
215 >        if (d > FTINY) {
216                  scalecolor(acol, 1.0/d);
217 <        else {
211 <                d = makeambient(acol, r, rdepth++);
212 <                rdepth--;
217 >                return;
218          }
219 +        rdepth++;
220 +        d = makeambient(acol, r, rdepth-1);
221 +        rdepth--;
222          if (d > FTINY)
223                  return;
224   dumbamb:                                        /* return global value */
225          copycolor(acol, ambval);
226 + #if  AMBVWT
227 +        if (nambvals == 0)
228 +                return;
229 +        scalecolor(acol, (double)AMBVWT);
230 +        addcolor(acol, avsum);                  /* average in computations */
231 +        d = 1.0/(AMBVWT+nambvals);
232 +        scalecolor(acol, d);
233 + #endif
234   }
235  
236  
# Line 233 | Line 249 | double s;
249          int  i;
250          register int  j;
251          register AMBVAL  *av;
252 <                                        /* do this node */
252 >
253          wsum = 0.0;
254 +                                        /* do this node */
255          for (av = at->alist; av != NULL; av = av->next) {
256                  if (tracktime)
257                          av->latick = ambclock++;
# Line 248 | Line 265 | double s;
265                  /*
266                   *  Ambient radius test.
267                   */
268 <                e1 = 0.0;
269 <                for (j = 0; j < 3; j++) {
270 <                        d = av->pos[j] - r->rop[j];
271 <                        e1 += d * d;
272 <                }
268 >                d = av->pos[0] - r->rop[0];
269 >                e1 = d * d;
270 >                d = av->pos[1] - r->rop[1];
271 >                e1 += d * d;
272 >                d = av->pos[2] - r->rop[2];
273 >                e1 += d * d;
274                  e1 /= av->rad * av->rad;
275                  if (e1 > ambacc*ambacc*1.21)
276                          continue;
# Line 276 | Line 294 | double s;
294                   *  Jittering final test reduces image artifacts.
295                   */
296                  wt = sqrt(e1) + sqrt(e2);
297 <                wt *= .9 + .2*urand(9015+samplendx);
280 <                if (wt > ambacc)
297 >                if (wt > ambacc*(.9+.2*urand(9015+samplendx)))
298                          continue;
299                  if (wt <= 1e-3)
300                          wt = 1e3;
# Line 424 | Line 441 | register AMBVAL  *aval;
441          copystruct(av, aval);
442          av->latick = ambclock;
443          av->next = NULL;
444 +        addcolor(avsum, av->val);       /* add to sum for averaging */
445          nambvals++;
446          return(av);
447   }
# Line 586 | Line 604 | int    always;
604          AMBTREE  oldatrunk;
605          AMBVAL  tav, *tap, *pnext;
606          register int    i, j;
607 +                                        /* see if it's time yet */
608 +        if (!always && (ambclock < lastsort+sortintvl ||
609 +                        nambvals < SORT_THRESH))
610 +                return;
611          /*
612           * The idea here is to minimize memory thrashing
613           * in VM systems by improving reference locality.
# Line 625 | Line 647 | int    always;
647                   * when we're thrashing, which is when we need to do it.
648                   */
649   #ifdef DEBUG
650 <                sprintf(errmsg, "sorting %u ambient values...", nambvals);
650 >                sprintf(errmsg, "sorting %u ambient values at ambclock=%lu...",
651 >                                nambvals, ambclock);
652                  eputs(errmsg);
653   #endif
654                  i_avlist = 0;
# Line 653 | Line 676 | int    always;
676                  }
677                  free((char *)avlist1);
678                  free((char *)avlist2);
679 <                if (sortintvl < SORT_INTVL<<6)
679 >                                                /* compute new sort interval */
680 >                sortintvl = ambclock - lastsort;
681 >                if (sortintvl >= MAX_SORT_INTVL/2)
682 >                        sortintvl = MAX_SORT_INTVL;
683 >                else
684                          sortintvl <<= 1;        /* wait twice as long next */
685   #ifdef DEBUG
686                  eputs("done\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines