29 |
|
#include "source.h" |
30 |
|
#include "otypes.h" |
31 |
|
#include "resolu.h" |
32 |
+ |
#include "random.h" |
33 |
|
|
34 |
|
CUBE thescene; /* our scene */ |
35 |
|
OBJECT nsceneobjs; /* number of objects in our scene */ |
47 |
|
|
48 |
|
int do_irrad = 0; /* compute irradiance? */ |
49 |
|
|
50 |
+ |
int rand_samp = 1; /* pure Monte Carlo sampling? */ |
51 |
+ |
|
52 |
|
void (*trace)() = NULL; /* trace call */ |
53 |
|
|
54 |
< |
char *tralist[128]; /* list of modifers to trace (or no) */ |
54 |
> |
#ifndef MAXMODLIST |
55 |
> |
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
56 |
> |
#endif |
57 |
> |
|
58 |
> |
char *tralist[MAXMODLIST]; /* list of modifers to trace (or no) */ |
59 |
|
int traincl = -1; /* include == 1, exclude == 0 */ |
60 |
< |
#define MAXTSET 511 /* maximum number in trace set */ |
60 |
> |
#ifndef MAXTSET |
61 |
> |
#define MAXTSET 8191 /* maximum number in trace set */ |
62 |
> |
#endif |
63 |
|
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
64 |
|
|
65 |
|
int hresolu = 0; /* horizontal (scan) size */ |
83 |
|
|
84 |
|
int backvis = 1; /* back face visibility */ |
85 |
|
|
86 |
< |
int maxdepth = 8; /* maximum recursion depth */ |
86 |
> |
int maxdepth = -10; /* maximum recursion depth */ |
87 |
|
double minweight = 2e-3; /* minimum ray weight */ |
88 |
|
|
89 |
|
char *ambfile = NULL; /* ambient file name */ |
105 |
|
static putf_t puta, putd, putf; |
106 |
|
|
107 |
|
typedef void oputf_t(RAY *r); |
108 |
< |
static oputf_t oputo, oputd, oputv, oputl, oputL, oputc, oputp, |
109 |
< |
oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputdash; |
108 |
> |
static oputf_t oputo, oputd, oputv, oputV, oputl, oputL, oputc, oputp, |
109 |
> |
oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde; |
110 |
|
|
111 |
|
static void setoutput(char *vs); |
112 |
|
static void tranotify(OBJECT obj); |
157 |
|
char *fname |
158 |
|
) |
159 |
|
{ |
160 |
< |
long vcount = hresolu>1 ? hresolu*vresolu : vresolu; |
160 |
> |
unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu |
161 |
> |
: vresolu; |
162 |
|
long nextflush = hresolu; |
163 |
|
FILE *fp; |
164 |
|
double d; |
170 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
171 |
|
error(SYSTEM, errmsg); |
172 |
|
} |
163 |
– |
#ifdef _WIN32 |
173 |
|
if (inform != 'a') |
174 |
|
SET_FILE_BINARY(fp); |
166 |
– |
#endif |
175 |
|
/* set up output */ |
176 |
|
setoutput(outvals); |
177 |
|
switch (outform) { |
197 |
|
d = normalize(direc); |
198 |
|
if (d == 0.0) { /* zero ==> flush */ |
199 |
|
bogusray(); |
200 |
< |
if (--nextflush <= 0 || vcount <= 0) { |
200 |
> |
if (--nextflush <= 0 || !vcount) { |
201 |
|
fflush(stdout); |
202 |
|
nextflush = hresolu; |
203 |
|
} |
209 |
|
else |
210 |
|
rad(orig, direc, lim_dist ? d : 0.0); |
211 |
|
/* flush if time */ |
212 |
< |
if (--nextflush == 0) { |
212 |
> |
if (!--nextflush) { |
213 |
|
fflush(stdout); |
214 |
|
nextflush = hresolu; |
215 |
|
} |
216 |
|
} |
217 |
|
if (ferror(stdout)) |
218 |
|
error(SYSTEM, "write error"); |
219 |
< |
if (--vcount == 0) /* check for end */ |
219 |
> |
if (vcount && !--vcount) /* check for end */ |
220 |
|
break; |
221 |
|
} |
222 |
< |
fflush(stdout); |
223 |
< |
if (vcount > 0) |
224 |
< |
error(USER, "read error"); |
222 |
> |
if (fflush(stdout) < 0) |
223 |
> |
error(SYSTEM, "write error"); |
224 |
> |
if (vcount) |
225 |
> |
error(USER, "unexpected EOF on input"); |
226 |
|
if (fname != NULL) |
227 |
|
fclose(fp); |
228 |
|
} |
240 |
|
|
241 |
|
static void |
242 |
|
setoutput( /* set up output tables */ |
243 |
< |
register char *vs |
243 |
> |
char *vs |
244 |
|
) |
245 |
|
{ |
246 |
< |
register oputf_t **table = ray_out; |
246 |
> |
oputf_t **table = ray_out; |
247 |
|
|
248 |
|
castonly = 1; |
249 |
|
while (*vs) |
250 |
|
switch (*vs++) { |
251 |
|
case 'T': /* trace sources */ |
252 |
+ |
if (!*vs) break; |
253 |
|
trace_sources(); |
254 |
|
/* fall through */ |
255 |
|
case 't': /* trace */ |
256 |
+ |
if (!*vs) break; |
257 |
|
*table = NULL; |
258 |
|
table = every_out; |
259 |
|
trace = ourtrace; |
269 |
|
*table++ = oputv; |
270 |
|
castonly = 0; |
271 |
|
break; |
272 |
+ |
case 'V': /* contribution */ |
273 |
+ |
*table++ = oputV; |
274 |
+ |
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
275 |
+ |
error(WARNING, |
276 |
+ |
"-otV accuracy depends on -aa 0 -as 0"); |
277 |
+ |
break; |
278 |
|
case 'l': /* effective distance */ |
279 |
|
*table++ = oputl; |
280 |
|
castonly = 0; |
313 |
|
case 'M': /* material */ |
314 |
|
*table++ = oputM; |
315 |
|
break; |
316 |
< |
case '-': /* dash */ |
317 |
< |
*table++ = oputdash; |
316 |
> |
case '~': /* tilde */ |
317 |
> |
*table++ = oputtilde; |
318 |
|
break; |
319 |
|
} |
320 |
|
*table = NULL; |
363 |
|
FVECT dir |
364 |
|
) |
365 |
|
{ |
366 |
< |
register int i; |
367 |
< |
|
368 |
< |
for (i = 0; i < 3; i++) { |
369 |
< |
thisray.rorg[i] = org[i] + dir[i]; |
353 |
< |
thisray.rdir[i] = -dir[i]; |
354 |
< |
} |
366 |
> |
VSUM(thisray.rorg, org, dir, 1.1e-4); |
367 |
> |
thisray.rdir[0] = -dir[0]; |
368 |
> |
thisray.rdir[1] = -dir[1]; |
369 |
> |
thisray.rdir[2] = -dir[2]; |
370 |
|
thisray.rmax = 0.0; |
371 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
372 |
|
/* pretend we hit surface */ |
373 |
< |
thisray.rot = 1.0-1e-4; |
373 |
> |
thisray.rot = 1e-5; |
374 |
|
thisray.rod = 1.0; |
375 |
|
VCOPY(thisray.ron, dir); |
376 |
< |
for (i = 0; i < 3; i++) /* fudge factor */ |
362 |
< |
thisray.rop[i] = org[i] + 1e-4*dir[i]; |
376 |
> |
VSUM(thisray.rop, org, dir, 1e-4); |
377 |
|
/* compute and print */ |
378 |
|
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
379 |
|
printvals(&thisray); |
385 |
|
RAY *r |
386 |
|
) |
387 |
|
{ |
388 |
< |
register oputf_t **tp; |
388 |
> |
oputf_t **tp; |
389 |
|
|
390 |
|
if (ray_out[0] == NULL) |
391 |
|
return; |
398 |
|
|
399 |
|
static int |
400 |
|
getvec( /* get a vector from fp */ |
401 |
< |
register FVECT vec, |
401 |
> |
FVECT vec, |
402 |
|
int fmt, |
403 |
|
FILE *fp |
404 |
|
) |
406 |
|
static float vf[3]; |
407 |
|
static double vd[3]; |
408 |
|
char buf[32]; |
409 |
< |
register int i; |
409 |
> |
int i; |
410 |
|
|
411 |
|
switch (fmt) { |
412 |
|
case 'a': /* ascii */ |
440 |
|
) |
441 |
|
{ |
442 |
|
static int hitlimit = 0; |
443 |
< |
register OBJREC *o = objptr(obj); |
444 |
< |
register char **tralp; |
443 |
> |
OBJREC *o = objptr(obj); |
444 |
> |
char **tralp; |
445 |
|
|
446 |
|
if (obj == OVOID) { /* starting over */ |
447 |
|
traset[0] = 0; |
468 |
|
RAY *r |
469 |
|
) |
470 |
|
{ |
471 |
< |
register oputf_t **tp; |
471 |
> |
oputf_t **tp; |
472 |
|
|
473 |
|
if (every_out[0] == NULL) |
474 |
|
return; |
539 |
|
|
540 |
|
|
541 |
|
static void |
542 |
+ |
oputV( /* print value contribution */ |
543 |
+ |
RAY *r |
544 |
+ |
) |
545 |
+ |
{ |
546 |
+ |
double contr[3]; |
547 |
+ |
|
548 |
+ |
raycontrib(contr, r, PRIMARY); |
549 |
+ |
multcolor(contr, r->rcol); |
550 |
+ |
(*putreal)(contr[RED]); |
551 |
+ |
(*putreal)(contr[GRN]); |
552 |
+ |
(*putreal)(contr[BLU]); |
553 |
+ |
} |
554 |
+ |
|
555 |
+ |
|
556 |
+ |
static void |
557 |
|
oputl( /* print effective distance */ |
558 |
|
RAY *r |
559 |
|
) |
658 |
|
|
659 |
|
|
660 |
|
static void |
661 |
< |
oputW( /* print contribution */ |
661 |
> |
oputW( /* print coefficient */ |
662 |
|
RAY *r |
663 |
|
) |
664 |
|
{ |
665 |
< |
COLOR contr; |
665 |
> |
double contr[3]; |
666 |
|
|
667 |
|
raycontrib(contr, r, PRIMARY); |
668 |
< |
(*putreal)(colval(contr,RED)); |
669 |
< |
(*putreal)(colval(contr,GRN)); |
670 |
< |
(*putreal)(colval(contr,BLU)); |
668 |
> |
(*putreal)(contr[RED]); |
669 |
> |
(*putreal)(contr[GRN]); |
670 |
> |
(*putreal)(contr[BLU]); |
671 |
|
} |
672 |
|
|
673 |
|
|
706 |
|
|
707 |
|
|
708 |
|
static void |
709 |
< |
oputdash( /* output dash (spacer) */ |
709 |
> |
oputtilde( /* output tilde (spacer) */ |
710 |
|
RAY *r |
711 |
|
) |
712 |
|
{ |
713 |
< |
putchar('-'); |
685 |
< |
putchar('\t'); |
713 |
> |
fputs("~\t", stdout); |
714 |
|
} |
715 |
|
|
716 |
|
|