121 |
|
|
122 |
|
int do_irrad = 0; /* compute irradiance? */ |
123 |
|
|
124 |
< |
int rand_samp = 0; /* pure Monte Carlo sampling? */ |
124 |
> |
int rand_samp = 1; /* pure Monte Carlo sampling? */ |
125 |
|
|
126 |
|
double dstrsrc = 0.0; /* square source distribution */ |
127 |
|
double shadthresh = .03; /* shadow threshold */ |
141 |
|
|
142 |
|
int backvis = 1; /* back face visibility */ |
143 |
|
|
144 |
< |
int maxdepth = 8; /* maximum recursion depth */ |
145 |
< |
double minweight = 5e-4; /* minimum ray weight */ |
144 |
> |
int maxdepth = -10; /* maximum recursion depth */ |
145 |
> |
double minweight = 2e-3; /* minimum ray weight */ |
146 |
|
|
147 |
|
char *ambfile = NULL; /* ambient file name */ |
148 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
156 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
157 |
|
|
158 |
|
|
159 |
+ |
static void |
160 |
+ |
reset_random(void) /* re-initialize random number generator */ |
161 |
+ |
{ |
162 |
+ |
if (rand_samp) { |
163 |
+ |
srandom((long)time(0)); |
164 |
+ |
initurand(0); |
165 |
+ |
} else { |
166 |
+ |
srandom(0L); |
167 |
+ |
initurand(2048); |
168 |
+ |
} |
169 |
+ |
} |
170 |
+ |
|
171 |
+ |
|
172 |
|
void |
173 |
|
ray_init( /* initialize ray-tracing calculation */ |
174 |
|
char *otnm |
180 |
|
if (ofun[OBJ_SPHERE].funp == o_default) |
181 |
|
initotypes(); |
182 |
|
/* initialize urand */ |
183 |
< |
if (rand_samp) { |
171 |
< |
srandom((long)time(0)); |
172 |
< |
initurand(0); |
173 |
< |
} else { |
174 |
< |
srandom(0L); |
175 |
< |
initurand(2048); |
176 |
< |
} |
183 |
> |
reset_random(); |
184 |
|
/* read scene octree */ |
185 |
|
readoct(octname = otnm, ~(IO_FILES|IO_INFO), &thescene, NULL); |
186 |
|
nsceneobjs = nobjects; |
193 |
|
/* ready to go... (almost) */ |
194 |
|
} |
195 |
|
|
196 |
+ |
|
197 |
|
void |
198 |
|
ray_trace( /* trace a primary ray */ |
199 |
|
RAY *r |
246 |
|
if (rp == NULL) |
247 |
|
return; |
248 |
|
rp->do_irrad = do_irrad; |
249 |
+ |
rp->rand_samp = rand_samp; |
250 |
|
rp->dstrsrc = dstrsrc; |
251 |
|
rp->shadthresh = shadthresh; |
252 |
|
rp->shadcert = shadcert; |
263 |
|
rp->backvis = backvis; |
264 |
|
rp->maxdepth = maxdepth; |
265 |
|
rp->minweight = minweight; |
257 |
– |
copycolor(rp->ambval, ambval); |
258 |
– |
memset(rp->ambfile, '\0', sizeof(rp->ambfile)); |
266 |
|
if (ambfile != NULL) |
267 |
|
strncpy(rp->ambfile, ambfile, sizeof(rp->ambfile)-1); |
268 |
+ |
else |
269 |
+ |
memset(rp->ambfile, '\0', sizeof(rp->ambfile)); |
270 |
+ |
copycolor(rp->ambval, ambval); |
271 |
|
rp->ambvwt = ambvwt; |
272 |
|
rp->ambacc = ambacc; |
273 |
|
rp->ambres = ambres; |
298 |
|
RAYPARAMS *rp |
299 |
|
) |
300 |
|
{ |
301 |
< |
register int i; |
301 |
> |
int i; |
302 |
|
|
303 |
|
if (rp == NULL) { /* restore defaults */ |
304 |
|
RAYPARAMS dflt; |
308 |
|
} |
309 |
|
/* restore saved settings */ |
310 |
|
do_irrad = rp->do_irrad; |
311 |
+ |
if (!rand_samp != !rp->rand_samp) { |
312 |
+ |
rand_samp = rp->rand_samp; |
313 |
+ |
reset_random(); |
314 |
+ |
} |
315 |
|
dstrsrc = rp->dstrsrc; |
316 |
|
shadthresh = rp->shadthresh; |
317 |
|
shadcert = rp->shadcert; |
333 |
|
ambdiv = rp->ambdiv; |
334 |
|
ambssamp = rp->ambssamp; |
335 |
|
ambounce = rp->ambounce; |
336 |
+ |
/* a bit dangerous if not static */ |
337 |
|
for (i = 0; rp->amblndx[i] >= 0; i++) |
338 |
|
amblist[i] = rp->amblval + rp->amblndx[i]; |
339 |
|
while (i <= AMBLLEN) |
380 |
|
return; |
381 |
|
|
382 |
|
rp->do_irrad = 0; |
383 |
+ |
rp->rand_samp = 1; |
384 |
|
rp->dstrsrc = 0.0; |
385 |
|
rp->shadthresh = .03; |
386 |
|
rp->shadcert = .75; |
395 |
|
rp->specthresh = .15; |
396 |
|
rp->specjitter = 1.; |
397 |
|
rp->backvis = 1; |
398 |
< |
rp->maxdepth = 8; |
398 |
> |
rp->maxdepth = -10; |
399 |
|
rp->minweight = 2e-3; |
384 |
– |
setcolor(rp->ambval, 0., 0., 0.); |
400 |
|
memset(rp->ambfile, '\0', sizeof(rp->ambfile)); |
401 |
+ |
setcolor(rp->ambval, 0., 0., 0.); |
402 |
|
rp->ambvwt = 0; |
403 |
|
rp->ambres = 256; |
404 |
|
rp->ambacc = 0.15; |