1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
42 |
|
int outform = 'a'; /* output format */ |
43 |
|
char *outvals = "v"; /* output specification */ |
44 |
|
|
45 |
+ |
char *tralist[128]; /* list of modifers to trace (or no) */ |
46 |
+ |
int traincl = -1; /* include == 1, exclude == 0 */ |
47 |
+ |
#define MAXTSET 511 /* maximum number in trace set */ |
48 |
+ |
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
49 |
+ |
|
50 |
|
int hresolu = 0; /* horizontal (scan) size */ |
51 |
|
int vresolu = 0; /* vertical resolution */ |
52 |
|
|
53 |
|
double dstrsrc = 0.0; /* square source distribution */ |
54 |
|
double shadthresh = .05; /* shadow threshold */ |
55 |
|
double shadcert = .5; /* shadow certainty */ |
56 |
< |
int directrelay = 1; /* number of source relays */ |
56 |
> |
int directrelay = 2; /* number of source relays */ |
57 |
|
int vspretest = 512; /* virtual source pretest density */ |
58 |
< |
int directinvis = 0; /* sources invisible? */ |
59 |
< |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
58 |
> |
int directvis = 1; /* sources visible? */ |
59 |
> |
double srcsizerat = .2; /* maximum ratio source size/dist. */ |
60 |
|
|
61 |
+ |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
62 |
+ |
double salbedo = 0.; /* global scattering albedo */ |
63 |
+ |
double seccg = 0.; /* global scattering eccentricity */ |
64 |
+ |
double ssampdist = 0.; /* scatter sampling distance */ |
65 |
+ |
|
66 |
|
double specthresh = .15; /* specular sampling threshold */ |
67 |
|
double specjitter = 1.; /* specular sampling jitter */ |
68 |
|
|
69 |
+ |
int backvis = 1; /* back face visibility */ |
70 |
+ |
|
71 |
|
int maxdepth = 6; /* maximum recursion depth */ |
72 |
|
double minweight = 4e-3; /* minimum ray weight */ |
73 |
|
|
74 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
75 |
|
double ambacc = 0.2; /* ambient accuracy */ |
76 |
< |
int ambres = 32; /* ambient resolution */ |
77 |
< |
int ambdiv = 128; /* ambient divisions */ |
76 |
> |
int ambres = 128; /* ambient resolution */ |
77 |
> |
int ambdiv = 512; /* ambient divisions */ |
78 |
|
int ambssamp = 0; /* ambient super-samples */ |
79 |
|
int ambounce = 0; /* ambient bounces */ |
80 |
|
char *amblist[128]; /* ambient include/exclude list */ |
85 |
|
static RAY thisray; /* for our convenience */ |
86 |
|
|
87 |
|
static int oputo(), oputd(), oputv(), oputl(), oputL(), |
88 |
< |
oputp(), oputn(), oputs(), oputw(), oputm(); |
88 |
> |
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
89 |
|
|
90 |
< |
static int (*ray_out[10])(), (*every_out[10])(); |
91 |
< |
static int castonly; |
90 |
> |
static int ourtrace(), tabin(); |
91 |
> |
static int (*ray_out[16])(), (*every_out[16])(); |
92 |
> |
static int castonly = 0; |
93 |
|
|
94 |
|
static int puta(), putf(), putd(); |
95 |
|
|
99 |
|
quit(code) /* quit program */ |
100 |
|
int code; |
101 |
|
{ |
102 |
+ |
#ifndef NIX |
103 |
+ |
headclean(); /* delete header file */ |
104 |
+ |
pfclean(); /* clean up persist files */ |
105 |
+ |
#endif |
106 |
|
exit(code); |
107 |
|
} |
108 |
|
|
135 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
136 |
|
error(SYSTEM, errmsg); |
137 |
|
} |
138 |
+ |
#ifdef MSDOS |
139 |
+ |
if (inform != 'a') |
140 |
+ |
setmode(fileno(fp), O_BINARY); |
141 |
+ |
#endif |
142 |
|
/* set up output */ |
143 |
|
setoutput(outvals); |
144 |
|
switch (outform) { |
152 |
|
default: |
153 |
|
error(CONSISTENCY, "botched output format"); |
154 |
|
} |
155 |
< |
fputformat(formstr(outform), stdout); |
156 |
< |
putchar('\n'); |
157 |
< |
if (hresolu > 0 && vresolu > 0) |
158 |
< |
fprtresolu(hresolu, vresolu, stdout); |
155 |
> |
if (hresolu > 0) { |
156 |
> |
if (vresolu > 0) |
157 |
> |
fprtresolu(hresolu, vresolu, stdout); |
158 |
> |
fflush(stdout); |
159 |
> |
} |
160 |
|
/* process file */ |
161 |
|
while (getvec(orig, inform, fp) == 0 && |
162 |
|
getvec(direc, inform, fp) == 0) { |
170 |
|
if (imm_irrad) |
171 |
|
irrad(orig, direc); |
172 |
|
else |
173 |
< |
traceray(orig, direc); |
173 |
> |
rad(orig, direc); |
174 |
|
/* flush if time */ |
175 |
|
if (--nextflush == 0) { |
176 |
|
fflush(stdout); |
181 |
|
if (--vcount == 0) /* check for end */ |
182 |
|
break; |
183 |
|
} |
184 |
+ |
fflush(stdout); |
185 |
|
if (vcount > 0) |
186 |
|
error(USER, "read error"); |
187 |
< |
fclose(fp); |
187 |
> |
if (fname != NULL) |
188 |
> |
fclose(fp); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
setoutput(vs) /* set up output tables */ |
193 |
|
register char *vs; |
194 |
|
{ |
195 |
< |
extern int ourtrace(), (*trace)(); |
195 |
> |
extern int (*trace)(); |
196 |
|
register int (**table)() = ray_out; |
197 |
|
|
198 |
|
castonly = 1; |
224 |
|
case 'p': /* point */ |
225 |
|
*table++ = oputp; |
226 |
|
break; |
227 |
< |
case 'n': /* normal */ |
227 |
> |
case 'n': /* perturbed normal */ |
228 |
|
*table++ = oputn; |
229 |
+ |
castonly = 0; |
230 |
|
break; |
231 |
+ |
case 'N': /* unperturbed normal */ |
232 |
+ |
*table++ = oputN; |
233 |
+ |
break; |
234 |
|
case 's': /* surface */ |
235 |
|
*table++ = oputs; |
236 |
|
break; |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
< |
traceray(org, dir) /* compute and print ray value(s) */ |
248 |
> |
rad(org, dir) /* compute and print ray value(s) */ |
249 |
|
FVECT org, dir; |
250 |
|
{ |
223 |
– |
register int (**tp)(); |
224 |
– |
|
251 |
|
VCOPY(thisray.rorg, org); |
252 |
|
VCOPY(thisray.rdir, dir); |
253 |
+ |
thisray.rmax = 0.0; |
254 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
255 |
|
if (castonly) |
256 |
|
localhit(&thisray, &thescene) || sourcehit(&thisray); |
257 |
|
else |
258 |
|
rayvalue(&thisray); |
259 |
< |
|
233 |
< |
if (ray_out[0] == NULL) |
234 |
< |
return; |
235 |
< |
for (tp = ray_out; *tp != NULL; tp++) |
236 |
< |
(**tp)(&thisray); |
237 |
< |
if (outform == 'a') |
238 |
< |
putchar('\n'); |
259 |
> |
printvals(&thisray); |
260 |
|
} |
261 |
|
|
262 |
|
|
271 |
|
} |
272 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
273 |
|
/* pretend we hit surface */ |
274 |
< |
thisray.rot = 1.0; |
274 |
> |
thisray.rot = 1.0-1e-4; |
275 |
|
thisray.rod = 1.0; |
276 |
|
VCOPY(thisray.ron, dir); |
277 |
|
for (i = 0; i < 3; i++) /* fudge factor */ |
278 |
|
thisray.rop[i] = org[i] + 1e-4*dir[i]; |
279 |
|
/* compute and print */ |
280 |
|
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
281 |
< |
oputv(&thisray); |
281 |
> |
printvals(&thisray); |
282 |
> |
} |
283 |
> |
|
284 |
> |
|
285 |
> |
printvals(r) /* print requested ray values */ |
286 |
> |
RAY *r; |
287 |
> |
{ |
288 |
> |
register int (**tp)(); |
289 |
> |
|
290 |
> |
if (ray_out[0] == NULL) |
291 |
> |
return; |
292 |
> |
for (tp = ray_out; *tp != NULL; tp++) |
293 |
> |
(**tp)(r); |
294 |
|
if (outform == 'a') |
295 |
|
putchar('\n'); |
296 |
|
} |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
+ |
tranotify(obj) /* record new modifier */ |
337 |
+ |
OBJECT obj; |
338 |
+ |
{ |
339 |
+ |
static int hitlimit = 0; |
340 |
+ |
register OBJREC *o = objptr(obj); |
341 |
+ |
register char **tralp; |
342 |
+ |
|
343 |
+ |
if (hitlimit || !ismodifier(o->otype)) |
344 |
+ |
return; |
345 |
+ |
for (tralp = tralist; *tralp != NULL; tralp++) |
346 |
+ |
if (!strcmp(o->oname, *tralp)) { |
347 |
+ |
if (traset[0] >= MAXTSET) { |
348 |
+ |
error(WARNING, "too many modifiers in trace list"); |
349 |
+ |
hitlimit++; |
350 |
+ |
return; /* should this be fatal? */ |
351 |
+ |
} |
352 |
+ |
insertelem(traset, obj); |
353 |
+ |
return; |
354 |
+ |
} |
355 |
+ |
} |
356 |
+ |
|
357 |
+ |
|
358 |
|
static |
359 |
|
ourtrace(r) /* print ray values */ |
360 |
|
RAY *r; |
363 |
|
|
364 |
|
if (every_out[0] == NULL) |
365 |
|
return; |
366 |
+ |
if (r->ro == NULL) { |
367 |
+ |
if (traincl == 1) |
368 |
+ |
return; |
369 |
+ |
} else if (traincl != -1 && traincl != inset(traset, r->ro->omod)) |
370 |
+ |
return; |
371 |
|
tabin(r); |
372 |
|
for (tp = every_out; *tp != NULL; tp++) |
373 |
|
(**tp)(r); |
458 |
|
|
459 |
|
|
460 |
|
static |
461 |
< |
oputn(r) /* print normal */ |
461 |
> |
oputN(r) /* print unperturbed normal */ |
462 |
|
register RAY *r; |
463 |
|
{ |
464 |
|
if (r->rot < FHUGE) { |
470 |
|
(*putreal)(0.0); |
471 |
|
(*putreal)(0.0); |
472 |
|
} |
473 |
+ |
} |
474 |
+ |
|
475 |
+ |
|
476 |
+ |
static |
477 |
+ |
oputn(r) /* print perturbed normal */ |
478 |
+ |
RAY *r; |
479 |
+ |
{ |
480 |
+ |
FVECT pnorm; |
481 |
+ |
|
482 |
+ |
if (r->rot >= FHUGE) { |
483 |
+ |
(*putreal)(0.0); |
484 |
+ |
(*putreal)(0.0); |
485 |
+ |
(*putreal)(0.0); |
486 |
+ |
return; |
487 |
+ |
} |
488 |
+ |
raynormal(pnorm, r); |
489 |
+ |
(*putreal)(pnorm[0]); |
490 |
+ |
(*putreal)(pnorm[1]); |
491 |
+ |
(*putreal)(pnorm[2]); |
492 |
|
} |
493 |
|
|
494 |
|
|