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 |
– |
|
24 |
|
extern CUBE thescene; /* contains space boundaries */ |
25 |
|
|
26 |
|
extern COLOR ambval; /* global ambient component */ |
164 |
|
int i; |
165 |
|
register int j; |
166 |
|
register AMBVAL *av; |
167 |
< |
|
167 |
> |
/* do this node */ |
168 |
|
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 */ |
169 |
|
for (av = at->alist; av != NULL; av = av->next) { |
170 |
|
/* |
171 |
|
* Ray strength test. |
203 |
|
* Jittering final test reduces image artifacts. |
204 |
|
*/ |
205 |
|
wt = sqrt(e1) + sqrt(e2); |
206 |
< |
wt *= 0.9 + 0.2*frandom(); |
206 |
> |
wt *= .9 + .2*frandom(); |
207 |
|
if (wt > ambacc) |
208 |
|
continue; |
209 |
|
if (wt <= 1e-3) |
214 |
|
copycolor(ct, av->val); |
215 |
|
scalecolor(ct, wt); |
216 |
|
addcolor(acol, ct); |
217 |
+ |
} |
218 |
+ |
if (at->kid == NULL) |
219 |
+ |
return(wsum); |
220 |
+ |
/* do children */ |
221 |
+ |
s *= 0.5; |
222 |
+ |
for (i = 0; i < 8; i++) { |
223 |
+ |
for (j = 0; j < 3; j++) { |
224 |
+ |
ck0[j] = c0[j]; |
225 |
+ |
if (1<<j & i) |
226 |
+ |
ck0[j] += s; |
227 |
+ |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
228 |
+ |
break; |
229 |
+ |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
230 |
+ |
break; |
231 |
+ |
} |
232 |
+ |
if (j == 3) |
233 |
+ |
wsum += sumambient(acol, r, at->kid+i, ck0, s); |
234 |
|
} |
235 |
|
return(wsum); |
236 |
|
} |