23 |
|
* sort of context, so it is impossible to simultaneously run |
24 |
|
* this library on multiple scenes or in multiple threads. |
25 |
|
* You get one scene and one thread, and if you want more, you |
26 |
< |
* will have to go with the process model used by the programs |
27 |
< |
* gen/mkillum, hd/rholo, and px/pinterp. Finally, unrecoverable |
28 |
< |
* errors result in a call to the application-defined function |
29 |
< |
* quit(). The usual thing to do is to call exit(). |
26 |
> |
* will have to go with the process model defined in raypcalls.c. |
27 |
> |
* Finally, unrecoverable errors result in a call to the application- |
28 |
> |
* defined function quit(). The usual thing to do is to call exit(). |
29 |
|
* You might want to do something else instead, like |
30 |
|
* call setjmp()/longjmp() to bring you back to the calling |
31 |
|
* function for recovery. You may also wish to define your own |
90 |
|
*/ |
91 |
|
|
92 |
|
#include <string.h> |
93 |
+ |
#include <time.h> |
94 |
|
|
95 |
|
#include "ray.h" |
96 |
|
#include "source.h" |
115 |
|
|
116 |
|
void (*trace)() = NULL; /* trace call */ |
117 |
|
|
118 |
– |
extern void ambnotify(); |
118 |
|
void (*addobjnotify[8])() = {ambnotify, NULL}; |
119 |
|
|
120 |
|
int do_irrad = 0; /* compute irradiance? */ |
121 |
|
|
122 |
+ |
int rand_samp = 0; /* pure Monte Carlo sampling? */ |
123 |
+ |
|
124 |
|
double dstrsrc = 0.0; /* square source distribution */ |
125 |
< |
double shadthresh = .05; /* shadow threshold */ |
126 |
< |
double shadcert = .5; /* shadow certainty */ |
125 |
> |
double shadthresh = .03; /* shadow threshold */ |
126 |
> |
double shadcert = .75; /* shadow certainty */ |
127 |
|
int directrelay = 2; /* number of source relays */ |
128 |
|
int vspretest = 512; /* virtual source pretest density */ |
129 |
|
int directvis = 1; /* sources visible? */ |
139 |
|
|
140 |
|
int backvis = 1; /* back face visibility */ |
141 |
|
|
142 |
< |
int maxdepth = 6; /* maximum recursion depth */ |
143 |
< |
double minweight = 4e-3; /* minimum ray weight */ |
142 |
> |
int maxdepth = 8; /* maximum recursion depth */ |
143 |
> |
double minweight = 2e-3; /* minimum ray weight */ |
144 |
|
|
145 |
|
char *ambfile = NULL; /* ambient file name */ |
146 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
147 |
|
int ambvwt = 0; /* initial weight for ambient value */ |
148 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
149 |
< |
int ambres = 128; /* ambient resolution */ |
150 |
< |
int ambdiv = 512; /* ambient divisions */ |
151 |
< |
int ambssamp = 0; /* ambient super-samples */ |
148 |
> |
double ambacc = 0.1; /* ambient accuracy */ |
149 |
> |
int ambres = 256; /* ambient resolution */ |
150 |
> |
int ambdiv = 1024; /* ambient divisions */ |
151 |
> |
int ambssamp = 512; /* ambient super-samples */ |
152 |
|
int ambounce = 0; /* ambient bounces */ |
153 |
|
char *amblist[AMBLLEN+1]; /* ambient include/exclude list */ |
154 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
155 |
|
|
156 |
|
|
157 |
< |
void |
158 |
< |
ray_init(otnm) /* initialize ray-tracing calculation */ |
159 |
< |
char *otnm; |
157 |
> |
extern void |
158 |
> |
ray_init( /* initialize ray-tracing calculation */ |
159 |
> |
char *otnm |
160 |
> |
) |
161 |
|
{ |
162 |
|
if (nobjects > 0) /* free old scene data */ |
163 |
|
ray_done(0); |
165 |
|
if (ofun[OBJ_SPHERE].funp == o_default) |
166 |
|
initotypes(); |
167 |
|
/* initialize urand */ |
168 |
+ |
srandom(rand_samp ? (long)time(0) : 0L); |
169 |
|
initurand(2048); |
170 |
|
/* read scene octree */ |
171 |
|
readoct(octname = otnm, ~(IO_FILES|IO_INFO), &thescene, NULL); |
177 |
|
/* ready to go... */ |
178 |
|
} |
179 |
|
|
180 |
< |
void |
181 |
< |
ray_trace(r) /* trace a primary ray */ |
182 |
< |
RAY *r; |
180 |
> |
extern void |
181 |
> |
ray_trace( /* trace a primary ray */ |
182 |
> |
RAY *r |
183 |
> |
) |
184 |
|
{ |
185 |
< |
rayorigin(r, NULL, PRIMARY, 1.0); |
186 |
< |
samplendx++; |
185 |
> |
rayorigin(r, PRIMARY, NULL, NULL); |
186 |
> |
samplendx = rand_samp ? random() : samplendx+1; |
187 |
|
rayvalue(r); /* assumes origin and direction are set */ |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
< |
void |
192 |
< |
ray_done(freall) /* free ray-tracing data */ |
193 |
< |
int freall; |
191 |
> |
extern void |
192 |
> |
ray_done( /* free ray-tracing data */ |
193 |
> |
int freall |
194 |
> |
) |
195 |
|
{ |
196 |
|
retainfonts = 1; |
197 |
|
ambdone(); |
209 |
|
initurand(0); |
210 |
|
} |
211 |
|
if (nobjects > 0) { |
212 |
< |
sprintf(errmsg, "%d objects left after call to ray_done()", |
212 |
> |
sprintf(errmsg, "%ld objects left after call to ray_done()", |
213 |
|
nobjects); |
214 |
|
error(WARNING, errmsg); |
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
< |
void |
220 |
< |
ray_save(rp) /* save current parameter settings */ |
221 |
< |
RAYPARAMS *rp; |
219 |
> |
extern void |
220 |
> |
ray_save( /* save current parameter settings */ |
221 |
> |
RAYPARAMS *rp |
222 |
> |
) |
223 |
|
{ |
224 |
|
int i, ndx; |
225 |
|
|
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
< |
void |
271 |
< |
ray_restore(rp) /* restore parameter settings */ |
272 |
< |
RAYPARAMS *rp; |
270 |
> |
extern void |
271 |
> |
ray_restore( /* restore parameter settings */ |
272 |
> |
RAYPARAMS *rp |
273 |
> |
) |
274 |
|
{ |
275 |
|
register int i; |
276 |
|
|
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
< |
void |
339 |
< |
ray_defaults(rp) /* get default parameter values */ |
340 |
< |
RAYPARAMS *rp; |
338 |
> |
extern void |
339 |
> |
ray_defaults( /* get default parameter values */ |
340 |
> |
RAYPARAMS *rp |
341 |
> |
) |
342 |
|
{ |
343 |
|
int i; |
344 |
|
|
347 |
|
|
348 |
|
rp->do_irrad = 0; |
349 |
|
rp->dstrsrc = 0.0; |
350 |
< |
rp->shadthresh = .05; |
351 |
< |
rp->shadcert = .5; |
350 |
> |
rp->shadthresh = .03; |
351 |
> |
rp->shadcert = .75; |
352 |
|
rp->directrelay = 2; |
353 |
|
rp->vspretest = 512; |
354 |
|
rp->directvis = 1; |
360 |
|
rp->specthresh = .15; |
361 |
|
rp->specjitter = 1.; |
362 |
|
rp->backvis = 1; |
363 |
< |
rp->maxdepth = 6; |
364 |
< |
rp->minweight = 4e-3; |
363 |
> |
rp->maxdepth = 8; |
364 |
> |
rp->minweight = 2e-3; |
365 |
|
setcolor(rp->ambval, 0., 0., 0.); |
366 |
|
memset(rp->ambfile, '\0', sizeof(rp->ambfile)); |
367 |
|
rp->ambvwt = 0; |
368 |
< |
rp->ambres = 128; |
369 |
< |
rp->ambacc = 0.2; |
370 |
< |
rp->ambdiv = 512; |
371 |
< |
rp->ambssamp = 0; |
368 |
> |
rp->ambres = 256; |
369 |
> |
rp->ambacc = 0.15; |
370 |
> |
rp->ambdiv = 1024; |
371 |
> |
rp->ambssamp = 512; |
372 |
|
rp->ambounce = 0; |
373 |
|
rp->ambincl = -1; |
374 |
|
memset(rp->amblval, '\0', sizeof(rp->amblval)); |