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 |
|
|
37 |
|
|
38 |
|
extern int |
39 |
|
rayorigin( /* start new ray from old one */ |
40 |
< |
register RAY *r, |
40 |
< |
register RAY *ro, |
40 |
> |
RAY *r, |
41 |
|
int rt, |
42 |
< |
double rw |
42 |
> |
const RAY *ro, |
43 |
> |
const COLOR rc |
44 |
|
) |
45 |
|
{ |
46 |
< |
double re; |
47 |
< |
|
46 |
> |
double rw, re; |
47 |
> |
/* assign coefficient/weight */ |
48 |
> |
if (rc == NULL) { |
49 |
> |
rw = 1.0; |
50 |
> |
setcolor(r->rcoef, 1., 1., 1.); |
51 |
> |
} else { |
52 |
> |
rw = intens(rc); |
53 |
> |
if (rc != r->rcoef) |
54 |
> |
copycolor(r->rcoef, rc); |
55 |
> |
} |
56 |
|
if ((r->parent = ro) == NULL) { /* primary ray */ |
57 |
|
r->rlvl = 0; |
58 |
|
r->rweight = rw; |
64 |
|
copycolor(r->albedo, salbedo); |
65 |
|
r->gecc = seccg; |
66 |
|
r->slights = NULL; |
58 |
– |
} else if (ro->rot >= FHUGE) { /* illegal continuation */ |
59 |
– |
memset(r, 0, sizeof(RAY)); |
60 |
– |
return(-1); |
67 |
|
} else { /* spawned ray */ |
68 |
+ |
if (ro->rot >= FHUGE) { |
69 |
+ |
memset(r, 0, sizeof(RAY)); |
70 |
+ |
return(-1); /* illegal continuation */ |
71 |
+ |
} |
72 |
|
r->rlvl = ro->rlvl; |
73 |
|
if (rt & RAYREFL) { |
74 |
|
r->rlvl++; |
88 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
89 |
|
VCOPY(r->rorg, ro->rop); |
90 |
|
r->rweight = ro->rweight * rw; |
91 |
< |
/* estimate absorption */ |
91 |
> |
/* estimate extinction */ |
92 |
|
re = colval(ro->cext,RED) < colval(ro->cext,GRN) ? |
93 |
|
colval(ro->cext,RED) : colval(ro->cext,GRN); |
94 |
|
if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); |
95 |
< |
if (re > 0.) |
96 |
< |
r->rweight *= exp(-re*ro->rot); |
95 |
> |
re *= ro->rot; |
96 |
> |
if (re > .1) |
97 |
> |
r->rweight *= exp(-re); |
98 |
|
} |
99 |
|
rayclear(r); |
100 |
+ |
if (maxdepth <= 0 && rc != NULL) { /* Russian roulette */ |
101 |
+ |
if (minweight <= 0.0) |
102 |
+ |
error(USER, "zero ray weight in Russian roulette"); |
103 |
+ |
if (maxdepth < 0 && r->rlvl > -maxdepth) |
104 |
+ |
return(-1); /* upper reflection limit */ |
105 |
+ |
if (r->rweight >= minweight) |
106 |
+ |
return(0); |
107 |
+ |
if (frandom() < r->rweight/minweight) |
108 |
+ |
return(-1); |
109 |
+ |
rw = minweight/r->rweight; /* promote survivor */ |
110 |
+ |
scalecolor(r->rcoef, rw); |
111 |
+ |
r->rweight = minweight; |
112 |
+ |
return(0); |
113 |
+ |
} |
114 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
115 |
|
} |
116 |
|
|
147 |
|
} else if (sourcehit(r)) |
148 |
|
rayshade(r, r->ro->omod); /* distant source */ |
149 |
|
|
125 |
– |
rayparticipate(r); /* for participating medium */ |
126 |
– |
|
150 |
|
if (trace != NULL) |
151 |
|
(*trace)(r); /* trace execution */ |
152 |
+ |
|
153 |
+ |
rayparticipate(r); /* for participating medium */ |
154 |
|
} |
155 |
|
|
156 |
|
|
172 |
|
{ |
173 |
|
RAY tr; |
174 |
|
|
175 |
< |
if (rayorigin(&tr, r, TRANS, 1.0) == 0) { |
175 |
> |
if (rayorigin(&tr, TRANS, r, NULL) == 0) { |
176 |
|
VCOPY(tr.rdir, r->rdir); |
177 |
|
rayvalue(&tr); |
178 |
|
copycolor(r->rcol, tr.rcol); |
234 |
|
ge *= 1. - colval(r->albedo,GRN); |
235 |
|
be *= 1. - colval(r->albedo,BLU); |
236 |
|
} |
237 |
< |
setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re), |
238 |
< |
ge<=0. ? 1. : ge>92. ? 0. : exp(-ge), |
239 |
< |
be<=0. ? 1. : be>92. ? 0. : exp(-be)); |
240 |
< |
multcolor(r->rcol, ce); /* path absorption */ |
237 |
> |
setcolor(ce, re<=FTINY ? 1. : re>92. ? 0. : exp(-re), |
238 |
> |
ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge), |
239 |
> |
be<=FTINY ? 1. : be>92. ? 0. : exp(-be)); |
240 |
> |
multcolor(r->rcol, ce); /* path extinction */ |
241 |
|
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
242 |
|
return; /* no scattering */ |
243 |
|
setcolor(ca, |
330 |
|
|
331 |
|
extern double |
332 |
|
raydist( /* compute (cumulative) ray distance */ |
333 |
< |
register RAY *r, |
333 |
> |
register const RAY *r, |
334 |
|
register int flags |
335 |
|
) |
336 |
|
{ |
344 |
|
} |
345 |
|
|
346 |
|
|
347 |
+ |
extern void |
348 |
+ |
raycontrib( /* compute (cumulative) ray contribution */ |
349 |
+ |
COLOR rc, |
350 |
+ |
const RAY *r, |
351 |
+ |
int flags |
352 |
+ |
) |
353 |
+ |
{ |
354 |
+ |
COLOR eext, ext1; |
355 |
+ |
|
356 |
+ |
setcolor(eext, 0., 0., 0.); |
357 |
+ |
setcolor(rc, 1., 1., 1.); |
358 |
+ |
|
359 |
+ |
while (r != NULL && r->crtype&flags) { |
360 |
+ |
multcolor(rc, r->rcoef); |
361 |
+ |
copycolor(ext1, r->cext); |
362 |
+ |
scalecolor(ext1, r->rot); |
363 |
+ |
addcolor(eext, ext1); |
364 |
+ |
r = r->parent; |
365 |
+ |
} |
366 |
+ |
if (intens(eext) > FTINY) { |
367 |
+ |
setcolor(ext1, exp(-colval(eext,RED)), |
368 |
+ |
exp(-colval(eext,GRN)), |
369 |
+ |
exp(-colval(eext,BLU))); |
370 |
+ |
multcolor(rc, ext1); |
371 |
+ |
} |
372 |
+ |
} |
373 |
+ |
|
374 |
+ |
|
375 |
|
extern double |
376 |
|
raynormal( /* compute perturbed normal for ray */ |
377 |
|
FVECT norm, |
418 |
|
FULLXF xf; |
419 |
|
} xfseed = { &xfseed }, *xflast = &xfseed; |
420 |
|
register struct xfn *xp; |
421 |
< |
register RAY *rp; |
421 |
> |
register const RAY *rp; |
422 |
|
|
423 |
|
/* |
424 |
|
* Search for transform in circular list that |