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)) */ |
25 |
|
|
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 */ |
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(); |
79 |
– |
char **amblp; |
79 |
|
OBJECT obj; |
80 |
|
AMBVAL amb; |
81 |
< |
/* set up ambient set */ |
83 |
< |
ambset[0] = 0; |
84 |
< |
for (amblp = amblist; *amblp != NULL; amblp++) { |
85 |
< |
if ((obj = modifier(*amblp)) == OVOID) { |
86 |
< |
sprintf(errmsg, "unknown %s modifier \"%s\"", |
87 |
< |
ambincl ? "include" : "exclude", *amblp); |
88 |
< |
error(WARNING, errmsg); |
89 |
< |
continue; |
90 |
< |
} |
91 |
< |
if (!inset(ambset, obj)) |
92 |
< |
insertelem(ambset, obj); |
93 |
< |
} |
81 |
> |
|
82 |
|
maxarad = thescene.cusize / 2.0; /* maximum radius */ |
83 |
|
/* minimum radius */ |
84 |
|
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
+ |
ambnotify(obj) /* record new modifier */ |
103 |
+ |
OBJECT obj; |
104 |
+ |
{ |
105 |
+ |
register OBJREC *o = objptr(obj); |
106 |
+ |
register char **amblp; |
107 |
+ |
|
108 |
+ |
if (!ismodifier(o->otype)) |
109 |
+ |
return; |
110 |
+ |
for (amblp = amblist; *amblp != NULL; amblp++) |
111 |
+ |
if (!strcmp(o->oname, *amblp)) { |
112 |
+ |
insertelem(ambset, obj); |
113 |
+ |
return; |
114 |
+ |
} |
115 |
+ |
} |
116 |
+ |
|
117 |
+ |
|
118 |
|
ambient(acol, r) /* compute ambient component for ray */ |
119 |
|
COLOR acol; |
120 |
|
register RAY *r; |
170 |
|
int i; |
171 |
|
register int j; |
172 |
|
register AMBVAL *av; |
173 |
< |
|
173 |
> |
/* do this node */ |
174 |
|
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 */ |
175 |
|
for (av = at->alist; av != NULL; av = av->next) { |
176 |
|
/* |
177 |
|
* Ray strength test. |
209 |
|
* Jittering final test reduces image artifacts. |
210 |
|
*/ |
211 |
|
wt = sqrt(e1) + sqrt(e2); |
212 |
< |
wt *= 0.9 + 0.2*frandom(); |
212 |
> |
wt *= .9 + .2*frandom(); |
213 |
|
if (wt > ambacc) |
214 |
|
continue; |
215 |
|
if (wt <= 1e-3) |
220 |
|
copycolor(ct, av->val); |
221 |
|
scalecolor(ct, wt); |
222 |
|
addcolor(acol, ct); |
223 |
+ |
} |
224 |
+ |
if (at->kid == NULL) |
225 |
+ |
return(wsum); |
226 |
+ |
/* do children */ |
227 |
+ |
s *= 0.5; |
228 |
+ |
for (i = 0; i < 8; i++) { |
229 |
+ |
for (j = 0; j < 3; j++) { |
230 |
+ |
ck0[j] = c0[j]; |
231 |
+ |
if (1<<j & i) |
232 |
+ |
ck0[j] += s; |
233 |
+ |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
234 |
+ |
break; |
235 |
+ |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
236 |
+ |
break; |
237 |
+ |
} |
238 |
+ |
if (j == 3) |
239 |
+ |
wsum += sumambient(acol, r, at->kid+i, ck0, s); |
240 |
|
} |
241 |
|
return(wsum); |
242 |
|
} |