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.29 by greg, Tue May 2 15:28:36 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 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 586 | Line 589 | int    always;
589          AMBTREE  oldatrunk;
590          AMBVAL  tav, *tap, *pnext;
591          register int    i, j;
592 +                                        /* see if it's time yet */
593 +        if (!always && (ambclock < lastsort+sortintvl ||
594 +                        nambvals < SORT_THRESH))
595 +                return;
596          /*
597           * The idea here is to minimize memory thrashing
598           * in VM systems by improving reference locality.
# Line 625 | Line 632 | int    always;
632                   * when we're thrashing, which is when we need to do it.
633                   */
634   #ifdef DEBUG
635 <                sprintf(errmsg, "sorting %u ambient values...", nambvals);
635 >                sprintf(errmsg, "sorting %u ambient values at ambclock=%lu...",
636 >                                nambvals, ambclock);
637                  eputs(errmsg);
638   #endif
639                  i_avlist = 0;
# Line 653 | Line 661 | int    always;
661                  }
662                  free((char *)avlist1);
663                  free((char *)avlist2);
664 <                if (sortintvl < SORT_INTVL<<6)
664 >                                                /* compute new sort interval */
665 >                sortintvl = ambclock - lastsort;
666 >                if (sortintvl > MAX_SORT_INTVL)
667 >                        sortintvl = MAX_SORT_INTVL;
668 >                else
669                          sortintvl <<= 1;        /* wait twice as long next */
670   #ifdef DEBUG
671                  eputs("done\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines