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.31 by greg, Tue Oct 3 11:53:30 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 > #define  OCTSCALE       1.0     /* ceil((valid rad.)/(cube size)) */
22  
23   typedef struct ambtree {
24          AMBVAL  *alist;         /* ambient value list */
# Line 48 | Line 48 | static int  nunflshed = 0;     /* number of unflushed ambi
48   #endif
49   #endif
50   #ifndef SORT_INTVL
51 < #define SORT_INTVL      (SORT_THRESH*8)
51 > #define SORT_INTVL      (SORT_THRESH*256)
52   #endif
53 + #ifndef MAX_SORT_INTVL
54 + #define MAX_SORT_INTVL  (SORT_INTVL<<4)
55 + #endif
56  
57   static unsigned long  ambclock = 0;     /* ambient access clock */
58   static unsigned int  nambvals = 0;      /* number of stored ambient values */
# Line 63 | Line 66 | static long  sortintvl = SORT_INTVL;   /* time until nex
66           * claiming our own memory (copy on write).
67           */
68   #define tracktime       (shm_boundary == NULL || ambfp == NULL)
66 #define checksort()     if (ambclock > lastsort+sortintvl && \
67                        nambvals > SORT_THRESH) sortambvals(0)
69  
70   #define  AMBFLUSH       (BUFSIZ/AMBVALSIZ)
71  
# Line 88 | Line 89 | int  ar;
89                  maxarad = thescene.cusize / 2.0;
90          } else {
91                  minarad = thescene.cusize / ar;
92 <                maxarad = 16 * minarad;                 /* heuristic */
92 >                maxarad = 64 * minarad;                 /* heuristic */
93                  if (maxarad > thescene.cusize / 2.0)
94                          maxarad = thescene.cusize / 2.0;
95          }
# Line 200 | Line 201 | register RAY  *r;
201                  return;
202          }
203                                                  /* resort memory? */
204 <        checksort();
204 >        sortambvals(0);
205                                                  /* get ambient value */
206          setcolor(acol, 0.0, 0.0, 0.0);
207          d = sumambient(acol, r, rdepth,
# Line 233 | Line 234 | double s;
234          int  i;
235          register int  j;
236          register AMBVAL  *av;
237 <                                        /* do this node */
237 >
238          wsum = 0.0;
239 +                                        /* do this node */
240          for (av = at->alist; av != NULL; av = av->next) {
241                  if (tracktime)
242                          av->latick = ambclock++;
# Line 248 | Line 250 | double s;
250                  /*
251                   *  Ambient radius test.
252                   */
253 <                e1 = 0.0;
254 <                for (j = 0; j < 3; j++) {
255 <                        d = av->pos[j] - r->rop[j];
256 <                        e1 += d * d;
257 <                }
253 >                d = av->pos[0] - r->rop[0];
254 >                e1 = d * d;
255 >                d = av->pos[1] - r->rop[1];
256 >                e1 += d * d;
257 >                d = av->pos[2] - r->rop[2];
258 >                e1 += d * d;
259                  e1 /= av->rad * av->rad;
260                  if (e1 > ambacc*ambacc*1.21)
261                          continue;
# Line 276 | Line 279 | double s;
279                   *  Jittering final test reduces image artifacts.
280                   */
281                  wt = sqrt(e1) + sqrt(e2);
282 <                wt *= .9 + .2*urand(9015+samplendx);
280 <                if (wt > ambacc)
282 >                if (wt > ambacc*(.9+.2*urand(9015+samplendx)))
283                          continue;
284                  if (wt <= 1e-3)
285                          wt = 1e3;
# Line 586 | Line 588 | int    always;
588          AMBTREE  oldatrunk;
589          AMBVAL  tav, *tap, *pnext;
590          register int    i, j;
591 +                                        /* see if it's time yet */
592 +        if (!always && (ambclock < lastsort+sortintvl ||
593 +                        nambvals < SORT_THRESH))
594 +                return;
595          /*
596           * The idea here is to minimize memory thrashing
597           * in VM systems by improving reference locality.
# Line 625 | Line 631 | int    always;
631                   * when we're thrashing, which is when we need to do it.
632                   */
633   #ifdef DEBUG
634 <                sprintf(errmsg, "sorting %u ambient values...", nambvals);
634 >                sprintf(errmsg, "sorting %u ambient values at ambclock=%lu...",
635 >                                nambvals, ambclock);
636                  eputs(errmsg);
637   #endif
638                  i_avlist = 0;
# Line 653 | Line 660 | int    always;
660                  }
661                  free((char *)avlist1);
662                  free((char *)avlist2);
663 <                if (sortintvl < SORT_INTVL<<6)
663 >                                                /* compute new sort interval */
664 >                sortintvl = ambclock - lastsort;
665 >                if (sortintvl > MAX_SORT_INTVL)
666 >                        sortintvl = MAX_SORT_INTVL;
667 >                else
668                          sortintvl <<= 1;        /* wait twice as long next */
669   #ifdef DEBUG
670                  eputs("done\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines