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 */ |
57 |
|
int vresolu = 0; /* vertical resolution */ |
58 |
|
|
59 |
|
double dstrsrc = 0.0; /* square source distribution */ |
60 |
< |
double shadthresh = .05; /* shadow threshold */ |
61 |
< |
double shadcert = .5; /* shadow certainty */ |
60 |
> |
double shadthresh = .03; /* shadow threshold */ |
61 |
> |
double shadcert = .75; /* shadow certainty */ |
62 |
|
int directrelay = 2; /* number of source relays */ |
63 |
|
int vspretest = 512; /* virtual source pretest density */ |
64 |
|
int directvis = 1; /* sources visible? */ |
74 |
|
|
75 |
|
int backvis = 1; /* back face visibility */ |
76 |
|
|
77 |
< |
int maxdepth = 6; /* maximum recursion depth */ |
78 |
< |
double minweight = 4e-3; /* minimum ray weight */ |
77 |
> |
int maxdepth = 8; /* maximum recursion depth */ |
78 |
> |
double minweight = 2e-3; /* minimum ray weight */ |
79 |
|
|
80 |
|
char *ambfile = NULL; /* ambient file name */ |
81 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
82 |
|
int ambvwt = 0; /* initial weight for ambient value */ |
83 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
84 |
< |
int ambres = 128; /* ambient resolution */ |
85 |
< |
int ambdiv = 512; /* ambient divisions */ |
86 |
< |
int ambssamp = 0; /* ambient super-samples */ |
83 |
> |
double ambacc = 0.15; /* ambient accuracy */ |
84 |
> |
int ambres = 256; /* ambient resolution */ |
85 |
> |
int ambdiv = 1024; /* ambient divisions */ |
86 |
> |
int ambssamp = 512; /* ambient super-samples */ |
87 |
|
int ambounce = 0; /* ambient bounces */ |
88 |
< |
char *amblist[128]; /* ambient include/exclude list */ |
88 |
> |
char *amblist[AMBLLEN]; /* ambient include/exclude list */ |
89 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
90 |
|
|
91 |
+ |
static int castonly = 0; |
92 |
|
|
93 |
|
static RAY thisray; /* for our convenience */ |
94 |
|
|
95 |
< |
static void oputo(), oputd(), oputv(), oputl(), oputL(), |
96 |
< |
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
95 |
> |
typedef void putf_t(double v); |
96 |
> |
static putf_t puta, putd, putf; |
97 |
|
|
98 |
< |
static void ourtrace(), tabin(); |
99 |
< |
static void (*ray_out[16])(), (*every_out[16])(); |
100 |
< |
static int castonly = 0; |
98 |
> |
typedef void oputf_t(RAY *r); |
99 |
> |
static oputf_t oputo, oputd, oputv, oputl, oputL, oputc, oputp, |
100 |
> |
oputn, oputN, oputs, oputw, oputW, oputm, oputM; |
101 |
|
|
102 |
< |
static void puta(), putf(), putd(); |
102 |
> |
static void setoutput(char *vs); |
103 |
> |
static void tranotify(OBJECT obj); |
104 |
> |
static void bogusray(void); |
105 |
> |
static void rad(FVECT org, FVECT dir, double dmax); |
106 |
> |
static void irrad(FVECT org, FVECT dir); |
107 |
> |
static void printvals(RAY *r); |
108 |
> |
static int getvec(FVECT vec, int fmt, FILE *fp); |
109 |
> |
static void tabin(RAY *r); |
110 |
> |
static void ourtrace(RAY *r); |
111 |
|
|
112 |
< |
static void (*putreal)(); |
112 |
> |
static oputf_t *ray_out[16], *every_out[16]; |
113 |
> |
static putf_t *putreal; |
114 |
|
|
115 |
< |
void bogusray(), rad(), irrad(), printvals(); |
115 |
> |
void (*addobjnotify[])() = {ambnotify, tranotify, NULL}; |
116 |
|
|
117 |
|
|
118 |
|
void |
119 |
< |
quit(code) /* quit program */ |
120 |
< |
int code; |
119 |
> |
quit( /* quit program */ |
120 |
> |
int code |
121 |
> |
) |
122 |
|
{ |
123 |
< |
#ifndef NIX |
123 |
> |
#ifndef NON_POSIX /* XXX we don't clean up elsewhere? */ |
124 |
|
headclean(); /* delete header file */ |
125 |
|
pfclean(); /* clean up persist files */ |
126 |
|
#endif |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
< |
char * |
132 |
< |
formstr(f) /* return format identifier */ |
133 |
< |
int f; |
131 |
> |
extern char * |
132 |
> |
formstr( /* return format identifier */ |
133 |
> |
int f |
134 |
> |
) |
135 |
|
{ |
136 |
|
switch (f) { |
137 |
|
case 'a': return("ascii"); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
< |
void |
147 |
< |
rtrace(fname) /* trace rays from file */ |
148 |
< |
char *fname; |
146 |
> |
extern void |
147 |
> |
rtrace( /* trace rays from file */ |
148 |
> |
char *fname |
149 |
> |
) |
150 |
|
{ |
151 |
|
long vcount = hresolu>1 ? hresolu*vresolu : vresolu; |
152 |
|
long nextflush = hresolu; |
160 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
161 |
|
error(SYSTEM, errmsg); |
162 |
|
} |
163 |
< |
#ifdef MSDOS |
163 |
> |
#ifdef _WIN32 |
164 |
|
if (inform != 'a') |
165 |
< |
setmode(fileno(fp), O_BINARY); |
165 |
> |
SET_FILE_BINARY(fp); |
166 |
|
#endif |
167 |
|
/* set up output */ |
168 |
|
setoutput(outvals); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
< |
setoutput(vs) /* set up output tables */ |
223 |
< |
register char *vs; |
222 |
> |
static void |
223 |
> |
trace_sources(void) /* trace rays to light sources, also */ |
224 |
|
{ |
225 |
< |
extern void (*trace)(); |
226 |
< |
register void (**table)() = ray_out; |
225 |
> |
int sn; |
226 |
> |
|
227 |
> |
for (sn = 0; sn < nsources; sn++) |
228 |
> |
source[sn].sflags |= SFOLLOW; |
229 |
> |
} |
230 |
|
|
231 |
+ |
|
232 |
+ |
static void |
233 |
+ |
setoutput( /* set up output tables */ |
234 |
+ |
register char *vs |
235 |
+ |
) |
236 |
+ |
{ |
237 |
+ |
register oputf_t **table = ray_out; |
238 |
+ |
|
239 |
|
castonly = 1; |
240 |
|
while (*vs) |
241 |
|
switch (*vs++) { |
242 |
+ |
case 'T': /* trace sources */ |
243 |
+ |
trace_sources(); |
244 |
+ |
/* fall through */ |
245 |
|
case 't': /* trace */ |
246 |
|
*table = NULL; |
247 |
|
table = every_out; |
262 |
|
*table++ = oputl; |
263 |
|
castonly = 0; |
264 |
|
break; |
265 |
+ |
case 'c': /* local coordinates */ |
266 |
+ |
*table++ = oputc; |
267 |
+ |
break; |
268 |
|
case 'L': /* single ray length */ |
269 |
|
*table++ = oputL; |
270 |
|
break; |
284 |
|
case 'w': /* weight */ |
285 |
|
*table++ = oputw; |
286 |
|
break; |
287 |
+ |
case 'W': /* coefficient */ |
288 |
+ |
*table++ = oputW; |
289 |
+ |
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
290 |
+ |
error(WARNING, |
291 |
+ |
"-otW accuracy requires -aa 0 -as 0"); |
292 |
+ |
break; |
293 |
|
case 'm': /* modifier */ |
294 |
|
*table++ = oputm; |
295 |
|
break; |
296 |
+ |
case 'M': /* material */ |
297 |
+ |
*table++ = oputM; |
298 |
+ |
break; |
299 |
|
} |
300 |
|
*table = NULL; |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
< |
void |
305 |
< |
bogusray() /* print out empty record */ |
304 |
> |
static void |
305 |
> |
bogusray(void) /* print out empty record */ |
306 |
|
{ |
307 |
|
thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] = |
308 |
|
thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0; |
309 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
309 |
> |
thisray.rmax = 0.0; |
310 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
311 |
|
printvals(&thisray); |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
< |
void |
316 |
< |
rad(org, dir, dmax) /* compute and print ray value(s) */ |
317 |
< |
FVECT org, dir; |
318 |
< |
double dmax; |
315 |
> |
static void |
316 |
> |
rad( /* compute and print ray value(s) */ |
317 |
> |
FVECT org, |
318 |
> |
FVECT dir, |
319 |
> |
double dmax |
320 |
> |
) |
321 |
|
{ |
322 |
|
VCOPY(thisray.rorg, org); |
323 |
|
VCOPY(thisray.rdir, dir); |
324 |
|
thisray.rmax = dmax; |
325 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
325 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
326 |
|
if (castonly) { |
327 |
< |
if (!localhit(&thisray, &thescene)) |
327 |
> |
if (!localhit(&thisray, &thescene)) { |
328 |
|
if (thisray.ro == &Aftplane) { /* clipped */ |
329 |
|
thisray.ro = NULL; |
330 |
|
thisray.rot = FHUGE; |
331 |
|
} else |
332 |
|
sourcehit(&thisray); |
333 |
+ |
} |
334 |
|
} else |
335 |
|
rayvalue(&thisray); |
336 |
|
printvals(&thisray); |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
< |
void |
341 |
< |
irrad(org, dir) /* compute immediate irradiance value */ |
342 |
< |
FVECT org, dir; |
340 |
> |
static void |
341 |
> |
irrad( /* compute immediate irradiance value */ |
342 |
> |
FVECT org, |
343 |
> |
FVECT dir |
344 |
> |
) |
345 |
|
{ |
346 |
|
register int i; |
347 |
|
|
349 |
|
thisray.rorg[i] = org[i] + dir[i]; |
350 |
|
thisray.rdir[i] = -dir[i]; |
351 |
|
} |
352 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
352 |
> |
thisray.rmax = 0.0; |
353 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
354 |
|
/* pretend we hit surface */ |
355 |
|
thisray.rot = 1.0-1e-4; |
356 |
|
thisray.rod = 1.0; |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
< |
void |
367 |
< |
printvals(r) /* print requested ray values */ |
368 |
< |
RAY *r; |
366 |
> |
static void |
367 |
> |
printvals( /* print requested ray values */ |
368 |
> |
RAY *r |
369 |
> |
) |
370 |
|
{ |
371 |
< |
register void (**tp)(); |
371 |
> |
register oputf_t **tp; |
372 |
|
|
373 |
|
if (ray_out[0] == NULL) |
374 |
|
return; |
379 |
|
} |
380 |
|
|
381 |
|
|
382 |
< |
int |
383 |
< |
getvec(vec, fmt, fp) /* get a vector from fp */ |
384 |
< |
register FVECT vec; |
385 |
< |
int fmt; |
386 |
< |
FILE *fp; |
382 |
> |
static int |
383 |
> |
getvec( /* get a vector from fp */ |
384 |
> |
register FVECT vec, |
385 |
> |
int fmt, |
386 |
> |
FILE *fp |
387 |
> |
) |
388 |
|
{ |
389 |
|
static float vf[3]; |
390 |
|
static double vd[3]; |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
< |
void |
421 |
< |
tranotify(obj) /* record new modifier */ |
422 |
< |
OBJECT obj; |
420 |
> |
static void |
421 |
> |
tranotify( /* record new modifier */ |
422 |
> |
OBJECT obj |
423 |
> |
) |
424 |
|
{ |
425 |
|
static int hitlimit = 0; |
426 |
|
register OBJREC *o = objptr(obj); |
447 |
|
|
448 |
|
|
449 |
|
static void |
450 |
< |
ourtrace(r) /* print ray values */ |
451 |
< |
RAY *r; |
450 |
> |
ourtrace( /* print ray values */ |
451 |
> |
RAY *r |
452 |
> |
) |
453 |
|
{ |
454 |
< |
register void (**tp)(); |
454 |
> |
register oputf_t **tp; |
455 |
|
|
456 |
|
if (every_out[0] == NULL) |
457 |
|
return; |
468 |
|
|
469 |
|
|
470 |
|
static void |
471 |
< |
tabin(r) /* tab in appropriate amount */ |
472 |
< |
RAY *r; |
471 |
> |
tabin( /* tab in appropriate amount */ |
472 |
> |
RAY *r |
473 |
> |
) |
474 |
|
{ |
475 |
< |
register RAY *rp; |
475 |
> |
const RAY *rp; |
476 |
|
|
477 |
|
for (rp = r->parent; rp != NULL; rp = rp->parent) |
478 |
|
putchar('\t'); |
480 |
|
|
481 |
|
|
482 |
|
static void |
483 |
< |
oputo(r) /* print origin */ |
484 |
< |
register RAY *r; |
483 |
> |
oputo( /* print origin */ |
484 |
> |
RAY *r |
485 |
> |
) |
486 |
|
{ |
487 |
|
(*putreal)(r->rorg[0]); |
488 |
|
(*putreal)(r->rorg[1]); |
491 |
|
|
492 |
|
|
493 |
|
static void |
494 |
< |
oputd(r) /* print direction */ |
495 |
< |
register RAY *r; |
494 |
> |
oputd( /* print direction */ |
495 |
> |
RAY *r |
496 |
> |
) |
497 |
|
{ |
498 |
|
(*putreal)(r->rdir[0]); |
499 |
|
(*putreal)(r->rdir[1]); |
502 |
|
|
503 |
|
|
504 |
|
static void |
505 |
< |
oputv(r) /* print value */ |
506 |
< |
register RAY *r; |
505 |
> |
oputv( /* print value */ |
506 |
> |
RAY *r |
507 |
> |
) |
508 |
|
{ |
509 |
|
COLR cout; |
510 |
|
|
522 |
|
|
523 |
|
|
524 |
|
static void |
525 |
< |
oputl(r) /* print effective distance */ |
526 |
< |
register RAY *r; |
525 |
> |
oputl( /* print effective distance */ |
526 |
> |
RAY *r |
527 |
> |
) |
528 |
|
{ |
529 |
|
(*putreal)(r->rt); |
530 |
|
} |
531 |
|
|
532 |
|
|
533 |
|
static void |
534 |
< |
oputL(r) /* print single ray length */ |
535 |
< |
register RAY *r; |
534 |
> |
oputL( /* print single ray length */ |
535 |
> |
RAY *r |
536 |
> |
) |
537 |
|
{ |
538 |
|
(*putreal)(r->rot); |
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
|
static void |
543 |
< |
oputp(r) /* print point */ |
544 |
< |
register RAY *r; |
543 |
> |
oputc( /* print local coordinates */ |
544 |
> |
RAY *r |
545 |
> |
) |
546 |
|
{ |
547 |
+ |
(*putreal)(r->uv[0]); |
548 |
+ |
(*putreal)(r->uv[1]); |
549 |
+ |
} |
550 |
+ |
|
551 |
+ |
|
552 |
+ |
static void |
553 |
+ |
oputp( /* print point */ |
554 |
+ |
RAY *r |
555 |
+ |
) |
556 |
+ |
{ |
557 |
|
if (r->rot < FHUGE) { |
558 |
|
(*putreal)(r->rop[0]); |
559 |
|
(*putreal)(r->rop[1]); |
567 |
|
|
568 |
|
|
569 |
|
static void |
570 |
< |
oputN(r) /* print unperturbed normal */ |
571 |
< |
register RAY *r; |
570 |
> |
oputN( /* print unperturbed normal */ |
571 |
> |
RAY *r |
572 |
> |
) |
573 |
|
{ |
574 |
|
if (r->rot < FHUGE) { |
575 |
|
(*putreal)(r->ron[0]); |
584 |
|
|
585 |
|
|
586 |
|
static void |
587 |
< |
oputn(r) /* print perturbed normal */ |
588 |
< |
RAY *r; |
587 |
> |
oputn( /* print perturbed normal */ |
588 |
> |
RAY *r |
589 |
> |
) |
590 |
|
{ |
591 |
|
FVECT pnorm; |
592 |
|
|
604 |
|
|
605 |
|
|
606 |
|
static void |
607 |
< |
oputs(r) /* print name */ |
608 |
< |
register RAY *r; |
607 |
> |
oputs( /* print name */ |
608 |
> |
RAY *r |
609 |
> |
) |
610 |
|
{ |
611 |
|
if (r->ro != NULL) |
612 |
|
fputs(r->ro->oname, stdout); |
617 |
|
|
618 |
|
|
619 |
|
static void |
620 |
< |
oputw(r) /* print weight */ |
621 |
< |
register RAY *r; |
620 |
> |
oputw( /* print weight */ |
621 |
> |
RAY *r |
622 |
> |
) |
623 |
|
{ |
624 |
|
(*putreal)(r->rweight); |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
static void |
629 |
< |
oputm(r) /* print modifier */ |
630 |
< |
register RAY *r; |
629 |
> |
oputW( /* print contribution */ |
630 |
> |
RAY *r |
631 |
> |
) |
632 |
|
{ |
633 |
+ |
COLOR contr; |
634 |
+ |
COLR cout; |
635 |
+ |
|
636 |
+ |
raycontrib(contr, r, PRIMARY); |
637 |
+ |
if (outform == 'c') { |
638 |
+ |
setcolr(cout, colval(contr,RED), |
639 |
+ |
colval(contr,GRN), |
640 |
+ |
colval(contr,BLU)); |
641 |
+ |
fwrite((char *)cout, sizeof(cout), 1, stdout); |
642 |
+ |
return; |
643 |
+ |
} |
644 |
+ |
(*putreal)(colval(contr,RED)); |
645 |
+ |
(*putreal)(colval(contr,GRN)); |
646 |
+ |
(*putreal)(colval(contr,BLU)); |
647 |
+ |
} |
648 |
+ |
|
649 |
+ |
|
650 |
+ |
static void |
651 |
+ |
oputm( /* print modifier */ |
652 |
+ |
RAY *r |
653 |
+ |
) |
654 |
+ |
{ |
655 |
|
if (r->ro != NULL) |
656 |
|
if (r->ro->omod != OVOID) |
657 |
|
fputs(objptr(r->ro->omod)->oname, stdout); |
664 |
|
|
665 |
|
|
666 |
|
static void |
667 |
< |
puta(v) /* print ascii value */ |
668 |
< |
double v; |
667 |
> |
oputM( /* print material */ |
668 |
> |
RAY *r |
669 |
> |
) |
670 |
> |
{ |
671 |
> |
OBJREC *mat; |
672 |
> |
|
673 |
> |
if (r->ro != NULL) { |
674 |
> |
if ((mat = findmaterial(r->ro)) != NULL) |
675 |
> |
fputs(mat->oname, stdout); |
676 |
> |
else |
677 |
> |
fputs(VOIDID, stdout); |
678 |
> |
} else |
679 |
> |
putchar('*'); |
680 |
> |
putchar('\t'); |
681 |
> |
} |
682 |
> |
|
683 |
> |
|
684 |
> |
static void |
685 |
> |
puta( /* print ascii value */ |
686 |
> |
double v |
687 |
> |
) |
688 |
|
{ |
689 |
|
printf("%e\t", v); |
690 |
|
} |