--- ray/src/rt/ambient.c 1995/05/02 15:28:36 2.29 +++ ray/src/rt/ambient.c 1995/10/17 18:22:47 2.32 @@ -18,7 +18,12 @@ static char SCCSid[] = "$SunId$ LBL"; #include "random.h" +#ifndef OCTSCALE #define OCTSCALE 1.0 /* ceil((valid rad.)/(cube size)) */ +#endif +#ifndef AMBVWT +#define AMBVWT 250 /* relative ambient value weight (# calcs) */ +#endif typedef struct ambtree { AMBVAL *alist; /* ambient value list */ @@ -54,8 +59,9 @@ static int nunflshed = 0; /* number of unflushed ambi #define MAX_SORT_INTVL (SORT_INTVL<<4) #endif +static COLOR avsum = BLKCOLOR; /* computed ambient value sum */ +static unsigned int nambvals = 0; /* number of computed ambient values */ static unsigned long ambclock = 0; /* ambient access clock */ -static unsigned int nambvals = 0; /* number of stored ambient values */ static unsigned long lastsort = 0; /* time of last value sort */ static long sortintvl = SORT_INTVL; /* time until next sort */ @@ -89,7 +95,7 @@ int ar; maxarad = thescene.cusize / 2.0; } else { minarad = thescene.cusize / ar; - maxarad = 16 * minarad; /* heuristic */ + maxarad = 64 * minarad; /* heuristic */ if (maxarad > thescene.cusize / 2.0) maxarad = thescene.cusize / 2.0; } @@ -196,7 +202,7 @@ register RAY *r; rdepth++; d = doambient(acol, r, r->rweight, NULL, NULL); rdepth--; - if (d == 0.0) + if (d <= FTINY) goto dumbamb; return; } @@ -206,16 +212,25 @@ register RAY *r; setcolor(acol, 0.0, 0.0, 0.0); d = sumambient(acol, r, rdepth, &atrunk, thescene.cuorg, thescene.cusize); - if (d > FTINY) + if (d > FTINY) { scalecolor(acol, 1.0/d); - else { - d = makeambient(acol, r, rdepth++); - rdepth--; + return; } + rdepth++; + d = makeambient(acol, r, rdepth-1); + rdepth--; if (d > FTINY) return; dumbamb: /* return global value */ copycolor(acol, ambval); +#if AMBVWT + if (nambvals == 0) + return; + scalecolor(acol, (double)AMBVWT); + addcolor(acol, avsum); /* average in computations */ + d = 1.0/(AMBVWT+nambvals); + scalecolor(acol, d); +#endif } @@ -279,8 +294,7 @@ double s; * Jittering final test reduces image artifacts. */ wt = sqrt(e1) + sqrt(e2); - wt *= .9 + .2*urand(9015+samplendx); - if (wt > ambacc) + if (wt > ambacc*(.9+.2*urand(9015+samplendx))) continue; if (wt <= 1e-3) wt = 1e3; @@ -427,6 +441,7 @@ register AMBVAL *aval; copystruct(av, aval); av->latick = ambclock; av->next = NULL; + addcolor(avsum, av->val); /* add to sum for averaging */ nambvals++; return(av); } @@ -663,7 +678,7 @@ int always; free((char *)avlist2); /* compute new sort interval */ sortintvl = ambclock - lastsort; - if (sortintvl > MAX_SORT_INTVL) + if (sortintvl >= MAX_SORT_INTVL/2) sortintvl = MAX_SORT_INTVL; else sortintvl <<= 1; /* wait twice as long next */