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 |
|
|
97 |
|
r->rweight *= exp(-re); |
98 |
|
} |
99 |
|
rayclear(r); |
100 |
+ |
if (r->crtype & SHADOW) /* shadow commitment */ |
101 |
+ |
return(0); |
102 |
+ |
if (maxdepth <= 0 && rc != NULL) { /* Russian roulette */ |
103 |
+ |
if (minweight <= 0.0) |
104 |
+ |
error(USER, "zero ray weight in Russian roulette"); |
105 |
+ |
if (maxdepth < 0 && r->rlvl > -maxdepth) |
106 |
+ |
return(-1); /* upper reflection limit */ |
107 |
+ |
if (r->rweight >= minweight) |
108 |
+ |
return(0); |
109 |
+ |
if (frandom() < r->rweight/minweight) |
110 |
+ |
return(-1); |
111 |
+ |
rw = minweight/r->rweight; /* promote survivor */ |
112 |
+ |
scalecolor(r->rcoef, rw); |
113 |
+ |
r->rweight = minweight; |
114 |
+ |
return(0); |
115 |
+ |
} |
116 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
117 |
|
} |
118 |
|
|
348 |
|
|
349 |
|
extern void |
350 |
|
raycontrib( /* compute (cumulative) ray contribution */ |
351 |
< |
COLOR rc, |
351 |
> |
double rc[3], |
352 |
|
const RAY *r, |
353 |
|
int flags |
354 |
|
) |
355 |
|
{ |
356 |
< |
COLOR eext, ext1; |
357 |
< |
|
341 |
< |
setcolor(eext, 0., 0., 0.); |
342 |
< |
setcolor(rc, 1., 1., 1.); |
356 |
> |
double eext[3]; |
357 |
> |
int i; |
358 |
|
|
359 |
+ |
eext[0] = eext[1] = eext[2] = 0.; |
360 |
+ |
rc[0] = rc[1] = rc[2] = 1.; |
361 |
+ |
|
362 |
|
while (r != NULL && r->crtype&flags) { |
363 |
< |
multcolor(rc, r->rcoef); |
364 |
< |
copycolor(ext1, r->cext); |
365 |
< |
scalecolor(ext1, r->rot); |
366 |
< |
addcolor(eext, ext1); |
363 |
> |
for (i = 3; i--; ) { |
364 |
> |
rc[i] *= colval(r->rcoef,i); |
365 |
> |
eext[i] += r->rot * colval(r->cext,i); |
366 |
> |
} |
367 |
|
r = r->parent; |
368 |
|
} |
369 |
< |
if (intens(eext) > FTINY) { |
370 |
< |
setcolor(ext1, exp(-colval(eext,RED)), |
371 |
< |
exp(-colval(eext,GRN)), |
354 |
< |
exp(-colval(eext,BLU))); |
355 |
< |
multcolor(rc, ext1); |
356 |
< |
} |
369 |
> |
for (i = 3; i--; ) |
370 |
> |
rc[i] *= (eext[i] <= FTINY) ? 1. : |
371 |
> |
(eext[i] > 300.) ? 0. : exp(-eext[i]); |
372 |
|
} |
373 |
|
|
374 |
|
|