9 |
|
*/ |
10 |
|
|
11 |
|
#include "ray.h" |
12 |
+ |
#include "platform.h" |
13 |
|
#include "source.h" |
14 |
|
#include "view.h" |
15 |
|
#include "random.h" |
16 |
|
|
17 |
|
#define DEGREE (PI/180.) |
18 |
|
|
19 |
< |
#define MAXNT 180 /* maximum number of theta divisions */ |
19 |
> |
#define MAXNT 181 /* maximum number of theta divisions */ |
20 |
|
#define MAXNP 360 /* maximum number of phi divisions */ |
21 |
|
|
22 |
|
extern char *progname; /* global argv[0] */ |
23 |
|
extern int nowarn; /* don't report warnings? */ |
24 |
|
|
25 |
|
/* current sensor's perspective */ |
26 |
< |
VIEW ourview = STDVIEW; |
26 |
> |
VIEW ourview = {VT_ANG,{0.,0.,0.},{0.,0.,1.},{1.,0.,0.}, |
27 |
> |
1.,180.,180.,0.,0.,0.,0., |
28 |
> |
{0.,0.,0.},{0.,0.,0.},0.,0.}; |
29 |
|
|
30 |
< |
unsigned long nsamps = 10000; /* desired number of initial samples */ |
28 |
< |
unsigned long nssamps = 9000; /* number of super-samples */ |
30 |
> |
long nsamps = 10000; /* desired number of initial samples */ |
31 |
|
int ndsamps = 32; /* number of direct samples */ |
32 |
|
int nprocs = 1; /* number of rendering processes */ |
33 |
|
|
34 |
|
float *sensor = NULL; /* current sensor data */ |
35 |
|
int sntp[2]; /* number of sensor theta and phi angles */ |
36 |
|
float maxtheta; /* maximum theta value for this sensor */ |
37 |
< |
float tvals[MAXNT+1]; /* theta values (1-D table of 1-cos(t)) */ |
38 |
< |
float *pvals = NULL; /* phi values (2-D table in radians) */ |
37 |
> |
float tvals[MAXNT+1]; /* theta prob. values (1-D table of 1-cos(t)) */ |
38 |
> |
float *pvals = NULL; /* phi prob. values (2-D table in radians) */ |
39 |
|
int ntheta = 0; /* polar angle divisions */ |
40 |
|
int nphi = 0; /* azimuthal angle divisions */ |
41 |
|
double gscale = 1.; /* global scaling value */ |
47 |
|
static void comp_sensor(char *sfile); |
48 |
|
|
49 |
|
static void |
50 |
< |
print_defaults() |
50 |
> |
over_options() /* overriding options */ |
51 |
|
{ |
52 |
+ |
directvis = (ndsamps <= 0); |
53 |
+ |
do_irrad = 0; |
54 |
+ |
} |
55 |
+ |
|
56 |
+ |
static void |
57 |
+ |
print_defaults() /* print out default parameters */ |
58 |
+ |
{ |
59 |
+ |
over_options(); |
60 |
|
printf("-n %-9d\t\t\t# number of processes\n", nprocs); |
61 |
|
printf("-rd %-9ld\t\t\t# ray directions\n", nsamps); |
52 |
– |
/* printf("-rs %-9ld\t\t\t# ray super-samples\n", nssamps); */ |
62 |
|
printf("-dn %-9d\t\t\t# direct number of samples\n", ndsamps); |
63 |
|
printf("-vp %f %f %f\t# view point\n", |
64 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
70 |
|
print_rdefaults(); |
71 |
|
} |
72 |
|
|
73 |
+ |
|
74 |
+ |
void |
75 |
+ |
quit(ec) /* make sure exit is called */ |
76 |
+ |
int ec; |
77 |
+ |
{ |
78 |
+ |
if (ray_pnprocs > 0) /* close children if any */ |
79 |
+ |
ray_pclose(0); |
80 |
+ |
else if (ray_pnprocs < 0) |
81 |
+ |
_exit(ec); /* avoid flush in child */ |
82 |
+ |
exit(ec); |
83 |
+ |
} |
84 |
+ |
|
85 |
+ |
|
86 |
|
int |
87 |
|
main( |
88 |
|
int argc, |
90 |
|
) |
91 |
|
{ |
92 |
|
int doheader = 1; |
93 |
+ |
int optwarn = 0; |
94 |
|
int i, rval; |
95 |
|
|
96 |
|
progname = argv[0]; |
97 |
|
/* set up rendering defaults */ |
98 |
|
rand_samp = 1; |
99 |
< |
dstrsrc = 0.5; |
99 |
> |
dstrsrc = 0.65; |
100 |
|
srcsizerat = 0.1; |
101 |
|
directrelay = 3; |
102 |
|
ambounce = 1; |
103 |
|
maxdepth = -10; |
81 |
– |
/* just asking defaults? */ |
82 |
– |
if (argc == 2 && !strcmp(argv[1], "-defaults")) { |
83 |
– |
print_defaults(); |
84 |
– |
return(0); |
85 |
– |
} |
86 |
– |
/* check octree */ |
87 |
– |
if (argc < 2 || argv[argc-1][0] == '-') |
88 |
– |
error(USER, "missing octree argument"); |
104 |
|
/* get options from command line */ |
105 |
< |
for (i = 1; i < argc-1; i++) { |
105 |
> |
for (i = 1; i < argc; i++) { |
106 |
|
while ((rval = expandarg(&argc, &argv, i)) > 0) |
107 |
|
; |
108 |
|
if (rval < 0) { |
109 |
|
sprintf(errmsg, "cannot expand '%s'", argv[i]); |
110 |
|
error(SYSTEM, errmsg); |
111 |
|
} |
112 |
< |
if (argv[i][0] != '-') { /* process a sensor file */ |
112 |
> |
if (argv[i][0] != '-') { |
113 |
> |
if (i >= argc-1) |
114 |
> |
break; /* final octree argument */ |
115 |
|
if (!ray_pnprocs) { |
116 |
< |
/* overriding options */ |
100 |
< |
directvis = (ndsamps <= 0); |
101 |
< |
do_irrad = 0; |
116 |
> |
over_options(); |
117 |
|
if (doheader) { /* print header */ |
118 |
+ |
newheader("RADIANCE", stdout); |
119 |
|
printargs(argc, argv, stdout); |
120 |
|
fputformat("ascii", stdout); |
121 |
|
putchar('\n'); |
122 |
|
} |
123 |
|
/* start process(es) */ |
124 |
< |
ray_pinit(argv[argc-1], nprocs); |
124 |
> |
if (strcmp(argv[argc-1], ".")) |
125 |
> |
ray_pinit(argv[argc-1], nprocs); |
126 |
|
} |
127 |
< |
comp_sensor(argv[i]); |
127 |
> |
comp_sensor(argv[i]); /* process a sensor file */ |
128 |
|
continue; |
129 |
|
} |
130 |
|
if (argv[i][1] == 'r') { /* sampling options */ |
131 |
|
if (argv[i][2] == 'd') |
132 |
|
nsamps = atol(argv[++i]); |
116 |
– |
else if (argv[i][2] == 's') |
117 |
– |
nssamps = atol(argv[++i]); |
133 |
|
else { |
134 |
|
sprintf(errmsg, "bad option at '%s'", argv[i]); |
135 |
|
error(USER, errmsg); |
165 |
|
sprintf(errmsg, "bad view option at '%s'", argv[i]); |
166 |
|
error(USER, errmsg); |
167 |
|
} |
168 |
< |
if (!strcmp(argv[i], "-w")) { /* turn off warnings */ |
169 |
< |
nowarn = 1; |
168 |
> |
if (!strcmp(argv[i], "-w")) { /* toggle warnings */ |
169 |
> |
nowarn = !nowarn; |
170 |
|
continue; |
171 |
|
} |
172 |
|
if (ray_pnprocs) { |
173 |
< |
error(WARNING, |
173 |
> |
if (!optwarn++) |
174 |
> |
error(WARNING, |
175 |
|
"rendering options should appear before first sensor"); |
176 |
|
} else if (!strcmp(argv[i], "-defaults")) { |
177 |
|
print_defaults(); |
194 |
|
} |
195 |
|
i += rval; |
196 |
|
} |
197 |
+ |
if (sensor == NULL) |
198 |
+ |
error(USER, i<argc ? "missing sensor file" : "missing octree"); |
199 |
|
quit(0); |
200 |
|
} |
201 |
|
|
206 |
|
char *sfile |
207 |
|
) |
208 |
|
{ |
209 |
+ |
int warnedneg; |
210 |
|
char linebuf[8192]; |
211 |
+ |
int last_pos_val = 0; |
212 |
|
int nelem = 1000; |
213 |
|
float *sarr = (float *)malloc(sizeof(float)*nelem); |
214 |
|
FILE *fp; |
236 |
|
cp = fskip(cp); |
237 |
|
if (cp == NULL) |
238 |
|
break; |
239 |
+ |
if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]+FTINY) { |
240 |
+ |
sprintf(errmsg, |
241 |
+ |
"Phi values not monotinically increasing in sensor file '%s'", |
242 |
+ |
sfile); |
243 |
+ |
error(USER, errmsg); |
244 |
+ |
} |
245 |
|
++ntp[1]; |
246 |
|
} |
247 |
+ |
warnedneg = 0; |
248 |
|
ntp[0] = 0; /* get thetas + data */ |
249 |
|
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) { |
250 |
|
++ntp[0]; |
262 |
|
cp = fskip(cp); |
263 |
|
if (cp == NULL) |
264 |
|
break; |
265 |
+ |
if (sarr[i] < .0) { |
266 |
+ |
if (!warnedneg++) { |
267 |
+ |
sprintf(errmsg, |
268 |
+ |
"Negative value(s) in sensor file '%s' (ignored)\n", sfile); |
269 |
+ |
error(WARNING, errmsg); |
270 |
+ |
} |
271 |
+ |
sarr[i] = .0; |
272 |
+ |
} else if (sarr[i] > FTINY && i > ntp[0]*(ntp[1]+1)) |
273 |
+ |
last_pos_val = i; |
274 |
|
++i; |
275 |
|
} |
276 |
< |
if (i == ntp[0]*(ntp[1]+1)) |
276 |
> |
if (i == ntp[0]*(ntp[1]+1)) /* empty line? */ |
277 |
|
break; |
278 |
+ |
if (ntp[0] > 1 && sarr[ntp[0]*(ntp[1]+1)] <= |
279 |
+ |
sarr[(ntp[0]-1)*(ntp[1]+1)]) { |
280 |
+ |
sprintf(errmsg, |
281 |
+ |
"Theta values not monotinically increasing in sensor file '%s'", |
282 |
+ |
sfile); |
283 |
+ |
error(USER, errmsg); |
284 |
+ |
} |
285 |
|
if (i != (ntp[0]+1)*(ntp[1]+1)) { |
286 |
|
sprintf(errmsg, |
287 |
|
"bad column count near line %d in sensor file '%s'", |
289 |
|
error(USER, errmsg); |
290 |
|
} |
291 |
|
} |
292 |
< |
nelem = i; |
292 |
> |
/* truncate zero region */ |
293 |
> |
ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1; |
294 |
> |
nelem = (ntp[0]+1)*(ntp[1]+1); |
295 |
|
fclose(fp); |
296 |
|
errmsg[0] = '\0'; /* sanity checks */ |
297 |
< |
if (ntp[0] <= 0) |
298 |
< |
sprintf(errmsg, "no data in sensor file '%s'", sfile); |
297 |
> |
if (!last_pos_val) |
298 |
> |
sprintf(errmsg, "no positive sensor values in file '%s'", sfile); |
299 |
|
else if (fabs(sarr[ntp[1]+1]) > FTINY) |
300 |
|
sprintf(errmsg, "minimum theta must be 0 in sensor file '%s'", |
301 |
|
sfile); |
302 |
|
else if (fabs(sarr[1]) > FTINY) |
303 |
|
sprintf(errmsg, "minimum phi must be 0 in sensor file '%s'", |
304 |
|
sfile); |
305 |
< |
else if (sarr[ntp[1]] <= FTINY) |
305 |
> |
else if (sarr[ntp[1]] < 270.-FTINY) |
306 |
|
sprintf(errmsg, |
307 |
< |
"maximum phi must be positive in sensor file '%s'", |
307 |
> |
"maximum phi must be 270 or greater in sensor file '%s'", |
308 |
|
sfile); |
309 |
< |
else if (sarr[ntp[0]*(ntp[1]+1)] <= FTINY) |
309 |
> |
else if (sarr[ntp[1]] >= 360.-FTINY) |
310 |
|
sprintf(errmsg, |
311 |
< |
"maximum theta must be positive in sensor file '%s'", |
311 |
> |
"maximum phi must be less than 360 in sensor file '%s'", |
312 |
|
sfile); |
313 |
|
if (errmsg[0]) |
314 |
|
error(USER, errmsg); |
321 |
|
char *sfile |
322 |
|
) |
323 |
|
{ |
324 |
< |
int samptot = nsamps; |
324 |
> |
long samptot = nsamps; |
325 |
|
float *rowp, *rowp1; |
326 |
|
double rowsum[MAXNT], rowomega[MAXNT]; |
327 |
|
double thdiv[MAXNT+1], phdiv[MAXNP+1]; |
353 |
|
error(INTERNAL, errmsg); |
354 |
|
} |
355 |
|
/* compute boundary angles */ |
356 |
< |
maxtheta = 1.5f*s_theta(sntp[0]-1) - 0.5f*s_theta(sntp[0]-2); |
356 |
> |
maxtheta = DEGREE*(1.5f*s_theta(sntp[0]-1) - 0.5f*s_theta(sntp[0]-2)); |
357 |
> |
if (maxtheta > PI) |
358 |
> |
maxtheta = PI; |
359 |
|
thdiv[0] = .0; |
360 |
|
for (t = 1; t < sntp[0]; t++) |
361 |
|
thdiv[t] = DEGREE/2.*(s_theta(t-1) + s_theta(t)); |
362 |
< |
thdiv[sntp[0]] = maxtheta*DEGREE; |
363 |
< |
phdiv[0] = .0; |
362 |
> |
thdiv[sntp[0]] = maxtheta; |
363 |
> |
phdiv[0] = DEGREE*(1.5f*s_phi(0) - 0.5f*s_phi(1)); |
364 |
|
for (p = 1; p < sntp[1]; p++) |
365 |
|
phdiv[p] = DEGREE/2.*(s_phi(p-1) + s_phi(p)); |
366 |
< |
phdiv[sntp[1]] = 2.*PI; |
366 |
> |
phdiv[sntp[1]] = DEGREE*(1.5f*s_phi(sntp[1]-1) - 0.5f*s_phi(sntp[1]-2)); |
367 |
|
/* size our table */ |
368 |
< |
tsize = 1. - cos(maxtheta*DEGREE); |
369 |
< |
psize = PI*tsize/(maxtheta*DEGREE); |
368 |
> |
tsize = 1. - cos(maxtheta); |
369 |
> |
psize = PI*tsize/maxtheta; |
370 |
|
if (sntp[0]*sntp[1] < samptot) /* don't overdo resolution */ |
371 |
|
samptot = sntp[0]*sntp[1]; |
372 |
< |
ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5); |
372 |
> |
ntheta = (int)(sqrt((double)samptot*tsize/psize)*sntp[0]/sntp[1]) + 1; |
373 |
|
if (ntheta > MAXNT) |
374 |
|
ntheta = MAXNT; |
375 |
|
nphi = samptot/ntheta; |
376 |
< |
pvals = (float *)malloc(sizeof(float)*ntheta*(nphi+1)); |
376 |
> |
pvals = (float *)malloc(sizeof(float)*(ntheta+1)*(nphi+1)); |
377 |
|
if (pvals == NULL) |
378 |
|
error(SYSTEM, "out of memory in init_ptable()"); |
379 |
|
gscale = .0; /* compute our inverse table */ |
380 |
|
for (i = 0; i < sntp[0]; i++) { |
381 |
|
rowp = &s_val(i,0); |
382 |
< |
rowsum[i] = 0.; |
382 |
> |
rowsum[i] = 1e-20; |
383 |
|
for (j = 0; j < sntp[1]; j++) |
384 |
|
rowsum[i] += *rowp++; |
385 |
|
rowomega[i] = cos(thdiv[i]) - cos(thdiv[i+1]); |
386 |
|
rowomega[i] *= 2.*PI / (double)sntp[1]; |
387 |
|
gscale += rowsum[i] * rowomega[i]; |
388 |
|
} |
389 |
+ |
if (gscale <= FTINY) { |
390 |
+ |
sprintf(errmsg, "Sensor values sum to zero in file '%s'", sfile); |
391 |
+ |
error(USER, errmsg); |
392 |
+ |
} |
393 |
|
for (i = 0; i < ntheta; i++) { |
394 |
|
prob = (double)i / (double)ntheta; |
395 |
|
for (t = 0; t < sntp[0]; t++) |
401 |
|
tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + |
402 |
|
frac*cos(thdiv[t+1]) ); |
403 |
|
/* offset b/c sensor values are centered */ |
404 |
< |
if (t <= 0 || frac > 0.5) |
404 |
> |
if ((t < sntp[0]-1) & (!t | (frac >= 0.5))) { |
405 |
|
frac -= 0.5; |
406 |
< |
else if (t >= sntp[0]-1 || frac < 0.5) { |
406 |
> |
} else { |
407 |
|
frac += 0.5; |
408 |
|
--t; |
409 |
|
} |
410 |
< |
pvals[i*(nphi+1)] = .0f; |
410 |
> |
pvals[i*(nphi+1)] = phdiv[0]; |
411 |
|
for (j = 1; j < nphi; j++) { |
412 |
|
prob = (double)j / (double)nphi; |
413 |
|
rowp = &s_val(t,0); |
414 |
|
rowp1 = &s_val(t+1,0); |
415 |
< |
for (p = 0; p < sntp[1]; p++) { |
415 |
> |
for (p = 0; p < sntp[1]; p++) |
416 |
|
if ((prob -= (1.-frac)*rowp[p]/rowsum[t] + |
417 |
|
frac*rowp1[p]/rowsum[t+1]) <= .0) |
418 |
|
break; |
419 |
< |
if (p >= sntp[1]) |
420 |
< |
error(INTERNAL, |
421 |
< |
"code error 2 in init_ptable()"); |
371 |
< |
frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t] |
372 |
< |
+ frac*rowp1[p]/rowsum[t+1]); |
373 |
< |
if (p <= 0 || frac1 > 0.5) |
374 |
< |
frac1 -= 0.5; |
375 |
< |
else if (p >= sntp[1]-1 || frac1 < 0.5) { |
376 |
< |
frac1 += 0.5; |
377 |
< |
--p; |
378 |
< |
} |
379 |
< |
pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] + |
380 |
< |
frac1*phdiv[p+1]; |
419 |
> |
if (p >= sntp[1]) { /* should never happen? */ |
420 |
> |
p = sntp[1] - 1; |
421 |
> |
prob = .5; |
422 |
|
} |
423 |
+ |
frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t] |
424 |
+ |
+ frac*rowp1[p]/rowsum[t+1]); |
425 |
+ |
pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] + |
426 |
+ |
frac1*phdiv[p+1]; |
427 |
|
} |
428 |
< |
pvals[i*(nphi+1) + nphi] = (float)(2.*PI); |
428 |
> |
pvals[i*(nphi+1) + nphi] = phdiv[sntp[1]]; |
429 |
|
} |
430 |
+ |
/* duplicate final row */ |
431 |
+ |
memcpy(pvals+ntheta*(nphi+1), pvals+(ntheta-1)*(nphi+1), |
432 |
+ |
sizeof(*pvals)*(nphi+1)); |
433 |
|
tvals[0] = .0f; |
434 |
|
tvals[ntheta] = (float)tsize; |
435 |
|
} |
476 |
|
int t, p; |
477 |
|
|
478 |
|
dv[2] = DOT(dvec, ourview.vdir); |
479 |
< |
theta = (float)((1./DEGREE) * acos(dv[2])); |
479 |
> |
theta = acos(dv[2]); |
480 |
|
if (theta >= maxtheta) |
481 |
|
return(.0f); |
482 |
|
dv[0] = DOT(dvec, ourview.hvec); |
483 |
|
dv[1] = DOT(dvec, ourview.vvec); |
484 |
< |
phi = (float)((1./DEGREE) * atan2(-dv[0], dv[1])); |
485 |
< |
while (phi < .0f) phi += 360.f; |
484 |
> |
phi = atan2(-dv[0], dv[1]); |
485 |
> |
while (phi < .0f) phi += (float)(2.*PI); |
486 |
|
t = (int)(theta/maxtheta * sntp[0]); |
487 |
< |
p = (int)(phi*(1./360.) * sntp[1]); |
487 |
> |
p = (int)(phi*(1./(2.*PI)) * sntp[1]); |
488 |
|
/* hack for non-uniform sensor grid */ |
489 |
+ |
theta *= (float)(1./DEGREE); |
490 |
+ |
phi *= (float)(1./DEGREE); |
491 |
|
while (t+1 < sntp[0] && theta >= s_theta(t+1)) |
492 |
|
++t; |
493 |
|
while (t-1 >= 0 && theta <= s_theta(t-1)) |
499 |
|
return(s_val(t,p)); |
500 |
|
} |
501 |
|
|
502 |
+ |
/* Print origin and direction */ |
503 |
+ |
static void |
504 |
+ |
print_ray( |
505 |
+ |
FVECT rorg, |
506 |
+ |
FVECT rdir |
507 |
+ |
) |
508 |
+ |
{ |
509 |
+ |
printf("%.6g %.6g %.6g %.8f %.8f %.8f\n", |
510 |
+ |
rorg[0], rorg[1], rorg[2], |
511 |
+ |
rdir[0], rdir[1], rdir[2]); |
512 |
+ |
} |
513 |
+ |
|
514 |
|
/* Compute sensor output */ |
515 |
|
static void |
516 |
|
comp_sensor( |
521 |
|
ndsamps > 0 ? 1 : 0; |
522 |
|
char *err; |
523 |
|
int nt, np; |
524 |
< |
COLOR vsum; |
524 |
> |
SCOLOR vsum; |
525 |
> |
COLOR cres; |
526 |
|
RAY rr; |
527 |
+ |
double sf; |
528 |
|
int i, j; |
529 |
|
/* set view */ |
530 |
|
ourview.type = VT_ANG; |
535 |
|
error(USER, err); |
536 |
|
/* assign probability table */ |
537 |
|
init_ptable(sfile); |
538 |
< |
/* do Monte Carlo sampling */ |
539 |
< |
setcolor(vsum, .0f, .0f, .0f); |
538 |
> |
/* stratified MC sampling */ |
539 |
> |
scolorblack(vsum); |
540 |
|
nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5); |
541 |
|
np = nsamps/nt; |
542 |
< |
VCOPY(rr.rorg, ourview.vp); |
479 |
< |
rr.rmax = .0; |
542 |
> |
sf = gscale/nsamps; |
543 |
|
for (i = 0; i < nt; i++) |
544 |
|
for (j = 0; j < np; j++) { |
545 |
+ |
VCOPY(rr.rorg, ourview.vp); |
546 |
|
get_direc(rr.rdir, (i+frandom())/nt, (j+frandom())/np); |
547 |
< |
rayorigin(&rr, PRIMARY, NULL, NULL); |
547 |
> |
if (ourview.vfore > FTINY) |
548 |
> |
VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore); |
549 |
> |
if (!ray_pnprocs) { |
550 |
> |
print_ray(rr.rorg, rr.rdir); |
551 |
> |
continue; |
552 |
> |
} |
553 |
> |
rr.rmax = .0; |
554 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
555 |
> |
scalescolor(rr.rcoef, sf); |
556 |
|
if (ray_pqueue(&rr) == 1) |
557 |
< |
addcolor(vsum, rr.rcol); |
557 |
> |
saddscolor(vsum, rr.rcol); |
558 |
|
} |
559 |
< |
/* finish MC calculation */ |
560 |
< |
while (ray_presult(&rr, 0) > 0) |
561 |
< |
addcolor(vsum, rr.rcol); |
562 |
< |
scalecolor(vsum, gscale/(nt*np)); |
563 |
< |
/* compute direct component */ |
559 |
> |
/* remaining rays pure MC */ |
560 |
> |
for (i = nsamps - nt*np; i-- > 0; ) { |
561 |
> |
VCOPY(rr.rorg, ourview.vp); |
562 |
> |
get_direc(rr.rdir, frandom(), frandom()); |
563 |
> |
if (ourview.vfore > FTINY) |
564 |
> |
VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore); |
565 |
> |
if (!ray_pnprocs) { |
566 |
> |
print_ray(rr.rorg, rr.rdir); |
567 |
> |
continue; |
568 |
> |
} |
569 |
> |
rr.rmax = .0; |
570 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
571 |
> |
scalescolor(rr.rcoef, sf); |
572 |
> |
if (ray_pqueue(&rr) == 1) |
573 |
> |
saddscolor(vsum, rr.rcol); |
574 |
> |
} |
575 |
> |
if (!ray_pnprocs) /* just printing rays */ |
576 |
> |
return; |
577 |
> |
/* scale partial result */ |
578 |
> |
scalescolor(vsum, sf); |
579 |
> |
/* add direct component */ |
580 |
|
for (i = ndirs; i-- > 0; ) { |
581 |
|
SRCINDEX si; |
582 |
|
initsrcindex(&si); |
583 |
|
while (srcray(&rr, NULL, &si)) { |
584 |
< |
double d = sens_val(rr.rdir); |
585 |
< |
if (d <= FTINY) |
584 |
> |
sf = sens_val(rr.rdir); |
585 |
> |
if (sf <= FTINY) |
586 |
|
continue; |
587 |
< |
d *= si.dom/ndirs; |
588 |
< |
scalecolor(rr.rcoef, d); |
587 |
> |
sf *= si.dom/ndirs; |
588 |
> |
scalescolor(rr.rcoef, sf); |
589 |
|
if (ray_pqueue(&rr) == 1) { |
590 |
< |
multcolor(rr.rcol, rr.rcoef); |
591 |
< |
addcolor(vsum, rr.rcol); |
590 |
> |
smultscolor(rr.rcol, rr.rcoef); |
591 |
> |
saddscolor(vsum, rr.rcol); |
592 |
|
} |
593 |
|
} |
594 |
|
} |
595 |
< |
/* finish direct calculation */ |
595 |
> |
/* finish our calculation */ |
596 |
|
while (ray_presult(&rr, 0) > 0) { |
597 |
< |
multcolor(rr.rcol, rr.rcoef); |
598 |
< |
addcolor(vsum, rr.rcol); |
597 |
> |
smultscolor(rr.rcol, rr.rcoef); |
598 |
> |
saddscolor(vsum, rr.rcol); |
599 |
|
} |
600 |
|
/* print our result */ |
601 |
< |
printf("%.4e %.4e %.4e\n", colval(vsum,RED), |
602 |
< |
colval(vsum,GRN), colval(vsum,BLU)); |
601 |
> |
scolor_rgb(cres, vsum); |
602 |
> |
printf("%.4e %.4e %.4e\n", colval(cres,RED), |
603 |
> |
colval(cres,GRN), colval(cres,BLU)); |
604 |
|
} |