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 '-oi' or '-oI' options indicate that |
23 |
> |
* radiance is computed. The '-i' or '-I' options indicate that |
24 |
|
* irradiance values are desired. |
25 |
|
*/ |
26 |
|
|
30 |
|
|
31 |
|
#include "otypes.h" |
32 |
|
|
33 |
+ |
int dimlist[MAXDIM]; /* sampling dimensions */ |
34 |
+ |
int ndims = 0; /* number of sampling dimensions */ |
35 |
+ |
int samplendx = 0; /* index for this sample */ |
36 |
+ |
|
37 |
+ |
int imm_irrad = 0; /* compute immediate irradiance? */ |
38 |
+ |
|
39 |
|
int inform = 'a'; /* input format */ |
40 |
|
int outform = 'a'; /* output format */ |
41 |
|
char *outvals = "v"; /* output specification */ |
46 |
|
double dstrsrc = 0.0; /* square source distribution */ |
47 |
|
double shadthresh = .05; /* shadow threshold */ |
48 |
|
double shadcert = .5; /* shadow certainty */ |
49 |
+ |
int directrelay = 1; /* number of source relays */ |
50 |
+ |
int vspretest = 512; /* virtual source pretest density */ |
51 |
+ |
int directinvis = 0; /* sources invisible? */ |
52 |
+ |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
53 |
|
|
54 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
55 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
56 |
+ |
|
57 |
|
int maxdepth = 6; /* maximum recursion depth */ |
58 |
|
double minweight = 4e-3; /* minimum ray weight */ |
59 |
|
|
66 |
|
char *amblist[128]; /* ambient include/exclude list */ |
67 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
68 |
|
|
69 |
+ |
extern OBJREC Lamb; /* a Lambertian surface */ |
70 |
+ |
|
71 |
|
static RAY thisray; /* for our convenience */ |
72 |
|
|
73 |
< |
static int oputo(), oputd(), oputv(), oputl(), |
73 |
> |
static int oputo(), oputd(), oputv(), oputl(), oputL(), |
74 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
75 |
|
|
76 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
80 |
|
|
81 |
|
static int (*putreal)(); |
82 |
|
|
68 |
– |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
69 |
– |
static OBJREC Lamb = { |
70 |
– |
OVOID, MAT_PLASTIC, "Lambertian", |
71 |
– |
{0, 5, NULL, Lambfa}, NULL, -1, |
72 |
– |
}; /* a Lambertian surface */ |
83 |
|
|
74 |
– |
|
84 |
|
quit(code) /* quit program */ |
85 |
|
int code; |
86 |
|
{ |
117 |
|
fflush(stdout); |
118 |
|
continue; |
119 |
|
} |
120 |
+ |
samplendx++; |
121 |
|
/* compute and print */ |
122 |
< |
if (outvals[0] == 'i') |
122 |
> |
if (imm_irrad) |
123 |
|
irrad(orig, direc); |
114 |
– |
else if (outvals[0] == 'I') |
115 |
– |
Irrad(orig, direc); |
124 |
|
else |
125 |
< |
radiance(orig, direc); |
125 |
> |
traceray(orig, direc); |
126 |
|
/* flush if time */ |
127 |
|
if (--nextflush == 0) { |
128 |
|
fflush(stdout); |
164 |
|
*table++ = oputv; |
165 |
|
castonly = 0; |
166 |
|
break; |
167 |
< |
case 'l': /* length */ |
167 |
> |
case 'l': /* effective distance */ |
168 |
|
*table++ = oputl; |
169 |
|
castonly = 0; |
170 |
|
break; |
171 |
+ |
case 'L': /* single ray length */ |
172 |
+ |
*table++ = oputL; |
173 |
+ |
break; |
174 |
|
case 'p': /* point */ |
175 |
|
*table++ = oputp; |
176 |
|
break; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
< |
radiance(org, dir) /* compute radiance value */ |
194 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
195 |
|
FVECT org, dir; |
196 |
|
{ |
197 |
|
register int (**tp)(); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
< |
irrad(org, dir) /* compute irradiance value */ |
216 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
217 |
|
FVECT org, dir; |
218 |
|
{ |
219 |
|
register int i; |
237 |
|
} |
238 |
|
|
239 |
|
|
229 |
– |
Irrad(org, dir) /* compute irradiance value after intersection */ |
230 |
– |
FVECT org, dir; |
231 |
– |
{ |
232 |
– |
/* compute intersection */ |
233 |
– |
VCOPY(thisray.rorg, org); |
234 |
– |
VCOPY(thisray.rdir, dir); |
235 |
– |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
236 |
– |
localhit(&thisray, &thescene); |
237 |
– |
if (thisray.ro != NULL) /* pretend we hit Lambertian surf. */ |
238 |
– |
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
239 |
– |
oputv(&thisray); |
240 |
– |
if (outform == 'a') |
241 |
– |
putchar('\n'); |
242 |
– |
} |
243 |
– |
|
244 |
– |
|
240 |
|
getvec(vec, fmt, fp) /* get a vector from fp */ |
241 |
|
register FVECT vec; |
242 |
|
int fmt; |
243 |
|
FILE *fp; |
244 |
|
{ |
245 |
+ |
extern char *fgetword(); |
246 |
|
static float vf[3]; |
247 |
+ |
static double vd[3]; |
248 |
+ |
char buf[32]; |
249 |
+ |
register int i; |
250 |
|
|
251 |
|
switch (fmt) { |
252 |
|
case 'a': /* ascii */ |
253 |
< |
if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3) |
254 |
< |
return(-1); |
253 |
> |
for (i = 0; i < 3; i++) { |
254 |
> |
if (fgetword(buf, sizeof(buf), fp) == NULL || |
255 |
> |
!isflt(buf)) |
256 |
> |
return(-1); |
257 |
> |
vec[i] = atof(buf); |
258 |
> |
} |
259 |
|
break; |
260 |
|
case 'f': /* binary float */ |
261 |
|
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
263 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
264 |
|
break; |
265 |
|
case 'd': /* binary double */ |
266 |
< |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
266 |
> |
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
267 |
|
return(-1); |
268 |
+ |
vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2]; |
269 |
|
break; |
270 |
|
} |
271 |
|
return(0); |
329 |
|
|
330 |
|
|
331 |
|
static |
332 |
< |
oputl(r) /* print length */ |
332 |
> |
oputl(r) /* print effective distance */ |
333 |
|
register RAY *r; |
334 |
|
{ |
335 |
|
(*putreal)(r->rt); |
336 |
+ |
} |
337 |
+ |
|
338 |
+ |
|
339 |
+ |
static |
340 |
+ |
oputL(r) /* print single ray length */ |
341 |
+ |
register RAY *r; |
342 |
+ |
{ |
343 |
+ |
(*putreal)(r->rot); |
344 |
|
} |
345 |
|
|
346 |
|
|