--- ray/src/rt/ambient.c 2014/04/11 22:54:34 2.72 +++ ray/src/rt/ambient.c 2014/04/19 02:39:44 2.74 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ambient.c,v 2.72 2014/04/11 22:54:34 greg Exp $"; +static const char RCSid[] = "$Id: ambient.c,v 2.74 2014/04/19 02:39:44 greg Exp $"; #endif /* * ambient.c - routines dealing with ambient (inter-reflected) component. @@ -51,6 +51,8 @@ static int nunflshed = 0; /* number of unflushed ambi #define MAX_SORT_INTVL (SORT_INTVL<<6) #endif + +static double qambacc = 0.; /* ambient accuracy to the 1/4 power */ static double avsum = 0.; /* computed ambient value sum (log) */ static unsigned int navsum = 0; /* number of values in avsum */ static unsigned int nambvals = 0; /* total number of indirect values */ @@ -132,8 +134,11 @@ setambacc( /* set ambient accuracy */ if (newa < 0.0) newa = 0.0; ambdiff = fabs(newa - ambacc); - if (ambdiff >= .01 && (ambacc = newa) > FTINY && nambvals > 0) - sortambvals(1); /* rebuild tree */ + if (ambdiff >= .01 && (ambacc = newa) > FTINY) { + qambacc = sqrt(sqrt(ambacc)); + if (nambvals > 0) + sortambvals(1); /* rebuild tree */ + } } @@ -320,7 +325,7 @@ multambient( /* compute ambient component & multiply ok = makeambient(acol, r, nrm, rdepth-1); rdepth--; if (ok) { - multcolor(aval, acol); /* got new value */ + multcolor(aval, acol); /* computed new value */ return; } dumbamb: /* return global value */ @@ -454,11 +459,10 @@ makeambient( /* make a new ambient value for storage amb.weight = 1.25*r->rweight; setcolor(acol, AVGREFL, AVGREFL, AVGREFL); /* compute ambient */ - if (!doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir)) { - setcolor(acol, 0.0, 0.0, 0.0); - return(0); - } + i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir); scalecolor(acol, 1./AVGREFL); /* undo assumed reflectance */ + if (i <= 0) /* no Hessian => no storage */ + return(i); /* store value */ VCOPY(amb.pos, r->rop); amb.ndir = encodedir(r->ron); @@ -530,7 +534,7 @@ avinsert( /* insert ambient value in our tree */ at = &atrunk; VCOPY(ck0, thescene.cuorg); s = thescene.cusize; - while (s*(OCTSCALE/2) > av->rad[1]*ambacc) { + while (s*(OCTSCALE/2) > av->rad[1]*qambacc) { if (at->kid == NULL) if ((at->kid = newambtree()) == NULL) error(SYSTEM, "out of memory in avinsert");