1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
16 |
|
* xorg yorg zorg xdir ydir zdir |
17 |
|
* |
18 |
|
* The direction need not be normalized. Output is flexible. |
19 |
+ |
* If the direction vector is (0,0,0), then the output is flushed. |
20 |
|
* All values default to ascii representation of real |
21 |
|
* numbers. Binary representations can be selected |
22 |
|
* with '-ff' for float or '-fd' for double. By default, |
23 |
< |
* radiance is computed. The '-i' option indicates that |
23 |
> |
* radiance is computed. The '-i' or '-I' options indicate that |
24 |
|
* irradiance values are desired. |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "ray.h" |
28 |
|
|
29 |
+ |
#include "octree.h" |
30 |
+ |
|
31 |
|
#include "otypes.h" |
32 |
|
|
33 |
+ |
#include "resolu.h" |
34 |
+ |
|
35 |
+ |
int dimlist[MAXDIM]; /* sampling dimensions */ |
36 |
+ |
int ndims = 0; /* number of sampling dimensions */ |
37 |
+ |
int samplendx = 0; /* index for this sample */ |
38 |
+ |
|
39 |
+ |
int imm_irrad = 0; /* compute immediate irradiance? */ |
40 |
+ |
|
41 |
|
int inform = 'a'; /* input format */ |
42 |
|
int outform = 'a'; /* output format */ |
43 |
|
char *outvals = "v"; /* output specification */ |
48 |
|
double dstrsrc = 0.0; /* square source distribution */ |
49 |
|
double shadthresh = .05; /* shadow threshold */ |
50 |
|
double shadcert = .5; /* shadow certainty */ |
51 |
+ |
int directrelay = 1; /* number of source relays */ |
52 |
+ |
int vspretest = 512; /* virtual source pretest density */ |
53 |
+ |
int directvis = 1; /* sources visible? */ |
54 |
+ |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
55 |
|
|
56 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
57 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
58 |
+ |
|
59 |
|
int maxdepth = 6; /* maximum recursion depth */ |
60 |
|
double minweight = 4e-3; /* minimum ray weight */ |
61 |
|
|
62 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
63 |
|
double ambacc = 0.2; /* ambient accuracy */ |
64 |
< |
int ambres = 128; /* ambient resolution */ |
64 |
> |
int ambres = 32; /* ambient resolution */ |
65 |
|
int ambdiv = 128; /* ambient divisions */ |
66 |
|
int ambssamp = 0; /* ambient super-samples */ |
67 |
|
int ambounce = 0; /* ambient bounces */ |
68 |
|
char *amblist[128]; /* ambient include/exclude list */ |
69 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
70 |
|
|
71 |
+ |
extern OBJREC Lamb; /* a Lambertian surface */ |
72 |
+ |
|
73 |
|
static RAY thisray; /* for our convenience */ |
74 |
|
|
75 |
< |
extern int oputo(), oputd(), oputv(), oputl(), |
76 |
< |
oputp(), oputn(), oputs(), oputw(), oputm(); |
75 |
> |
static int oputo(), oputd(), oputv(), oputl(), oputL(), |
76 |
> |
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
77 |
|
|
78 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
79 |
+ |
static int castonly; |
80 |
|
|
81 |
< |
extern int puta(), putf(), putd(); |
81 |
> |
static int puta(), putf(), putd(); |
82 |
|
|
83 |
|
static int (*putreal)(); |
84 |
|
|
86 |
|
quit(code) /* quit program */ |
87 |
|
int code; |
88 |
|
{ |
89 |
+ |
#ifndef NIX |
90 |
+ |
headclean(); /* delete header file */ |
91 |
+ |
pfclean(); /* clean up persist files */ |
92 |
+ |
#endif |
93 |
|
exit(code); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
+ |
char * |
98 |
+ |
formstr(f) /* return format identifier */ |
99 |
+ |
int f; |
100 |
+ |
{ |
101 |
+ |
switch (f) { |
102 |
+ |
case 'a': return("ascii"); |
103 |
+ |
case 'f': return("float"); |
104 |
+ |
case 'd': return("double"); |
105 |
+ |
case 'c': return(COLRFMT); |
106 |
+ |
} |
107 |
+ |
return("unknown"); |
108 |
+ |
} |
109 |
+ |
|
110 |
+ |
|
111 |
|
rtrace(fname) /* trace rays from file */ |
112 |
|
char *fname; |
113 |
|
{ |
122 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
123 |
|
error(SYSTEM, errmsg); |
124 |
|
} |
125 |
+ |
#ifdef MSDOS |
126 |
+ |
if (inform != 'a') |
127 |
+ |
setmode(fileno(fp), O_BINARY); |
128 |
+ |
#endif |
129 |
|
/* set up output */ |
130 |
|
setoutput(outvals); |
131 |
|
switch (outform) { |
132 |
|
case 'a': putreal = puta; break; |
133 |
|
case 'f': putreal = putf; break; |
134 |
|
case 'd': putreal = putd; break; |
135 |
+ |
case 'c': |
136 |
+ |
if (strcmp(outvals, "v")) |
137 |
+ |
error(USER, "color format with value output only"); |
138 |
+ |
break; |
139 |
+ |
default: |
140 |
+ |
error(CONSISTENCY, "botched output format"); |
141 |
|
} |
142 |
+ |
if (hresolu > 0 && vresolu > 0) |
143 |
+ |
fprtresolu(hresolu, vresolu, stdout); |
144 |
|
/* process file */ |
145 |
|
while (getvec(orig, inform, fp) == 0 && |
146 |
|
getvec(direc, inform, fp) == 0) { |
147 |
|
|
148 |
< |
if (normalize(direc) == 0.0) |
149 |
< |
error(USER, "zero direction vector"); |
148 |
> |
if (normalize(direc) == 0.0) { /* zero ==> flush */ |
149 |
> |
fflush(stdout); |
150 |
> |
continue; |
151 |
> |
} |
152 |
> |
samplendx++; |
153 |
|
/* compute and print */ |
154 |
< |
if (outvals[0] == 'i') |
154 |
> |
if (imm_irrad) |
155 |
|
irrad(orig, direc); |
156 |
|
else |
157 |
< |
radiance(orig, direc); |
158 |
< |
/* flush if requested */ |
157 |
> |
traceray(orig, direc); |
158 |
> |
/* flush if time */ |
159 |
|
if (--nextflush == 0) { |
160 |
|
fflush(stdout); |
161 |
|
nextflush = hresolu; |
177 |
|
extern int ourtrace(), (*trace)(); |
178 |
|
register int (**table)() = ray_out; |
179 |
|
|
180 |
+ |
castonly = 1; |
181 |
|
while (*vs) |
182 |
|
switch (*vs++) { |
183 |
|
case 't': /* trace */ |
184 |
|
*table = NULL; |
185 |
|
table = every_out; |
186 |
|
trace = ourtrace; |
187 |
+ |
castonly = 0; |
188 |
|
break; |
189 |
|
case 'o': /* origin */ |
190 |
|
*table++ = oputo; |
194 |
|
break; |
195 |
|
case 'v': /* value */ |
196 |
|
*table++ = oputv; |
197 |
+ |
castonly = 0; |
198 |
|
break; |
199 |
< |
case 'l': /* length */ |
199 |
> |
case 'l': /* effective distance */ |
200 |
|
*table++ = oputl; |
201 |
+ |
castonly = 0; |
202 |
|
break; |
203 |
+ |
case 'L': /* single ray length */ |
204 |
+ |
*table++ = oputL; |
205 |
+ |
break; |
206 |
|
case 'p': /* point */ |
207 |
|
*table++ = oputp; |
208 |
|
break; |
209 |
< |
case 'n': /* normal */ |
209 |
> |
case 'n': /* perturbed normal */ |
210 |
|
*table++ = oputn; |
211 |
+ |
castonly = 0; |
212 |
|
break; |
213 |
+ |
case 'N': /* unperturbed normal */ |
214 |
+ |
*table++ = oputN; |
215 |
+ |
break; |
216 |
|
case 's': /* surface */ |
217 |
|
*table++ = oputs; |
218 |
|
break; |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
< |
radiance(org, dir) /* compute radiance value */ |
230 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
231 |
|
FVECT org, dir; |
232 |
|
{ |
233 |
|
register int (**tp)(); |
235 |
|
VCOPY(thisray.rorg, org); |
236 |
|
VCOPY(thisray.rdir, dir); |
237 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
238 |
< |
rayvalue(&thisray); |
238 |
> |
if (castonly) |
239 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
240 |
> |
else |
241 |
> |
rayvalue(&thisray); |
242 |
|
|
243 |
|
if (ray_out[0] == NULL) |
244 |
|
return; |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
< |
irrad(org, dir) /* compute irradiance value */ |
252 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
253 |
|
FVECT org, dir; |
254 |
|
{ |
187 |
– |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
188 |
– |
static OBJREC Lamb = { |
189 |
– |
OVOID, MAT_PLASTIC, "Lambertian", |
190 |
– |
{0, 5, NULL, Lambfa}, NULL, -1, |
191 |
– |
}; |
255 |
|
register int i; |
256 |
|
|
257 |
|
for (i = 0; i < 3; i++) { |
278 |
|
int fmt; |
279 |
|
FILE *fp; |
280 |
|
{ |
281 |
+ |
extern char *fgetword(); |
282 |
|
static float vf[3]; |
283 |
+ |
static double vd[3]; |
284 |
+ |
char buf[32]; |
285 |
+ |
register int i; |
286 |
|
|
287 |
|
switch (fmt) { |
288 |
|
case 'a': /* ascii */ |
289 |
< |
if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3) |
290 |
< |
return(-1); |
289 |
> |
for (i = 0; i < 3; i++) { |
290 |
> |
if (fgetword(buf, sizeof(buf), fp) == NULL || |
291 |
> |
!isflt(buf)) |
292 |
> |
return(-1); |
293 |
> |
vec[i] = atof(buf); |
294 |
> |
} |
295 |
|
break; |
296 |
|
case 'f': /* binary float */ |
297 |
< |
if (fread(vf, sizeof(float), 3, fp) != 3) |
297 |
> |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
298 |
|
return(-1); |
299 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
300 |
|
break; |
301 |
|
case 'd': /* binary double */ |
302 |
< |
if (fread(vec, sizeof(double), 3, fp) != 3) |
302 |
> |
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
303 |
|
return(-1); |
304 |
+ |
vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2]; |
305 |
|
break; |
306 |
+ |
default: |
307 |
+ |
error(CONSISTENCY, "botched input format"); |
308 |
|
} |
309 |
|
return(0); |
310 |
|
} |
360 |
|
oputv(r) /* print value */ |
361 |
|
register RAY *r; |
362 |
|
{ |
363 |
+ |
COLR cout; |
364 |
+ |
|
365 |
+ |
if (outform == 'c') { |
366 |
+ |
setcolr(cout, colval(r->rcol,RED), |
367 |
+ |
colval(r->rcol,GRN), |
368 |
+ |
colval(r->rcol,BLU)); |
369 |
+ |
fwrite((char *)cout, sizeof(cout), 1, stdout); |
370 |
+ |
return; |
371 |
+ |
} |
372 |
|
(*putreal)(colval(r->rcol,RED)); |
373 |
|
(*putreal)(colval(r->rcol,GRN)); |
374 |
|
(*putreal)(colval(r->rcol,BLU)); |
376 |
|
|
377 |
|
|
378 |
|
static |
379 |
< |
oputl(r) /* print length */ |
379 |
> |
oputl(r) /* print effective distance */ |
380 |
|
register RAY *r; |
381 |
|
{ |
382 |
< |
if (r->rot < FHUGE) |
300 |
< |
(*putreal)(r->rot); |
301 |
< |
else |
302 |
< |
(*putreal)(0.0); |
382 |
> |
(*putreal)(r->rt); |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
|
static |
387 |
+ |
oputL(r) /* print single ray length */ |
388 |
+ |
register RAY *r; |
389 |
+ |
{ |
390 |
+ |
(*putreal)(r->rot); |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
|
394 |
+ |
static |
395 |
|
oputp(r) /* print point */ |
396 |
|
register RAY *r; |
397 |
|
{ |
408 |
|
|
409 |
|
|
410 |
|
static |
411 |
< |
oputn(r) /* print normal */ |
411 |
> |
oputN(r) /* print unperturbed normal */ |
412 |
|
register RAY *r; |
413 |
|
{ |
414 |
|
if (r->rot < FHUGE) { |
424 |
|
|
425 |
|
|
426 |
|
static |
427 |
+ |
oputn(r) /* print perturbed normal */ |
428 |
+ |
RAY *r; |
429 |
+ |
{ |
430 |
+ |
FVECT pnorm; |
431 |
+ |
|
432 |
+ |
if (r->rot >= FHUGE) { |
433 |
+ |
(*putreal)(0.0); |
434 |
+ |
(*putreal)(0.0); |
435 |
+ |
(*putreal)(0.0); |
436 |
+ |
return; |
437 |
+ |
} |
438 |
+ |
raynormal(pnorm, r); |
439 |
+ |
(*putreal)(pnorm[0]); |
440 |
+ |
(*putreal)(pnorm[1]); |
441 |
+ |
(*putreal)(pnorm[2]); |
442 |
+ |
} |
443 |
+ |
|
444 |
+ |
|
445 |
+ |
static |
446 |
|
oputs(r) /* print name */ |
447 |
|
register RAY *r; |
448 |
|
{ |
486 |
|
putd(v) /* print binary double */ |
487 |
|
double v; |
488 |
|
{ |
489 |
< |
fwrite(&v, sizeof(v), 1, stdout); |
489 |
> |
fwrite((char *)&v, sizeof(v), 1, stdout); |
490 |
|
} |
491 |
|
|
492 |
|
|
496 |
|
{ |
497 |
|
float f = v; |
498 |
|
|
499 |
< |
fwrite(&f, sizeof(f), 1, stdout); |
499 |
> |
fwrite((char *)&f, sizeof(f), 1, stdout); |
500 |
|
} |