13 |
|
#include "source.h" |
14 |
|
#include "otypes.h" |
15 |
|
#include "otspecial.h" |
16 |
+ |
#include "random.h" |
17 |
|
|
18 |
|
#define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ |
19 |
|
|
93 |
|
colval(ro->cext,RED) : colval(ro->cext,GRN); |
94 |
|
if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); |
95 |
|
re *= ro->rot; |
96 |
< |
if (re > .1) |
97 |
< |
r->rweight *= exp(-re); |
96 |
> |
if (re > 0.1) |
97 |
> |
if (re > 92.) |
98 |
> |
r->rweight = 0.0; |
99 |
> |
else |
100 |
> |
r->rweight *= exp(-re); |
101 |
|
} |
102 |
|
rayclear(r); |
103 |
+ |
if (r->rweight <= 0.0) /* check for expiration */ |
104 |
+ |
return(-1); |
105 |
+ |
if (r->crtype & SHADOW) /* shadow commitment */ |
106 |
+ |
return(0); |
107 |
+ |
if (maxdepth <= 0 && rc != NULL) { /* Russian roulette */ |
108 |
+ |
if (minweight <= 0.0) |
109 |
+ |
error(USER, "zero ray weight in Russian roulette"); |
110 |
+ |
if (maxdepth < 0 && r->rlvl > -maxdepth) |
111 |
+ |
return(-1); /* upper reflection limit */ |
112 |
+ |
if (r->rweight >= minweight) |
113 |
+ |
return(0); |
114 |
+ |
if (frandom() < r->rweight/minweight) |
115 |
+ |
return(-1); |
116 |
+ |
rw = minweight/r->rweight; /* promote survivor */ |
117 |
+ |
scalecolor(r->rcoef, rw); |
118 |
+ |
r->rweight = minweight; |
119 |
+ |
return(0); |
120 |
+ |
} |
121 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
122 |
|
} |
123 |
|
|
301 |
|
foremat = backmat = 0; |
302 |
|
/* foreground */ |
303 |
|
fr = *r; |
304 |
< |
if (coef > FTINY) |
304 |
> |
if (coef > FTINY) { |
305 |
> |
scalecolor(fr.rcoef, coef); |
306 |
|
foremat = rayshade(&fr, fore); |
307 |
+ |
} |
308 |
|
/* background */ |
309 |
|
br = *r; |
310 |
< |
if (coef < 1.0-FTINY) |
310 |
> |
if (coef < 1.0-FTINY) { |
311 |
> |
scalecolor(br.rcoef, 1.0-coef); |
312 |
|
backmat = rayshade(&br, back); |
313 |
+ |
} |
314 |
|
/* check for transparency */ |
315 |
|
if (backmat ^ foremat) { |
316 |
|
if (backmat && coef > FTINY) |
357 |
|
|
358 |
|
extern void |
359 |
|
raycontrib( /* compute (cumulative) ray contribution */ |
360 |
< |
COLOR rc, |
360 |
> |
double rc[3], |
361 |
|
const RAY *r, |
362 |
|
int flags |
363 |
|
) |
364 |
|
{ |
365 |
< |
COLOR eext, ext1; |
366 |
< |
|
341 |
< |
setcolor(eext, 0., 0., 0.); |
342 |
< |
setcolor(rc, 1., 1., 1.); |
365 |
> |
double eext[3]; |
366 |
> |
int i; |
367 |
|
|
368 |
+ |
eext[0] = eext[1] = eext[2] = 0.; |
369 |
+ |
rc[0] = rc[1] = rc[2] = 1.; |
370 |
+ |
|
371 |
|
while (r != NULL && r->crtype&flags) { |
372 |
< |
multcolor(rc, r->rcoef); |
373 |
< |
copycolor(ext1, r->cext); |
374 |
< |
scalecolor(ext1, r->rot); |
375 |
< |
addcolor(eext, ext1); |
372 |
> |
for (i = 3; i--; ) { |
373 |
> |
rc[i] *= colval(r->rcoef,i); |
374 |
> |
eext[i] += r->rot * colval(r->cext,i); |
375 |
> |
} |
376 |
|
r = r->parent; |
377 |
|
} |
378 |
< |
if (intens(eext) > FTINY) { |
379 |
< |
setcolor(ext1, exp(-colval(eext,RED)), |
380 |
< |
exp(-colval(eext,GRN)), |
354 |
< |
exp(-colval(eext,BLU))); |
355 |
< |
multcolor(rc, ext1); |
356 |
< |
} |
378 |
> |
for (i = 3; i--; ) |
379 |
> |
rc[i] *= (eext[i] <= FTINY) ? 1. : |
380 |
> |
(eext[i] > 92.) ? 0. : exp(-eext[i]); |
381 |
|
} |
382 |
|
|
383 |
|
|