1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
|
#endif |
6 |
|
|
7 |
|
/* |
37 |
|
int samplendx = 0; /* index for this sample */ |
38 |
|
|
39 |
|
int imm_irrad = 0; /* compute immediate irradiance? */ |
40 |
+ |
int lim_dist = 0; /* limit distance? */ |
41 |
|
|
42 |
|
int inform = 'a'; /* input format */ |
43 |
|
int outform = 'a'; /* output format */ |
44 |
|
char *outvals = "v"; /* output specification */ |
45 |
|
|
46 |
+ |
char *tralist[128]; /* list of modifers to trace (or no) */ |
47 |
+ |
int traincl = -1; /* include == 1, exclude == 0 */ |
48 |
+ |
#define MAXTSET 511 /* maximum number in trace set */ |
49 |
+ |
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
50 |
+ |
|
51 |
|
int hresolu = 0; /* horizontal (scan) size */ |
52 |
|
int vresolu = 0; /* vertical resolution */ |
53 |
|
|
54 |
|
double dstrsrc = 0.0; /* square source distribution */ |
55 |
|
double shadthresh = .05; /* shadow threshold */ |
56 |
|
double shadcert = .5; /* shadow certainty */ |
57 |
< |
int directrelay = 1; /* number of source relays */ |
57 |
> |
int directrelay = 2; /* number of source relays */ |
58 |
|
int vspretest = 512; /* virtual source pretest density */ |
59 |
|
int directvis = 1; /* sources visible? */ |
60 |
< |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
60 |
> |
double srcsizerat = .2; /* maximum ratio source size/dist. */ |
61 |
|
|
62 |
+ |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
63 |
+ |
COLOR salbedo = BLKCOLOR; /* global scattering albedo */ |
64 |
+ |
double seccg = 0.; /* global scattering eccentricity */ |
65 |
+ |
double ssampdist = 0.; /* scatter sampling distance */ |
66 |
+ |
|
67 |
|
double specthresh = .15; /* specular sampling threshold */ |
68 |
|
double specjitter = 1.; /* specular sampling jitter */ |
69 |
|
|
70 |
+ |
int backvis = 1; /* back face visibility */ |
71 |
+ |
|
72 |
|
int maxdepth = 6; /* maximum recursion depth */ |
73 |
|
double minweight = 4e-3; /* minimum ray weight */ |
74 |
|
|
75 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
76 |
+ |
int ambvwt = 0; /* initial weight for ambient value */ |
77 |
|
double ambacc = 0.2; /* ambient accuracy */ |
78 |
< |
int ambres = 32; /* ambient resolution */ |
79 |
< |
int ambdiv = 128; /* ambient divisions */ |
78 |
> |
int ambres = 128; /* ambient resolution */ |
79 |
> |
int ambdiv = 512; /* ambient divisions */ |
80 |
|
int ambssamp = 0; /* ambient super-samples */ |
81 |
|
int ambounce = 0; /* ambient bounces */ |
82 |
|
char *amblist[128]; /* ambient include/exclude list */ |
83 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
84 |
|
|
85 |
|
extern OBJREC Lamb; /* a Lambertian surface */ |
86 |
+ |
extern OBJREC Aftplane; /* aft clipping object */ |
87 |
|
|
88 |
+ |
|
89 |
|
static RAY thisray; /* for our convenience */ |
90 |
|
|
91 |
|
static int oputo(), oputd(), oputv(), oputl(), oputL(), |
92 |
|
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
93 |
|
|
94 |
< |
static int (*ray_out[10])(), (*every_out[10])(); |
95 |
< |
static int castonly; |
94 |
> |
static int ourtrace(), tabin(); |
95 |
> |
static int (*ray_out[16])(), (*every_out[16])(); |
96 |
> |
static int castonly = 0; |
97 |
|
|
98 |
|
static int puta(), putf(), putd(); |
99 |
|
|
131 |
|
long vcount = hresolu>1 ? hresolu*vresolu : vresolu; |
132 |
|
long nextflush = hresolu; |
133 |
|
FILE *fp; |
134 |
+ |
double d; |
135 |
|
FVECT orig, direc; |
136 |
|
/* set up input */ |
137 |
|
if (fname == NULL) |
166 |
|
while (getvec(orig, inform, fp) == 0 && |
167 |
|
getvec(direc, inform, fp) == 0) { |
168 |
|
|
169 |
< |
if (normalize(direc) == 0.0) { /* zero ==> flush */ |
170 |
< |
fflush(stdout); |
171 |
< |
continue; |
172 |
< |
} |
173 |
< |
samplendx++; |
169 |
> |
d = normalize(direc); |
170 |
> |
if (d == 0.0) { /* zero ==> flush */ |
171 |
> |
bogusray(); |
172 |
> |
if (--nextflush <= 0 || vcount <= 0) { |
173 |
> |
fflush(stdout); |
174 |
> |
nextflush = hresolu; |
175 |
> |
} |
176 |
> |
} else { |
177 |
> |
samplendx++; |
178 |
|
/* compute and print */ |
179 |
< |
if (imm_irrad) |
180 |
< |
irrad(orig, direc); |
181 |
< |
else |
182 |
< |
traceray(orig, direc); |
179 |
> |
if (imm_irrad) |
180 |
> |
irrad(orig, direc); |
181 |
> |
else |
182 |
> |
rad(orig, direc, lim_dist ? d : 0.0); |
183 |
|
/* flush if time */ |
184 |
< |
if (--nextflush == 0) { |
185 |
< |
fflush(stdout); |
186 |
< |
nextflush = hresolu; |
184 |
> |
if (--nextflush == 0) { |
185 |
> |
fflush(stdout); |
186 |
> |
nextflush = hresolu; |
187 |
> |
} |
188 |
|
} |
189 |
|
if (ferror(stdout)) |
190 |
|
error(SYSTEM, "write error"); |
202 |
|
setoutput(vs) /* set up output tables */ |
203 |
|
register char *vs; |
204 |
|
{ |
205 |
< |
extern int ourtrace(), (*trace)(); |
205 |
> |
extern int (*trace)(); |
206 |
|
register int (**table)() = ray_out; |
207 |
|
|
208 |
|
castonly = 1; |
255 |
|
} |
256 |
|
|
257 |
|
|
258 |
< |
traceray(org, dir) /* compute and print ray value(s) */ |
236 |
< |
FVECT org, dir; |
258 |
> |
bogusray() /* print out empty record */ |
259 |
|
{ |
260 |
< |
register int (**tp)(); |
260 |
> |
thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] = |
261 |
> |
thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0; |
262 |
> |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
263 |
> |
printvals(&thisray); |
264 |
> |
} |
265 |
|
|
266 |
+ |
|
267 |
+ |
rad(org, dir, dmax) /* compute and print ray value(s) */ |
268 |
+ |
FVECT org, dir; |
269 |
+ |
double dmax; |
270 |
+ |
{ |
271 |
|
VCOPY(thisray.rorg, org); |
272 |
|
VCOPY(thisray.rdir, dir); |
273 |
+ |
thisray.rmax = dmax; |
274 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
275 |
< |
if (castonly) |
276 |
< |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
277 |
< |
else |
275 |
> |
if (castonly) { |
276 |
> |
if (!localhit(&thisray, &thescene)) |
277 |
> |
if (thisray.ro == &Aftplane) { /* clipped */ |
278 |
> |
thisray.ro = NULL; |
279 |
> |
thisray.rot = FHUGE; |
280 |
> |
} else |
281 |
> |
sourcehit(&thisray); |
282 |
> |
} else |
283 |
|
rayvalue(&thisray); |
284 |
< |
|
248 |
< |
if (ray_out[0] == NULL) |
249 |
< |
return; |
250 |
< |
for (tp = ray_out; *tp != NULL; tp++) |
251 |
< |
(**tp)(&thisray); |
252 |
< |
if (outform == 'a') |
253 |
< |
putchar('\n'); |
284 |
> |
printvals(&thisray); |
285 |
|
} |
286 |
|
|
287 |
|
|
296 |
|
} |
297 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
298 |
|
/* pretend we hit surface */ |
299 |
< |
thisray.rot = 1.0; |
299 |
> |
thisray.rot = 1.0-1e-4; |
300 |
|
thisray.rod = 1.0; |
301 |
|
VCOPY(thisray.ron, dir); |
302 |
|
for (i = 0; i < 3; i++) /* fudge factor */ |
303 |
|
thisray.rop[i] = org[i] + 1e-4*dir[i]; |
304 |
|
/* compute and print */ |
305 |
|
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
306 |
< |
oputv(&thisray); |
306 |
> |
printvals(&thisray); |
307 |
> |
} |
308 |
> |
|
309 |
> |
|
310 |
> |
printvals(r) /* print requested ray values */ |
311 |
> |
RAY *r; |
312 |
> |
{ |
313 |
> |
register int (**tp)(); |
314 |
> |
|
315 |
> |
if (ray_out[0] == NULL) |
316 |
> |
return; |
317 |
> |
for (tp = ray_out; *tp != NULL; tp++) |
318 |
> |
(**tp)(r); |
319 |
|
if (outform == 'a') |
320 |
|
putchar('\n'); |
321 |
|
} |
358 |
|
} |
359 |
|
|
360 |
|
|
361 |
+ |
tranotify(obj) /* record new modifier */ |
362 |
+ |
OBJECT obj; |
363 |
+ |
{ |
364 |
+ |
static int hitlimit = 0; |
365 |
+ |
register OBJREC *o = objptr(obj); |
366 |
+ |
register char **tralp; |
367 |
+ |
|
368 |
+ |
if (hitlimit || !ismodifier(o->otype)) |
369 |
+ |
return; |
370 |
+ |
for (tralp = tralist; *tralp != NULL; tralp++) |
371 |
+ |
if (!strcmp(o->oname, *tralp)) { |
372 |
+ |
if (traset[0] >= MAXTSET) { |
373 |
+ |
error(WARNING, "too many modifiers in trace list"); |
374 |
+ |
hitlimit++; |
375 |
+ |
return; /* should this be fatal? */ |
376 |
+ |
} |
377 |
+ |
insertelem(traset, obj); |
378 |
+ |
return; |
379 |
+ |
} |
380 |
+ |
} |
381 |
+ |
|
382 |
+ |
|
383 |
|
static |
384 |
|
ourtrace(r) /* print ray values */ |
385 |
|
RAY *r; |
388 |
|
|
389 |
|
if (every_out[0] == NULL) |
390 |
|
return; |
391 |
+ |
if (r->ro == NULL) { |
392 |
+ |
if (traincl == 1) |
393 |
+ |
return; |
394 |
+ |
} else if (traincl != -1 && traincl != inset(traset, r->ro->omod)) |
395 |
+ |
return; |
396 |
|
tabin(r); |
397 |
|
for (tp = every_out; *tp != NULL; tp++) |
398 |
|
(**tp)(r); |
542 |
|
register RAY *r; |
543 |
|
{ |
544 |
|
if (r->ro != NULL) |
545 |
< |
fputs(objptr(r->ro->omod)->oname, stdout); |
545 |
> |
if (r->ro->omod != OVOID) |
546 |
> |
fputs(objptr(r->ro->omod)->oname, stdout); |
547 |
> |
else |
548 |
> |
fputs(VOIDID, stdout); |
549 |
|
else |
550 |
|
putchar('*'); |
551 |
|
putchar('\t'); |