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 > 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 |
|
|
154 |
|
} else if (sourcehit(r)) |
155 |
|
rayshade(r, r->ro->omod); /* distant source */ |
156 |
|
|
125 |
– |
rayparticipate(r); /* for participating medium */ |
126 |
– |
|
157 |
|
if (trace != NULL) |
158 |
|
(*trace)(r); /* trace execution */ |
159 |
+ |
|
160 |
+ |
rayparticipate(r); /* for participating medium */ |
161 |
|
} |
162 |
|
|
163 |
|
|
179 |
|
{ |
180 |
|
RAY tr; |
181 |
|
|
182 |
< |
if (rayorigin(&tr, r, TRANS, 1.0) == 0) { |
182 |
> |
if (rayorigin(&tr, TRANS, r, NULL) == 0) { |
183 |
|
VCOPY(tr.rdir, r->rdir); |
184 |
|
rayvalue(&tr); |
185 |
|
copycolor(r->rcol, tr.rcol); |
194 |
|
int mod |
195 |
|
) |
196 |
|
{ |
165 |
– |
int gotmat; |
197 |
|
register OBJREC *m; |
198 |
+ |
|
199 |
|
r->rt = r->rot; /* set effective ray length */ |
200 |
< |
for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) { |
200 |
> |
for ( ; mod != OVOID; mod = m->omod) { |
201 |
|
m = objptr(mod); |
202 |
|
/****** unnecessary test since modifier() is always called |
203 |
|
if (!ismodifier(m->otype)) { |
216 |
|
if (!islight(m->otype)) |
217 |
|
m = &Lamb; |
218 |
|
} |
219 |
< |
/* materials call raytexture */ |
220 |
< |
gotmat = (*ofun[m->otype].funp)(m, r); |
219 |
> |
if ((*ofun[m->otype].funp)(m, r)) |
220 |
> |
return(1); /* materials call raytexture() */ |
221 |
|
} |
222 |
< |
return(gotmat); |
222 |
> |
return(0); /* no material! */ |
223 |
|
} |
224 |
|
|
225 |
|
|
241 |
|
ge *= 1. - colval(r->albedo,GRN); |
242 |
|
be *= 1. - colval(r->albedo,BLU); |
243 |
|
} |
244 |
< |
setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re), |
245 |
< |
ge<=0. ? 1. : ge>92. ? 0. : exp(-ge), |
246 |
< |
be<=0. ? 1. : be>92. ? 0. : exp(-be)); |
247 |
< |
multcolor(r->rcol, ce); /* path absorption */ |
244 |
> |
setcolor(ce, re<=FTINY ? 1. : re>92. ? 0. : exp(-re), |
245 |
> |
ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge), |
246 |
> |
be<=FTINY ? 1. : be>92. ? 0. : exp(-be)); |
247 |
> |
multcolor(r->rcol, ce); /* path extinction */ |
248 |
|
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
249 |
|
return; /* no scattering */ |
250 |
|
setcolor(ca, |
337 |
|
|
338 |
|
extern double |
339 |
|
raydist( /* compute (cumulative) ray distance */ |
340 |
< |
register RAY *r, |
340 |
> |
register const RAY *r, |
341 |
|
register int flags |
342 |
|
) |
343 |
|
{ |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
+ |
extern void |
355 |
+ |
raycontrib( /* compute (cumulative) ray contribution */ |
356 |
+ |
double rc[3], |
357 |
+ |
const RAY *r, |
358 |
+ |
int flags |
359 |
+ |
) |
360 |
+ |
{ |
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 |
+ |
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 |
+ |
for (i = 3; i--; ) |
375 |
+ |
rc[i] *= (eext[i] <= FTINY) ? 1. : |
376 |
+ |
(eext[i] > 92.) ? 0. : exp(-eext[i]); |
377 |
+ |
} |
378 |
+ |
|
379 |
+ |
|
380 |
|
extern double |
381 |
|
raynormal( /* compute perturbed normal for ray */ |
382 |
|
FVECT norm, |
423 |
|
FULLXF xf; |
424 |
|
} xfseed = { &xfseed }, *xflast = &xfseed; |
425 |
|
register struct xfn *xp; |
426 |
< |
register RAY *rp; |
426 |
> |
register const RAY *rp; |
427 |
|
|
428 |
|
/* |
429 |
|
* Search for transform in circular list that |