17 |
|
|
18 |
|
#include "octree.h" |
19 |
|
|
20 |
+ |
#include "otypes.h" |
21 |
+ |
|
22 |
|
#include "random.h" |
23 |
|
|
24 |
|
#define OCTSCALE 0.5 /* ceil((valid rad.)/(cube size)) */ |
34 |
|
extern char *amblist[]; /* ambient include/exclude list */ |
35 |
|
extern int ambincl; /* include == 1, exclude == 0 */ |
36 |
|
|
37 |
< |
OBJECT ambset[128]; /* ambient include/exclude set */ |
37 |
> |
OBJECT ambset[256]={0}; /* ambient include/exclude set */ |
38 |
|
|
39 |
|
double maxarad; /* maximum ambient radius */ |
40 |
|
double minarad; /* minimum ambient radius */ |
76 |
|
char *afile; |
77 |
|
{ |
78 |
|
long ftell(); |
77 |
– |
char **amblp; |
78 |
– |
OBJECT obj; |
79 |
|
AMBVAL amb; |
80 |
< |
/* set up ambient set */ |
81 |
< |
ambset[0] = 0; |
82 |
< |
for (amblp = amblist; *amblp != NULL; amblp++) { |
83 |
< |
if ((obj = modifier(*amblp)) == OVOID) { |
84 |
< |
sprintf(errmsg, "unknown %s modifier \"%s\"", |
85 |
< |
ambincl ? "include" : "exclude", *amblp); |
86 |
< |
error(WARNING, errmsg); |
87 |
< |
continue; |
88 |
< |
} |
89 |
< |
if (!inset(ambset, obj)) |
90 |
< |
insertelem(ambset, obj); |
91 |
< |
} |
80 |
> |
|
81 |
|
maxarad = thescene.cusize / 2.0; /* maximum radius */ |
82 |
|
/* minimum radius */ |
83 |
|
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
85 |
|
/* open ambient file */ |
86 |
|
if (afile != NULL) |
87 |
|
if ((ambfp = fopen(afile, "r+")) != NULL) { |
88 |
< |
while (fread(&amb, sizeof(AMBVAL), 1, ambfp) == 1) |
88 |
> |
while (fread((char *)&amb,sizeof(AMBVAL),1,ambfp) == 1) |
89 |
|
avinsert(&amb, &atrunk, thescene.cuorg, |
90 |
|
thescene.cusize); |
91 |
|
/* align */ |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
+ |
ambnotify(obj) /* record new modifier */ |
102 |
+ |
OBJECT obj; |
103 |
+ |
{ |
104 |
+ |
register OBJREC *o = objptr(obj); |
105 |
+ |
register char **amblp; |
106 |
+ |
|
107 |
+ |
if (!ismodifier(o->otype)) |
108 |
+ |
return; |
109 |
+ |
for (amblp = amblist; *amblp != NULL; amblp++) |
110 |
+ |
if (!strcmp(o->oname, *amblp)) { |
111 |
+ |
insertelem(ambset, obj); |
112 |
+ |
return; |
113 |
+ |
} |
114 |
+ |
} |
115 |
+ |
|
116 |
+ |
|
117 |
|
ambient(acol, r) /* compute ambient component for ray */ |
118 |
|
COLOR acol; |
119 |
|
register RAY *r; |
208 |
|
* Jittering final test reduces image artifacts. |
209 |
|
*/ |
210 |
|
wt = sqrt(e1) + sqrt(e2); |
211 |
< |
if (wt > ambacc*(0.9 + 0.2*frandom())) |
211 |
> |
wt *= .9 + .2*frandom(); |
212 |
> |
if (wt > ambacc) |
213 |
|
continue; |
214 |
|
if (wt <= 1e-3) |
215 |
|
wt = 1e3; |
227 |
|
for (i = 0; i < 8; i++) { |
228 |
|
for (j = 0; j < 3; j++) { |
229 |
|
ck0[j] = c0[j]; |
230 |
< |
if (1<<j & i) { |
230 |
> |
if (1<<j & i) |
231 |
|
ck0[j] += s; |
232 |
< |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
233 |
< |
break; |
234 |
< |
} else |
235 |
< |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
230 |
< |
break; |
232 |
> |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
233 |
> |
break; |
234 |
> |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
235 |
> |
break; |
236 |
|
} |
237 |
|
if (j == 3) |
238 |
|
wsum += sumambient(acol, r, at->kid+i, ck0, s); |
272 |
|
extern int ambcmp(); |
273 |
|
extern double sin(), cos(), sqrt(); |
274 |
|
double phi, xd, yd, zd; |
275 |
+ |
double b, b2; |
276 |
|
register AMBSAMP *div; |
277 |
|
AMBSAMP dnew; |
278 |
|
RAY ar; |
327 |
|
div[ne].n = 0; |
328 |
|
div[ne].t = i; div[ne].p = j; |
329 |
|
/* sum errors */ |
330 |
< |
xd = bright(ar.rcol); |
330 |
> |
b = bright(ar.rcol); |
331 |
|
if (i > 0) { /* from above */ |
332 |
< |
yd = bright(div[ne-np].v) - xd; |
333 |
< |
yd *= yd * 0.25; |
334 |
< |
div[ne].k += yd; |
332 |
> |
b2 = bright(div[ne-np].v) - b; |
333 |
> |
b2 *= b2 * 0.25; |
334 |
> |
div[ne].k += b2; |
335 |
|
div[ne].n++; |
336 |
< |
div[ne-np].k += yd; |
336 |
> |
div[ne-np].k += b2; |
337 |
|
div[ne-np].n++; |
338 |
|
} |
339 |
|
if (j > 0) { /* from behind */ |
340 |
< |
yd = bright(div[ne-1].v) - xd; |
341 |
< |
yd *= yd * 0.25; |
342 |
< |
div[ne].k += yd; |
340 |
> |
b2 = bright(div[ne-1].v) - b; |
341 |
> |
b2 *= b2 * 0.25; |
342 |
> |
div[ne].k += b2; |
343 |
|
div[ne].n++; |
344 |
< |
div[ne-1].k += yd; |
344 |
> |
div[ne-1].k += b2; |
345 |
|
div[ne-1].n++; |
346 |
|
} |
347 |
|
if (j == np-1) { /* around */ |
348 |
< |
yd = bright(div[ne-(np-1)].v) - xd; |
349 |
< |
yd *= yd * 0.25; |
350 |
< |
div[ne].k += yd; |
348 |
> |
b2 = bright(div[ne-(np-1)].v) - b; |
349 |
> |
b2 *= b2 * 0.25; |
350 |
> |
div[ne].k += b2; |
351 |
|
div[ne].n++; |
352 |
< |
div[ne-(np-1)].k += yd; |
352 |
> |
div[ne-(np-1)].k += b2; |
353 |
|
div[ne-(np-1)].n++; |
354 |
|
} |
355 |
|
ne++; |
386 |
|
addcolor(dnew.v, ar.rcol); |
387 |
|
dnew.n = div[0].n + 1; |
388 |
|
dnew.t = div[0].t; dnew.p = div[0].p; |
389 |
< |
yd = bright(dnew.v)/dnew.n - bright(ar.rcol); |
390 |
< |
yd = yd*yd + div[0].k*(div[0].n*div[0].n); |
391 |
< |
dnew.k = yd/(dnew.n*dnew.n); |
389 |
> |
b2 = bright(dnew.v)/dnew.n - bright(ar.rcol); |
390 |
> |
b2 = b2*b2 + div[0].k*(div[0].n*div[0].n); |
391 |
> |
dnew.k = b2/(dnew.n*dnew.n); |
392 |
|
/* reinsert */ |
393 |
|
for (k = 0; k < ne-1 && dnew.k < div[k+1].k; k++) |
394 |
< |
bcopy(&div[k+1], &div[k], sizeof(AMBSAMP)); |
395 |
< |
bcopy(&dnew, &div[k], sizeof(AMBSAMP)); |
394 |
> |
copystruct(&div[k], &div[k+1]); |
395 |
> |
copystruct(&div[k], &dnew); |
396 |
|
|
397 |
|
if (ne >= i) { /* extract darkest division */ |
398 |
|
ne--; |
437 |
|
#endif |
438 |
|
if (ambfp == NULL) |
439 |
|
return; |
440 |
< |
if (fwrite(av, sizeof(AMBVAL), 1, ambfp) != 1) |
440 |
> |
if (fwrite((char *)av, sizeof(AMBVAL), 1, ambfp) != 1) |
441 |
|
goto writerr; |
442 |
|
#ifdef AMBFLUSH |
443 |
|
if (++nunflshed >= AMBFLUSH) { |
466 |
|
|
467 |
|
if ((av = newambval()) == NULL) |
468 |
|
goto memerr; |
469 |
< |
bcopy(aval, av, sizeof(AMBVAL)); |
469 |
> |
copystruct(av, aval); |
470 |
|
VCOPY(ck0, c0); |
471 |
|
while (s*(OCTSCALE/2) > av->rad*ambacc) { |
472 |
|
if (at->kid == NULL) |