176 |
|
} |
177 |
|
|
178 |
|
|
179 |
< |
ambient(acol, r) /* compute ambient component for ray */ |
179 |
> |
ambient(acol, r, nrm) /* compute ambient component for ray */ |
180 |
|
COLOR acol; |
181 |
|
register RAY *r; |
182 |
+ |
FVECT nrm; |
183 |
|
{ |
184 |
|
static int rdepth = 0; /* ambient recursion */ |
185 |
|
double d; |
206 |
|
sortambvals(0); |
207 |
|
/* get ambient value */ |
208 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
209 |
< |
d = sumambient(acol, r, rdepth, |
209 |
> |
d = sumambient(acol, r, nrm, rdepth, |
210 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
211 |
|
if (d > FTINY) { |
212 |
|
scalecolor(acol, 1.0/d); |
213 |
|
return; |
214 |
|
} |
215 |
|
rdepth++; /* need to cache new value */ |
216 |
< |
d = makeambient(acol, r, rdepth-1); |
216 |
> |
d = makeambient(acol, r, nrm, rdepth-1); |
217 |
|
rdepth--; |
218 |
|
if (d > FTINY) |
219 |
|
return; |
231 |
|
|
232 |
|
|
233 |
|
double |
234 |
< |
sumambient(acol, r, al, at, c0, s) /* get interpolated ambient value */ |
234 |
> |
sumambient(acol, r, rn, al, at, c0, s) /* get interpolated ambient value */ |
235 |
|
COLOR acol; |
236 |
|
register RAY *r; |
237 |
+ |
FVECT rn; |
238 |
|
int al; |
239 |
|
AMBTREE *at; |
240 |
|
FVECT c0; |
298 |
|
else |
299 |
|
wt = 1.0 / wt; |
300 |
|
wsum += wt; |
301 |
< |
extambient(ct, av, r->rop, r->ron); |
301 |
> |
extambient(ct, av, r->rop, rn); |
302 |
|
scalecolor(ct, wt); |
303 |
|
addcolor(acol, ct); |
304 |
|
} |
317 |
|
break; |
318 |
|
} |
319 |
|
if (j == 3) |
320 |
< |
wsum += sumambient(acol, r, al, at->kid+i, ck0, s); |
320 |
> |
wsum += sumambient(acol, r, rn, al, at->kid+i, ck0, s); |
321 |
|
} |
322 |
|
return(wsum); |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
|
double |
327 |
< |
makeambient(acol, r, al) /* make a new ambient value */ |
327 |
> |
makeambient(acol, r, rn, al) /* make a new ambient value */ |
328 |
|
COLOR acol; |
329 |
|
register RAY *r; |
330 |
+ |
FVECT rn; |
331 |
|
int al; |
332 |
|
{ |
333 |
|
AMBVAL amb; |
349 |
|
VCOPY(amb.gdir, gd); |
350 |
|
/* insert into tree */ |
351 |
|
avsave(&amb); /* and save to file */ |
352 |
+ |
if (rn != r->ron) |
353 |
+ |
extambient(acol, &amb, r->rop, rn); /* texture */ |
354 |
|
return(amb.rad); |
355 |
|
} |
356 |
|
|