21 |
|
|
22 |
|
#define OCTSCALE 0.5 /* ceil((valid rad.)/(cube size)) */ |
23 |
|
|
24 |
+ |
#define WDONE 4 /* stop if wsum/wmin is at or above */ |
25 |
+ |
|
26 |
|
extern CUBE thescene; /* contains space boundaries */ |
27 |
|
|
28 |
|
extern COLOR ambval; /* global ambient component */ |
166 |
|
int i; |
167 |
|
register int j; |
168 |
|
register AMBVAL *av; |
169 |
< |
/* do this node */ |
169 |
> |
|
170 |
|
wsum = 0.0; |
171 |
+ |
/* check children first */ |
172 |
+ |
if (at->kid != NULL) { |
173 |
+ |
s *= 0.5; |
174 |
+ |
for (i = 0; i < 8; i++) { |
175 |
+ |
for (j = 0; j < 3; j++) { |
176 |
+ |
ck0[j] = c0[j]; |
177 |
+ |
if (1<<j & i) |
178 |
+ |
ck0[j] += s; |
179 |
+ |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
180 |
+ |
break; |
181 |
+ |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
182 |
+ |
break; |
183 |
+ |
} |
184 |
+ |
if (j == 3) |
185 |
+ |
wsum += sumambient(acol, r, at->kid+i, ck0, s); |
186 |
+ |
} |
187 |
+ |
if (wsum*ambacc >= WDONE) |
188 |
+ |
return(wsum); /* close enough */ |
189 |
+ |
} |
190 |
+ |
/* check this node */ |
191 |
|
for (av = at->alist; av != NULL; av = av->next) { |
192 |
|
/* |
193 |
|
* Ray strength test. |
225 |
|
* Jittering final test reduces image artifacts. |
226 |
|
*/ |
227 |
|
wt = sqrt(e1) + sqrt(e2); |
228 |
< |
if (wt > ambacc*(0.9 + 0.2*frandom())) |
228 |
> |
wt *= 0.9 + 0.2*frandom(); |
229 |
> |
if (wt > ambacc) |
230 |
|
continue; |
231 |
|
if (wt <= 1e-3) |
232 |
|
wt = 1e3; |
236 |
|
copycolor(ct, av->val); |
237 |
|
scalecolor(ct, wt); |
238 |
|
addcolor(acol, ct); |
216 |
– |
} |
217 |
– |
if (at->kid == NULL) |
218 |
– |
return(wsum); |
219 |
– |
/* do children */ |
220 |
– |
s *= 0.5; |
221 |
– |
for (i = 0; i < 8; i++) { |
222 |
– |
for (j = 0; j < 3; j++) { |
223 |
– |
ck0[j] = c0[j]; |
224 |
– |
if (1<<j & i) |
225 |
– |
ck0[j] += s; |
226 |
– |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
227 |
– |
break; |
228 |
– |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
229 |
– |
break; |
230 |
– |
} |
231 |
– |
if (j == 3) |
232 |
– |
wsum += sumambient(acol, r, at->kid+i, ck0, s); |
239 |
|
} |
240 |
|
return(wsum); |
241 |
|
} |