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.57 by greg, Fri Nov 5 17:36:55 2004 UTC vs.
Revision 2.60 by greg, Sat May 28 22:27:54 2005 UTC

# Line 254 | 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 275 | Line 276 | ambient(               /* compute ambient component for ray */
276  
277          if (ambacc <= FTINY) {                  /* no ambient storage */
278                  rdepth++;
279 <                d = doambient(acol, r, r->rweight, NULL, NULL);
279 >                d = doambient(acol, r, aval, intens(aval)*r->rweight,
280 >                                                        NULL, NULL);
281                  rdepth--;
282                  if (d <= FTINY)
283                          goto dumbamb;
284 +                multcolor(aval, acol);
285                  return;
286          }
287  
# Line 286 | Line 289 | ambient(               /* compute ambient component for ray */
289                  sortambvals(0);
290                                                  /* get ambient value */
291          setcolor(acol, 0.0, 0.0, 0.0);
292 <        d = sumambient(acol, r, nrm, rdepth,
292 >        d = sumambient(acol, r, intens(aval)*r->rweight, nrm, rdepth,
293                          &atrunk, thescene.cuorg, thescene.cusize);
294          if (d > FTINY) {
295                  scalecolor(acol, 1.0/d);
296 +                multcolor(aval, acol);
297                  return;
298          }
299          rdepth++;                               /* need to cache new value */
300 <        d = makeambient(acol, r, nrm, rdepth-1);
300 >        d = makeambient(acol, r, aval, nrm, rdepth-1);
301          rdepth--;
302 <        if (d > FTINY)
302 >        if (d > FTINY) {
303 >                multcolor(aval, acol);          /* got new value */
304                  return;
305 +        }
306   dumbamb:                                        /* return global value */
307 <        copycolor(acol, ambval);
308 <        if ((ambvwt <= 0) | (navsum == 0))
307 >        if ((ambvwt <= 0) | (navsum == 0)) {
308 >                multcolor(aval, ambval);
309                  return;
310 +        }
311          l = bright(ambval);                     /* average in computations */
312          if (l > FTINY) {
313                  d = (log(l)*(double)ambvwt + avsum) /
314                                  (double)(ambvwt + navsum);
315                  d = exp(d) / l;
316 <                scalecolor(acol, d);            /* apply color of ambval */
316 >                scalecolor(aval, d);
317 >                multcolor(aval, ambval);        /* apply color of ambval */
318          } else {
319                  d = exp( avsum / (double)navsum );
320 <                setcolor(acol, d, d, d);        /* neutral color */
320 >                scalecolor(aval, d);            /* neutral color */
321          }
322   }
323  
# Line 318 | Line 326 | extern double
326   sumambient(     /* get interpolated ambient value */
327          COLOR  acol,
328          register RAY  *r,
329 +        double  aw,
330          FVECT  rn,
331          int  al,
332          AMBTREE  *at,
# Line 343 | 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.85*aw)
356                          continue;
357                  /*
358                   *  Ambient radius test.
# Line 422 | 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, aw, 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 */
443          COLOR  acol,
444 <        register RAY  *r,
444 >        RAY  *r,
445 >        COLOR  ac,
446          FVECT  rn,
447          int  al
448   )
449   {
450          AMBVAL  amb;
451 +        double  awt;
452          FVECT   gp, gd;
453 <                                                /* compute weight */
454 <        amb.weight = pow(AVGREFL, (double)al);
455 <        if (r->rweight < 0.1*amb.weight)        /* heuristic */
456 <                amb.weight = r->rweight;
453 >        int     i;
454 >
455 >        amb.weight = AVGREFL;                   /* compute weight */
456 >        for (i = al; i-- >= 0; )
457 >                amb.weight *= AVGREFL;
458 >        awt = intens(ac)*r->rweight;
459 >        if (awt < 0.07*amb.weight)              /* heuristic override */
460 >                amb.weight = 1.2*awt;
461                                                  /* compute ambient */
462 <        amb.rad = doambient(acol, r, amb.weight, gp, gd);
462 >        amb.rad = doambient(acol, r, ac, amb.weight, gp, gd);
463          if (amb.rad <= FTINY)
464                  return(0.0);
465                                                  /* store it */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines