21 |
|
* irradiance values are desired. |
22 |
|
*/ |
23 |
|
|
24 |
< |
#include "ray.h" |
24 |
> |
#include <time.h> |
25 |
|
|
26 |
+ |
#include "platform.h" |
27 |
+ |
#include "ray.h" |
28 |
+ |
#include "ambient.h" |
29 |
+ |
#include "source.h" |
30 |
|
#include "otypes.h" |
27 |
– |
|
31 |
|
#include "resolu.h" |
32 |
|
|
33 |
|
CUBE thescene; /* our scene */ |
48 |
|
|
49 |
|
void (*trace)() = NULL; /* trace call */ |
50 |
|
|
48 |
– |
extern void ambnotify(), tranotify(); |
49 |
– |
void (*addobjnotify[])() = {ambnotify, tranotify, NULL}; |
51 |
|
char *tralist[128]; /* list of modifers to trace (or no) */ |
52 |
|
int traincl = -1; /* include == 1, exclude == 0 */ |
53 |
< |
#define MAXTSET 511 /* maximum number in trace set */ |
53 |
> |
#ifndef MAXTSET |
54 |
> |
#define MAXTSET 1024 /* maximum number in trace set */ |
55 |
> |
#endif |
56 |
|
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
57 |
|
|
58 |
|
int hresolu = 0; /* horizontal (scan) size */ |
59 |
|
int vresolu = 0; /* vertical resolution */ |
60 |
|
|
61 |
|
double dstrsrc = 0.0; /* square source distribution */ |
62 |
< |
double shadthresh = .05; /* shadow threshold */ |
63 |
< |
double shadcert = .5; /* shadow certainty */ |
62 |
> |
double shadthresh = .03; /* shadow threshold */ |
63 |
> |
double shadcert = .75; /* shadow certainty */ |
64 |
|
int directrelay = 2; /* number of source relays */ |
65 |
|
int vspretest = 512; /* virtual source pretest density */ |
66 |
|
int directvis = 1; /* sources visible? */ |
76 |
|
|
77 |
|
int backvis = 1; /* back face visibility */ |
78 |
|
|
79 |
< |
int maxdepth = 6; /* maximum recursion depth */ |
80 |
< |
double minweight = 4e-3; /* minimum ray weight */ |
79 |
> |
int maxdepth = -10; /* maximum recursion depth */ |
80 |
> |
double minweight = 2e-3; /* minimum ray weight */ |
81 |
|
|
82 |
|
char *ambfile = NULL; /* ambient file name */ |
83 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
84 |
|
int ambvwt = 0; /* initial weight for ambient value */ |
85 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
86 |
< |
int ambres = 128; /* ambient resolution */ |
87 |
< |
int ambdiv = 512; /* ambient divisions */ |
88 |
< |
int ambssamp = 0; /* ambient super-samples */ |
85 |
> |
double ambacc = 0.15; /* ambient accuracy */ |
86 |
> |
int ambres = 256; /* ambient resolution */ |
87 |
> |
int ambdiv = 1024; /* ambient divisions */ |
88 |
> |
int ambssamp = 512; /* ambient super-samples */ |
89 |
|
int ambounce = 0; /* ambient bounces */ |
90 |
< |
char *amblist[128]; /* ambient include/exclude list */ |
90 |
> |
char *amblist[AMBLLEN]; /* ambient include/exclude list */ |
91 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
92 |
|
|
93 |
+ |
static int castonly = 0; |
94 |
|
|
95 |
|
static RAY thisray; /* for our convenience */ |
96 |
|
|
97 |
< |
static void oputo(), oputd(), oputv(), oputl(), oputL(), oputc(), |
98 |
< |
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
97 |
> |
typedef void putf_t(double v); |
98 |
> |
static putf_t puta, putd, putf; |
99 |
|
|
100 |
< |
static void ourtrace(), tabin(); |
101 |
< |
static void (*ray_out[16])(), (*every_out[16])(); |
102 |
< |
static int castonly = 0; |
100 |
> |
typedef void oputf_t(RAY *r); |
101 |
> |
static oputf_t oputo, oputd, oputv, oputl, oputL, oputc, oputp, |
102 |
> |
oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde; |
103 |
|
|
104 |
< |
static void puta(), putf(), putd(); |
104 |
> |
static void setoutput(char *vs); |
105 |
> |
static void tranotify(OBJECT obj); |
106 |
> |
static void bogusray(void); |
107 |
> |
static void rad(FVECT org, FVECT dir, double dmax); |
108 |
> |
static void irrad(FVECT org, FVECT dir); |
109 |
> |
static void printvals(RAY *r); |
110 |
> |
static int getvec(FVECT vec, int fmt, FILE *fp); |
111 |
> |
static void tabin(RAY *r); |
112 |
> |
static void ourtrace(RAY *r); |
113 |
|
|
114 |
< |
static void (*putreal)(); |
114 |
> |
static oputf_t *ray_out[16], *every_out[16]; |
115 |
> |
static putf_t *putreal; |
116 |
|
|
117 |
< |
void bogusray(), rad(), irrad(), printvals(); |
117 |
> |
void (*addobjnotify[])() = {ambnotify, tranotify, NULL}; |
118 |
|
|
119 |
|
|
120 |
|
void |
121 |
< |
quit(code) /* quit program */ |
122 |
< |
int code; |
121 |
> |
quit( /* quit program */ |
122 |
> |
int code |
123 |
> |
) |
124 |
|
{ |
125 |
< |
#ifndef NIX |
125 |
> |
#ifndef NON_POSIX /* XXX we don't clean up elsewhere? */ |
126 |
|
headclean(); /* delete header file */ |
127 |
|
pfclean(); /* clean up persist files */ |
128 |
|
#endif |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
< |
char * |
134 |
< |
formstr(f) /* return format identifier */ |
135 |
< |
int f; |
133 |
> |
extern char * |
134 |
> |
formstr( /* return format identifier */ |
135 |
> |
int f |
136 |
> |
) |
137 |
|
{ |
138 |
|
switch (f) { |
139 |
|
case 'a': return("ascii"); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
< |
void |
149 |
< |
rtrace(fname) /* trace rays from file */ |
150 |
< |
char *fname; |
148 |
> |
extern void |
149 |
> |
rtrace( /* trace rays from file */ |
150 |
> |
char *fname |
151 |
> |
) |
152 |
|
{ |
153 |
< |
long vcount = hresolu>1 ? hresolu*vresolu : vresolu; |
153 |
> |
unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu |
154 |
> |
: vresolu; |
155 |
|
long nextflush = hresolu; |
156 |
|
FILE *fp; |
157 |
|
double d; |
163 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
164 |
|
error(SYSTEM, errmsg); |
165 |
|
} |
149 |
– |
#ifdef MSDOS |
166 |
|
if (inform != 'a') |
167 |
< |
setmode(fileno(fp), O_BINARY); |
152 |
< |
#endif |
167 |
> |
SET_FILE_BINARY(fp); |
168 |
|
/* set up output */ |
169 |
|
setoutput(outvals); |
170 |
|
switch (outform) { |
190 |
|
d = normalize(direc); |
191 |
|
if (d == 0.0) { /* zero ==> flush */ |
192 |
|
bogusray(); |
193 |
< |
if (--nextflush <= 0 || vcount <= 0) { |
193 |
> |
if (--nextflush <= 0 || !vcount) { |
194 |
|
fflush(stdout); |
195 |
|
nextflush = hresolu; |
196 |
|
} |
202 |
|
else |
203 |
|
rad(orig, direc, lim_dist ? d : 0.0); |
204 |
|
/* flush if time */ |
205 |
< |
if (--nextflush == 0) { |
205 |
> |
if (!--nextflush) { |
206 |
|
fflush(stdout); |
207 |
|
nextflush = hresolu; |
208 |
|
} |
209 |
|
} |
210 |
|
if (ferror(stdout)) |
211 |
|
error(SYSTEM, "write error"); |
212 |
< |
if (--vcount == 0) /* check for end */ |
212 |
> |
if (vcount && !--vcount) /* check for end */ |
213 |
|
break; |
214 |
|
} |
215 |
|
fflush(stdout); |
216 |
< |
if (vcount > 0) |
217 |
< |
error(USER, "read error"); |
216 |
> |
if (vcount) |
217 |
> |
error(USER, "unexpected EOF on input"); |
218 |
|
if (fname != NULL) |
219 |
|
fclose(fp); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
< |
setoutput(vs) /* set up output tables */ |
224 |
< |
register char *vs; |
223 |
> |
static void |
224 |
> |
trace_sources(void) /* trace rays to light sources, also */ |
225 |
|
{ |
226 |
< |
extern void (*trace)(); |
227 |
< |
register void (**table)() = ray_out; |
226 |
> |
int sn; |
227 |
> |
|
228 |
> |
for (sn = 0; sn < nsources; sn++) |
229 |
> |
source[sn].sflags |= SFOLLOW; |
230 |
> |
} |
231 |
|
|
232 |
+ |
|
233 |
+ |
static void |
234 |
+ |
setoutput( /* set up output tables */ |
235 |
+ |
register char *vs |
236 |
+ |
) |
237 |
+ |
{ |
238 |
+ |
register oputf_t **table = ray_out; |
239 |
+ |
|
240 |
|
castonly = 1; |
241 |
|
while (*vs) |
242 |
|
switch (*vs++) { |
243 |
+ |
case 'T': /* trace sources */ |
244 |
+ |
if (!*vs) break; |
245 |
+ |
trace_sources(); |
246 |
+ |
/* fall through */ |
247 |
|
case 't': /* trace */ |
248 |
+ |
if (!*vs) break; |
249 |
|
*table = NULL; |
250 |
|
table = every_out; |
251 |
|
trace = ourtrace; |
287 |
|
case 'w': /* weight */ |
288 |
|
*table++ = oputw; |
289 |
|
break; |
290 |
+ |
case 'W': /* coefficient */ |
291 |
+ |
*table++ = oputW; |
292 |
+ |
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
293 |
+ |
error(WARNING, |
294 |
+ |
"-otW accuracy depends on -aa 0 -as 0"); |
295 |
+ |
break; |
296 |
|
case 'm': /* modifier */ |
297 |
|
*table++ = oputm; |
298 |
|
break; |
299 |
+ |
case 'M': /* material */ |
300 |
+ |
*table++ = oputM; |
301 |
+ |
break; |
302 |
+ |
case '~': /* tilde */ |
303 |
+ |
*table++ = oputtilde; |
304 |
+ |
break; |
305 |
|
} |
306 |
|
*table = NULL; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
< |
void |
311 |
< |
bogusray() /* print out empty record */ |
310 |
> |
static void |
311 |
> |
bogusray(void) /* print out empty record */ |
312 |
|
{ |
313 |
|
thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] = |
314 |
|
thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0; |
315 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
315 |
> |
thisray.rmax = 0.0; |
316 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
317 |
|
printvals(&thisray); |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
< |
void |
322 |
< |
rad(org, dir, dmax) /* compute and print ray value(s) */ |
323 |
< |
FVECT org, dir; |
324 |
< |
double dmax; |
321 |
> |
static void |
322 |
> |
rad( /* compute and print ray value(s) */ |
323 |
> |
FVECT org, |
324 |
> |
FVECT dir, |
325 |
> |
double dmax |
326 |
> |
) |
327 |
|
{ |
328 |
|
VCOPY(thisray.rorg, org); |
329 |
|
VCOPY(thisray.rdir, dir); |
330 |
|
thisray.rmax = dmax; |
331 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
331 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
332 |
|
if (castonly) { |
333 |
< |
if (!localhit(&thisray, &thescene)) |
333 |
> |
if (!localhit(&thisray, &thescene)) { |
334 |
|
if (thisray.ro == &Aftplane) { /* clipped */ |
335 |
|
thisray.ro = NULL; |
336 |
|
thisray.rot = FHUGE; |
337 |
|
} else |
338 |
|
sourcehit(&thisray); |
339 |
+ |
} |
340 |
|
} else |
341 |
|
rayvalue(&thisray); |
342 |
|
printvals(&thisray); |
343 |
|
} |
344 |
|
|
345 |
|
|
346 |
< |
void |
347 |
< |
irrad(org, dir) /* compute immediate irradiance value */ |
348 |
< |
FVECT org, dir; |
346 |
> |
static void |
347 |
> |
irrad( /* compute immediate irradiance value */ |
348 |
> |
FVECT org, |
349 |
> |
FVECT dir |
350 |
> |
) |
351 |
|
{ |
352 |
|
register int i; |
353 |
|
|
355 |
|
thisray.rorg[i] = org[i] + dir[i]; |
356 |
|
thisray.rdir[i] = -dir[i]; |
357 |
|
} |
358 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
358 |
> |
thisray.rmax = 0.0; |
359 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
360 |
|
/* pretend we hit surface */ |
361 |
|
thisray.rot = 1.0-1e-4; |
362 |
|
thisray.rod = 1.0; |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
< |
void |
373 |
< |
printvals(r) /* print requested ray values */ |
374 |
< |
RAY *r; |
372 |
> |
static void |
373 |
> |
printvals( /* print requested ray values */ |
374 |
> |
RAY *r |
375 |
> |
) |
376 |
|
{ |
377 |
< |
register void (**tp)(); |
377 |
> |
register oputf_t **tp; |
378 |
|
|
379 |
|
if (ray_out[0] == NULL) |
380 |
|
return; |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
< |
int |
389 |
< |
getvec(vec, fmt, fp) /* get a vector from fp */ |
390 |
< |
register FVECT vec; |
391 |
< |
int fmt; |
392 |
< |
FILE *fp; |
388 |
> |
static int |
389 |
> |
getvec( /* get a vector from fp */ |
390 |
> |
register FVECT vec, |
391 |
> |
int fmt, |
392 |
> |
FILE *fp |
393 |
> |
) |
394 |
|
{ |
395 |
|
static float vf[3]; |
396 |
|
static double vd[3]; |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
< |
void |
427 |
< |
tranotify(obj) /* record new modifier */ |
428 |
< |
OBJECT obj; |
426 |
> |
static void |
427 |
> |
tranotify( /* record new modifier */ |
428 |
> |
OBJECT obj |
429 |
> |
) |
430 |
|
{ |
431 |
|
static int hitlimit = 0; |
432 |
|
register OBJREC *o = objptr(obj); |
453 |
|
|
454 |
|
|
455 |
|
static void |
456 |
< |
ourtrace(r) /* print ray values */ |
457 |
< |
RAY *r; |
456 |
> |
ourtrace( /* print ray values */ |
457 |
> |
RAY *r |
458 |
> |
) |
459 |
|
{ |
460 |
< |
register void (**tp)(); |
460 |
> |
register oputf_t **tp; |
461 |
|
|
462 |
|
if (every_out[0] == NULL) |
463 |
|
return; |
469 |
|
tabin(r); |
470 |
|
for (tp = every_out; *tp != NULL; tp++) |
471 |
|
(**tp)(r); |
472 |
< |
putchar('\n'); |
472 |
> |
if (outform == 'a') |
473 |
> |
putchar('\n'); |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
|
static void |
478 |
< |
tabin(r) /* tab in appropriate amount */ |
479 |
< |
RAY *r; |
478 |
> |
tabin( /* tab in appropriate amount */ |
479 |
> |
RAY *r |
480 |
> |
) |
481 |
|
{ |
482 |
< |
register RAY *rp; |
482 |
> |
const RAY *rp; |
483 |
|
|
484 |
|
for (rp = r->parent; rp != NULL; rp = rp->parent) |
485 |
|
putchar('\t'); |
487 |
|
|
488 |
|
|
489 |
|
static void |
490 |
< |
oputo(r) /* print origin */ |
491 |
< |
RAY *r; |
490 |
> |
oputo( /* print origin */ |
491 |
> |
RAY *r |
492 |
> |
) |
493 |
|
{ |
494 |
|
(*putreal)(r->rorg[0]); |
495 |
|
(*putreal)(r->rorg[1]); |
498 |
|
|
499 |
|
|
500 |
|
static void |
501 |
< |
oputd(r) /* print direction */ |
502 |
< |
RAY *r; |
501 |
> |
oputd( /* print direction */ |
502 |
> |
RAY *r |
503 |
> |
) |
504 |
|
{ |
505 |
|
(*putreal)(r->rdir[0]); |
506 |
|
(*putreal)(r->rdir[1]); |
509 |
|
|
510 |
|
|
511 |
|
static void |
512 |
< |
oputv(r) /* print value */ |
513 |
< |
RAY *r; |
512 |
> |
oputv( /* print value */ |
513 |
> |
RAY *r |
514 |
> |
) |
515 |
|
{ |
457 |
– |
COLR cout; |
458 |
– |
|
516 |
|
if (outform == 'c') { |
517 |
+ |
COLR cout; |
518 |
|
setcolr(cout, colval(r->rcol,RED), |
519 |
|
colval(r->rcol,GRN), |
520 |
|
colval(r->rcol,BLU)); |
528 |
|
|
529 |
|
|
530 |
|
static void |
531 |
< |
oputl(r) /* print effective distance */ |
532 |
< |
RAY *r; |
531 |
> |
oputl( /* print effective distance */ |
532 |
> |
RAY *r |
533 |
> |
) |
534 |
|
{ |
535 |
|
(*putreal)(r->rt); |
536 |
|
} |
537 |
|
|
538 |
|
|
539 |
|
static void |
540 |
< |
oputL(r) /* print single ray length */ |
541 |
< |
RAY *r; |
540 |
> |
oputL( /* print single ray length */ |
541 |
> |
RAY *r |
542 |
> |
) |
543 |
|
{ |
544 |
|
(*putreal)(r->rot); |
545 |
|
} |
546 |
|
|
547 |
|
|
548 |
|
static void |
549 |
< |
oputc(r) /* print local coordinates */ |
550 |
< |
RAY *r; |
549 |
> |
oputc( /* print local coordinates */ |
550 |
> |
RAY *r |
551 |
> |
) |
552 |
|
{ |
553 |
|
(*putreal)(r->uv[0]); |
554 |
|
(*putreal)(r->uv[1]); |
556 |
|
|
557 |
|
|
558 |
|
static void |
559 |
< |
oputp(r) /* print point */ |
560 |
< |
RAY *r; |
559 |
> |
oputp( /* print point */ |
560 |
> |
RAY *r |
561 |
> |
) |
562 |
|
{ |
563 |
|
if (r->rot < FHUGE) { |
564 |
|
(*putreal)(r->rop[0]); |
573 |
|
|
574 |
|
|
575 |
|
static void |
576 |
< |
oputN(r) /* print unperturbed normal */ |
577 |
< |
RAY *r; |
576 |
> |
oputN( /* print unperturbed normal */ |
577 |
> |
RAY *r |
578 |
> |
) |
579 |
|
{ |
580 |
|
if (r->rot < FHUGE) { |
581 |
|
(*putreal)(r->ron[0]); |
590 |
|
|
591 |
|
|
592 |
|
static void |
593 |
< |
oputn(r) /* print perturbed normal */ |
594 |
< |
RAY *r; |
593 |
> |
oputn( /* print perturbed normal */ |
594 |
> |
RAY *r |
595 |
> |
) |
596 |
|
{ |
597 |
|
FVECT pnorm; |
598 |
|
|
610 |
|
|
611 |
|
|
612 |
|
static void |
613 |
< |
oputs(r) /* print name */ |
614 |
< |
RAY *r; |
613 |
> |
oputs( /* print name */ |
614 |
> |
RAY *r |
615 |
> |
) |
616 |
|
{ |
617 |
|
if (r->ro != NULL) |
618 |
|
fputs(r->ro->oname, stdout); |
623 |
|
|
624 |
|
|
625 |
|
static void |
626 |
< |
oputw(r) /* print weight */ |
627 |
< |
RAY *r; |
626 |
> |
oputw( /* print weight */ |
627 |
> |
RAY *r |
628 |
> |
) |
629 |
|
{ |
630 |
|
(*putreal)(r->rweight); |
631 |
|
} |
632 |
|
|
633 |
|
|
634 |
|
static void |
635 |
< |
oputm(r) /* print modifier */ |
636 |
< |
RAY *r; |
635 |
> |
oputW( /* print contribution */ |
636 |
> |
RAY *r |
637 |
> |
) |
638 |
|
{ |
639 |
+ |
COLOR contr; |
640 |
+ |
|
641 |
+ |
raycontrib(contr, r, PRIMARY); |
642 |
+ |
(*putreal)(colval(contr,RED)); |
643 |
+ |
(*putreal)(colval(contr,GRN)); |
644 |
+ |
(*putreal)(colval(contr,BLU)); |
645 |
+ |
} |
646 |
+ |
|
647 |
+ |
|
648 |
+ |
static void |
649 |
+ |
oputm( /* print modifier */ |
650 |
+ |
RAY *r |
651 |
+ |
) |
652 |
+ |
{ |
653 |
|
if (r->ro != NULL) |
654 |
|
if (r->ro->omod != OVOID) |
655 |
|
fputs(objptr(r->ro->omod)->oname, stdout); |
662 |
|
|
663 |
|
|
664 |
|
static void |
665 |
< |
puta(v) /* print ascii value */ |
666 |
< |
double v; |
665 |
> |
oputM( /* print material */ |
666 |
> |
RAY *r |
667 |
> |
) |
668 |
> |
{ |
669 |
> |
OBJREC *mat; |
670 |
> |
|
671 |
> |
if (r->ro != NULL) { |
672 |
> |
if ((mat = findmaterial(r->ro)) != NULL) |
673 |
> |
fputs(mat->oname, stdout); |
674 |
> |
else |
675 |
> |
fputs(VOIDID, stdout); |
676 |
> |
} else |
677 |
> |
putchar('*'); |
678 |
> |
putchar('\t'); |
679 |
> |
} |
680 |
> |
|
681 |
> |
|
682 |
> |
static void |
683 |
> |
oputtilde( /* output tilde (spacer) */ |
684 |
> |
RAY *r |
685 |
> |
) |
686 |
> |
{ |
687 |
> |
fputs("~\t", stdout); |
688 |
> |
} |
689 |
> |
|
690 |
> |
|
691 |
> |
static void |
692 |
> |
puta( /* print ascii value */ |
693 |
> |
double v |
694 |
> |
) |
695 |
|
{ |
696 |
|
printf("%e\t", v); |
697 |
|
} |