18 |
|
|
19 |
|
#include "random.h" |
20 |
|
|
21 |
+ |
#ifndef OCTSCALE |
22 |
|
#define OCTSCALE 1.0 /* ceil((valid rad.)/(cube size)) */ |
23 |
+ |
#endif |
24 |
+ |
#ifndef AMBVWT |
25 |
+ |
#define AMBVWT 250 /* relative ambient value weight (# calcs) */ |
26 |
+ |
#endif |
27 |
|
|
28 |
|
typedef struct ambtree { |
29 |
|
AMBVAL *alist; /* ambient value list */ |
59 |
|
#define MAX_SORT_INTVL (SORT_INTVL<<4) |
60 |
|
#endif |
61 |
|
|
62 |
+ |
static COLOR avsum = BLKCOLOR; /* computed ambient value sum */ |
63 |
+ |
static unsigned int nambvals = 0; /* number of computed ambient values */ |
64 |
|
static unsigned long ambclock = 0; /* ambient access clock */ |
58 |
– |
static unsigned int nambvals = 0; /* number of stored ambient values */ |
65 |
|
static unsigned long lastsort = 0; /* time of last value sort */ |
66 |
|
static long sortintvl = SORT_INTVL; /* time until next sort */ |
67 |
|
|
202 |
|
rdepth++; |
203 |
|
d = doambient(acol, r, r->rweight, NULL, NULL); |
204 |
|
rdepth--; |
205 |
< |
if (d == 0.0) |
205 |
> |
if (d <= FTINY) |
206 |
|
goto dumbamb; |
207 |
|
return; |
208 |
|
} |
212 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
213 |
|
d = sumambient(acol, r, rdepth, |
214 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
215 |
< |
if (d > FTINY) |
215 |
> |
if (d > FTINY) { |
216 |
|
scalecolor(acol, 1.0/d); |
217 |
< |
else { |
212 |
< |
d = makeambient(acol, r, rdepth++); |
213 |
< |
rdepth--; |
217 |
> |
return; |
218 |
|
} |
219 |
+ |
rdepth++; |
220 |
+ |
d = makeambient(acol, r, rdepth-1); |
221 |
+ |
rdepth--; |
222 |
|
if (d > FTINY) |
223 |
|
return; |
224 |
|
dumbamb: /* return global value */ |
225 |
|
copycolor(acol, ambval); |
226 |
+ |
#if AMBVWT |
227 |
+ |
if (nambvals == 0) |
228 |
+ |
return; |
229 |
+ |
scalecolor(acol, (double)AMBVWT); |
230 |
+ |
addcolor(acol, avsum); /* average in computations */ |
231 |
+ |
d = 1.0/(AMBVWT+nambvals); |
232 |
+ |
scalecolor(acol, d); |
233 |
+ |
#endif |
234 |
|
} |
235 |
|
|
236 |
|
|
294 |
|
* Jittering final test reduces image artifacts. |
295 |
|
*/ |
296 |
|
wt = sqrt(e1) + sqrt(e2); |
297 |
< |
wt *= .9 + .2*urand(9015+samplendx); |
283 |
< |
if (wt > ambacc) |
297 |
> |
if (wt > ambacc*(.9+.2*urand(9015+samplendx))) |
298 |
|
continue; |
299 |
|
if (wt <= 1e-3) |
300 |
|
wt = 1e3; |
441 |
|
copystruct(av, aval); |
442 |
|
av->latick = ambclock; |
443 |
|
av->next = NULL; |
444 |
+ |
addcolor(avsum, av->val); /* add to sum for averaging */ |
445 |
|
nambvals++; |
446 |
|
return(av); |
447 |
|
} |
678 |
|
free((char *)avlist2); |
679 |
|
/* compute new sort interval */ |
680 |
|
sortintvl = ambclock - lastsort; |
681 |
< |
if (sortintvl > MAX_SORT_INTVL) |
681 |
> |
if (sortintvl >= MAX_SORT_INTVL/2) |
682 |
|
sortintvl = MAX_SORT_INTVL; |
683 |
|
else |
684 |
|
sortintvl <<= 1; /* wait twice as long next */ |