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.33 by greg, Tue Oct 24 13:33:23 1995 UTC vs.
Revision 2.35 by greg, Tue Nov 21 14:28:22 1995 UTC

# Line 60 | Line 60 | static int  nunflshed = 0;     /* number of unflushed ambi
60   #endif
61  
62   static COLOR  avsum = BLKCOLOR;         /* computed ambient value sum */
63 < static unsigned int  nambvals = 0;      /* number of computed ambient values */
63 > static unsigned int  nambvals = 0;      /* total number of indirect values */
64 > static unsigned int  nambshare = 0;     /* number of values from file */
65   static unsigned long  ambclock = 0;     /* ambient access clock */
66   static unsigned long  lastsort = 0;     /* time of last value sort */
67   static long  sortintvl = SORT_INTVL;    /* time until next sort */
# Line 69 | Line 70 | static long  sortintvl = SORT_INTVL;   /* time until nex
70          /*
71           * Track access times unless we are sharing ambient values
72           * through memory on a multiprocessor, when we want to avoid
73 <         * claiming our own memory (copy on write).
73 >         * claiming our own memory (copy on write).  Go ahead anyway
74 >         * if more than two thirds of our values are unshared.
75           */
76 < #define tracktime       (shm_boundary == NULL || ambfp == NULL)
76 > #define tracktime       (shm_boundary == NULL || nambvals > 3*nambshare)
77  
78   #define  AMBFLUSH       (BUFSIZ/AMBVALSIZ)
79  
# Line 143 | Line 145 | char  *afile;
145                          avinsert(avstore(&amb));
146                                                  /* align */
147                  fseek(ambfp, -((ftell(ambfp)-headlen)%AMBVALSIZ), 1);
148 +                nambshare = nambvals;
149          } else if ((ambfp = fopen(afile, "w+")) != NULL)
150                  initambfile(1);
151          else {
# Line 176 | Line 179 | OBJECT obj;
179   }
180  
181  
182 < ambient(acol, r)                /* compute ambient component for ray */
182 > ambient(acol, r, nrm)           /* compute ambient component for ray */
183   COLOR  acol;
184   register RAY  *r;
185 + FVECT  nrm;
186   {
187          static int  rdepth = 0;                 /* ambient recursion */
188          double  d;
# Line 205 | Line 209 | register RAY  *r;
209          sortambvals(0);
210                                                  /* get ambient value */
211          setcolor(acol, 0.0, 0.0, 0.0);
212 <        d = sumambient(acol, r, rdepth,
212 >        d = sumambient(acol, r, nrm, rdepth,
213                          &atrunk, thescene.cuorg, thescene.cusize);
214          if (d > FTINY) {
215                  scalecolor(acol, 1.0/d);
216                  return;
217          }
218          rdepth++;                               /* need to cache new value */
219 <        d = makeambient(acol, r, rdepth-1);
219 >        d = makeambient(acol, r, nrm, rdepth-1);
220          rdepth--;
221          if (d > FTINY)
222                  return;
# Line 230 | Line 234 | dumbamb:                                       /* return global value */
234  
235  
236   double
237 < sumambient(acol, r, al, at, c0, s)      /* get interpolated ambient value */
237 > sumambient(acol, r, rn, al, at, c0, s)  /* get interpolated ambient value */
238   COLOR  acol;
239   register RAY  *r;
240 + FVECT  rn;
241   int  al;
242   AMBTREE  *at;
243   FVECT  c0;
# Line 296 | Line 301 | double s;
301                  else
302                          wt = 1.0 / wt;
303                  wsum += wt;
304 <                extambient(ct, av, r->rop, r->ron);
304 >                extambient(ct, av, r->rop, rn);
305                  scalecolor(ct, wt);
306                  addcolor(acol, ct);
307          }
# Line 315 | Line 320 | double s;
320                                  break;
321                  }
322                  if (j == 3)
323 <                        wsum += sumambient(acol, r, al, at->kid+i, ck0, s);
323 >                        wsum += sumambient(acol, r, rn, al, at->kid+i, ck0, s);
324          }
325          return(wsum);
326   }
327  
328  
329   double
330 < makeambient(acol, r, al)        /* make a new ambient value */
330 > makeambient(acol, r, rn, al)    /* make a new ambient value */
331   COLOR  acol;
332   register RAY  *r;
333 + FVECT  rn;
334   int  al;
335   {
336          AMBVAL  amb;
# Line 346 | Line 352 | int  al;
352          VCOPY(amb.gdir, gd);
353                                                  /* insert into tree */
354          avsave(&amb);                           /* and save to file */
355 +        if (rn != r->ron)
356 +                extambient(acol, &amb, r->rop, rn);     /* texture */
357          return(amb.rad);
358   }
359  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines