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 |
|
|
59 |
|
r->crtype = r->rtype = rt; |
60 |
|
r->rsrc = -1; |
61 |
|
r->clipset = NULL; |
62 |
+ |
r->revf = raytrace; |
63 |
|
copycolor(r->cext, cextinction); |
64 |
|
copycolor(r->albedo, salbedo); |
65 |
|
r->gecc = seccg; |
80 |
|
r->clipset = ro->newcset; |
81 |
|
r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot; |
82 |
|
} |
83 |
+ |
r->revf = ro->revf; |
84 |
|
copycolor(r->cext, ro->cext); |
85 |
|
copycolor(r->albedo, ro->albedo); |
86 |
|
r->gecc = ro->gecc; |
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 |
|
|
142 |
|
|
143 |
|
|
144 |
|
extern void |
145 |
< |
rayvalue( /* trace a ray and compute its value */ |
145 |
> |
raytrace( /* trace a ray and compute its value */ |
146 |
|
RAY *r |
147 |
|
) |
148 |
|
{ |
353 |
|
|
354 |
|
extern void |
355 |
|
raycontrib( /* compute (cumulative) ray contribution */ |
356 |
< |
COLOR rc, |
356 |
> |
double rc[3], |
357 |
|
const RAY *r, |
358 |
|
int flags |
359 |
|
) |
360 |
|
{ |
361 |
< |
COLOR eext, ext1; |
362 |
< |
|
339 |
< |
setcolor(eext, 0., 0., 0.); |
340 |
< |
setcolor(rc, 1., 1., 1.); |
361 |
> |
double eext[3]; |
362 |
> |
int i; |
363 |
|
|
364 |
+ |
eext[0] = eext[1] = eext[2] = 0.; |
365 |
+ |
rc[0] = rc[1] = rc[2] = 1.; |
366 |
+ |
|
367 |
|
while (r != NULL && r->crtype&flags) { |
368 |
< |
multcolor(rc, r->rcoef); |
369 |
< |
copycolor(ext1, r->cext); |
370 |
< |
scalecolor(ext1, r->rot); |
371 |
< |
addcolor(eext, ext1); |
368 |
> |
for (i = 3; i--; ) { |
369 |
> |
rc[i] *= colval(r->rcoef,i); |
370 |
> |
eext[i] += r->rot * colval(r->cext,i); |
371 |
> |
} |
372 |
|
r = r->parent; |
373 |
|
} |
374 |
< |
if (intens(eext) > FTINY) { |
375 |
< |
setcolor(ext1, exp(-colval(eext,RED)), |
376 |
< |
exp(-colval(eext,GRN)), |
352 |
< |
exp(-colval(eext,BLU))); |
353 |
< |
multcolor(rc, ext1); |
354 |
< |
} |
374 |
> |
for (i = 3; i--; ) |
375 |
> |
rc[i] *= (eext[i] <= FTINY) ? 1. : |
376 |
> |
(eext[i] > 92.) ? 0. : exp(-eext[i]); |
377 |
|
} |
378 |
|
|
379 |
|
|