36 |
|
|
37 |
|
extern int |
38 |
|
rayorigin( /* start new ray from old one */ |
39 |
< |
register RAY *r, |
40 |
< |
register RAY *ro, |
39 |
> |
RAY *r, |
40 |
|
int rt, |
41 |
< |
double rw |
41 |
> |
const RAY *ro, |
42 |
> |
const COLOR rc |
43 |
|
) |
44 |
|
{ |
45 |
< |
double re; |
46 |
< |
|
45 |
> |
double rw, re; |
46 |
> |
/* assign coefficient/weight */ |
47 |
> |
if (rc == NULL) { |
48 |
> |
rw = 1.0; |
49 |
> |
setcolor(r->rcoef, 1., 1., 1.); |
50 |
> |
} else { |
51 |
> |
rw = intens(rc); |
52 |
> |
if (rc != r->rcoef) |
53 |
> |
copycolor(r->rcoef, rc); |
54 |
> |
} |
55 |
|
if ((r->parent = ro) == NULL) { /* primary ray */ |
56 |
|
r->rlvl = 0; |
57 |
|
r->rweight = rw; |
62 |
|
copycolor(r->albedo, salbedo); |
63 |
|
r->gecc = seccg; |
64 |
|
r->slights = NULL; |
57 |
– |
} else if (ro->rot >= FHUGE) { /* illegal continuation */ |
58 |
– |
memset(r, 0, sizeof(RAY)); |
59 |
– |
return(-1); |
65 |
|
} else { /* spawned ray */ |
66 |
+ |
if (ro->rot >= FHUGE) { |
67 |
+ |
memset(r, 0, sizeof(RAY)); |
68 |
+ |
return(-1); /* illegal continuation */ |
69 |
+ |
} |
70 |
|
r->rlvl = ro->rlvl; |
71 |
|
if (rt & RAYREFL) { |
72 |
|
r->rlvl++; |
85 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
86 |
|
VCOPY(r->rorg, ro->rop); |
87 |
|
r->rweight = ro->rweight * rw; |
88 |
< |
/* estimate absorption */ |
88 |
> |
/* estimate extinction */ |
89 |
|
re = colval(ro->cext,RED) < colval(ro->cext,GRN) ? |
90 |
|
colval(ro->cext,RED) : colval(ro->cext,GRN); |
91 |
|
if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); |
92 |
< |
if (re > 0.) |
93 |
< |
r->rweight *= exp(-re*ro->rot); |
92 |
> |
re *= ro->rot; |
93 |
> |
if (re > .1) |
94 |
> |
r->rweight *= exp(-re); |
95 |
|
} |
96 |
|
rayclear(r); |
97 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
130 |
|
} else if (sourcehit(r)) |
131 |
|
rayshade(r, r->ro->omod); /* distant source */ |
132 |
|
|
123 |
– |
rayparticipate(r); /* for participating medium */ |
124 |
– |
|
133 |
|
if (trace != NULL) |
134 |
|
(*trace)(r); /* trace execution */ |
135 |
+ |
|
136 |
+ |
rayparticipate(r); /* for participating medium */ |
137 |
|
} |
138 |
|
|
139 |
|
|
155 |
|
{ |
156 |
|
RAY tr; |
157 |
|
|
158 |
< |
if (rayorigin(&tr, r, TRANS, 1.0) == 0) { |
158 |
> |
if (rayorigin(&tr, TRANS, r, NULL) == 0) { |
159 |
|
VCOPY(tr.rdir, r->rdir); |
160 |
|
rayvalue(&tr); |
161 |
|
copycolor(r->rcol, tr.rcol); |
217 |
|
ge *= 1. - colval(r->albedo,GRN); |
218 |
|
be *= 1. - colval(r->albedo,BLU); |
219 |
|
} |
220 |
< |
setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re), |
221 |
< |
ge<=0. ? 1. : ge>92. ? 0. : exp(-ge), |
222 |
< |
be<=0. ? 1. : be>92. ? 0. : exp(-be)); |
223 |
< |
multcolor(r->rcol, ce); /* path absorption */ |
220 |
> |
setcolor(ce, re<=FTINY ? 1. : re>92. ? 0. : exp(-re), |
221 |
> |
ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge), |
222 |
> |
be<=FTINY ? 1. : be>92. ? 0. : exp(-be)); |
223 |
> |
multcolor(r->rcol, ce); /* path extinction */ |
224 |
|
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
225 |
|
return; /* no scattering */ |
226 |
|
setcolor(ca, |
313 |
|
|
314 |
|
extern double |
315 |
|
raydist( /* compute (cumulative) ray distance */ |
316 |
< |
register RAY *r, |
316 |
> |
register const RAY *r, |
317 |
|
register int flags |
318 |
|
) |
319 |
|
{ |
327 |
|
} |
328 |
|
|
329 |
|
|
330 |
+ |
extern void |
331 |
+ |
raycontrib( /* compute (cumulative) ray contribution */ |
332 |
+ |
COLOR rc, |
333 |
+ |
const RAY *r, |
334 |
+ |
int flags |
335 |
+ |
) |
336 |
+ |
{ |
337 |
+ |
COLOR eext, ext1; |
338 |
+ |
|
339 |
+ |
setcolor(eext, 0., 0., 0.); |
340 |
+ |
setcolor(rc, 1., 1., 1.); |
341 |
+ |
|
342 |
+ |
while (r != NULL && r->crtype&flags) { |
343 |
+ |
multcolor(rc, r->rcoef); |
344 |
+ |
copycolor(ext1, r->cext); |
345 |
+ |
scalecolor(ext1, r->rot); |
346 |
+ |
addcolor(eext, ext1); |
347 |
+ |
r = r->parent; |
348 |
+ |
} |
349 |
+ |
if (intens(eext) > FTINY) { |
350 |
+ |
setcolor(ext1, exp(-colval(eext,RED)), |
351 |
+ |
exp(-colval(eext,GRN)), |
352 |
+ |
exp(-colval(eext,BLU))); |
353 |
+ |
multcolor(rc, ext1); |
354 |
+ |
} |
355 |
+ |
} |
356 |
+ |
|
357 |
+ |
|
358 |
|
extern double |
359 |
|
raynormal( /* compute perturbed normal for ray */ |
360 |
|
FVECT norm, |
401 |
|
FULLXF xf; |
402 |
|
} xfseed = { &xfseed }, *xflast = &xfseed; |
403 |
|
register struct xfn *xp; |
404 |
< |
register RAY *rp; |
404 |
> |
register const RAY *rp; |
405 |
|
|
406 |
|
/* |
407 |
|
* Search for transform in circular list that |