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.56 by schorsch, Tue Mar 30 16:13:00 2004 UTC vs.
Revision 2.61 by greg, Tue May 31 18:01:09 2005 UTC

# Line 24 | Line 24 | static const char      RCSid[] = "$Id$";
24  
25   extern char  *shm_boundary;     /* memory sharing boundary */
26  
27 < #define  MAXASET        511     /* maximum number of elements in ambient set */
27 > #ifndef  MAXASET
28 > #define  MAXASET        2047    /* maximum number of elements in ambient set */
29 > #endif
30   OBJECT  ambset[MAXASET+1]={0};  /* ambient include/exclude set */
31  
32   double  maxarad;                /* maximum ambient radius */
# Line 252 | Line 254 | ambnotify(                     /* record new modifier */
254  
255  
256   extern void
257 < ambient(                /* compute ambient component for ray */
258 <        COLOR  acol,
257 > multambient(            /* compute ambient component & multiply by coef. */
258 >        COLOR  aval,
259          register RAY  *r,
260          FVECT  nrm
261   )
262   {
263          static int  rdepth = 0;                 /* ambient recursion */
264 +        COLOR   acol;
265          double  d, l;
266  
267          if (ambdiv <= 0)                        /* no ambient calculation */
# Line 272 | Line 275 | ambient(               /* compute ambient component for ray */
275                  goto dumbamb;
276  
277          if (ambacc <= FTINY) {                  /* no ambient storage */
278 +                copycolor(acol, aval);
279                  rdepth++;
280                  d = doambient(acol, r, r->rweight, NULL, NULL);
281                  rdepth--;
282                  if (d <= FTINY)
283                          goto dumbamb;
284 +                copycolor(aval, acol);
285                  return;
286          }
287  
288          if (tracktime)                          /* sort to minimize thrashing */
289                  sortambvals(0);
290 <                                                /* get ambient value */
290 >                                                /* interpolate ambient value */
291          setcolor(acol, 0.0, 0.0, 0.0);
292          d = sumambient(acol, r, nrm, rdepth,
293                          &atrunk, thescene.cuorg, thescene.cusize);
294          if (d > FTINY) {
295 <                scalecolor(acol, 1.0/d);
295 >                d = 1.0/d;
296 >                scalecolor(acol, d);
297 >                multcolor(aval, acol);
298                  return;
299          }
300          rdepth++;                               /* need to cache new value */
301          d = makeambient(acol, r, nrm, rdepth-1);
302          rdepth--;
303 <        if (d > FTINY)
303 >        if (d > FTINY) {
304 >                multcolor(aval, acol);          /* got new value */
305                  return;
306 +        }
307   dumbamb:                                        /* return global value */
308 <        copycolor(acol, ambval);
309 <        if ((ambvwt <= 0) | (navsum == 0))
308 >        if ((ambvwt <= 0) | (navsum == 0)) {
309 >                multcolor(aval, ambval);
310                  return;
311 +        }
312          l = bright(ambval);                     /* average in computations */
313          if (l > FTINY) {
314                  d = (log(l)*(double)ambvwt + avsum) /
315                                  (double)(ambvwt + navsum);
316                  d = exp(d) / l;
317 <                scalecolor(acol, d);            /* apply color of ambval */
317 >                scalecolor(aval, d);
318 >                multcolor(aval, ambval);        /* apply color of ambval */
319          } else {
320                  d = exp( avsum / (double)navsum );
321 <                setcolor(acol, d, d, d);        /* neutral color */
321 >                scalecolor(aval, d);            /* neutral color */
322          }
323   }
324  
# Line 341 | Line 352 | sumambient(    /* get interpolated ambient value */
352                   */
353                  if (av->lvl > al)       /* list sorted, so this works */
354                          break;
355 <                if (av->weight < r->rweight-FTINY)
355 >                if (av->weight < 0.9*r->rweight)
356                          continue;
357                  /*
358                   *  Ambient radius test.
# Line 420 | Line 431 | sumambient(    /* get interpolated ambient value */
431                                  break;
432                  }
433                  if (j == 3)
434 <                        wsum += sumambient(acol, r, rn, al, at->kid+i, ck0, s);
434 >                        wsum += sumambient(acol, r, rn, al,
435 >                                                at->kid+i, ck0, s);
436          }
437          return(wsum);
438   }
439  
440  
441   extern double
442 < makeambient(    /* make a new ambient value */
442 > makeambient(            /* make a new ambient value for storage */
443          COLOR  acol,
444 <        register RAY  *r,
444 >        RAY  *r,
445          FVECT  rn,
446          int  al
447   )
448   {
449          AMBVAL  amb;
450          FVECT   gp, gd;
451 <                                                /* compute weight */
452 <        amb.weight = pow(AVGREFL, (double)al);
453 <        if (r->rweight < 0.1*amb.weight)        /* heuristic */
451 >        int     i;
452 >
453 >        amb.weight = 1.0;                       /* compute weight */
454 >        for (i = al; i-- > 0; )
455 >                amb.weight *= AVGREFL;
456 >        if (r->rweight < 0.1*amb.weight)        /* heuristic override */
457                  amb.weight = r->rweight;
458 +        setcolor(acol, AVGREFL, AVGREFL, AVGREFL);
459                                                  /* compute ambient */
460          amb.rad = doambient(acol, r, amb.weight, gp, gd);
461 <        if (amb.rad <= FTINY)
461 >        if (amb.rad <= FTINY) {
462 >                setcolor(acol, 0.0, 0.0, 0.0);
463                  return(0.0);
464 <                                                /* store it */
464 >        }
465 >        scalecolor(acol, 1./AVGREFL);           /* undo assumed reflectance */
466 >                                                /* store value */
467          VCOPY(amb.pos, r->rop);
468          VCOPY(amb.dir, r->ron);
469          amb.lvl = al;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines