| 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; |
| 63 |
|
copycolor(r->albedo, salbedo); |
| 64 |
|
r->gecc = seccg; |
| 65 |
|
r->slights = NULL; |
| 58 |
– |
} else if (ro->rot >= FHUGE) { /* illegal continuation */ |
| 59 |
– |
memset(r, 0, sizeof(RAY)); |
| 60 |
– |
return(-1); |
| 66 |
|
} else { /* spawned ray */ |
| 67 |
+ |
if (ro->rot >= FHUGE) { |
| 68 |
+ |
memset(r, 0, sizeof(RAY)); |
| 69 |
+ |
return(-1); /* illegal continuation */ |
| 70 |
+ |
} |
| 71 |
|
r->rlvl = ro->rlvl; |
| 72 |
|
if (rt & RAYREFL) { |
| 73 |
|
r->rlvl++; |
| 87 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
| 88 |
|
VCOPY(r->rorg, ro->rop); |
| 89 |
|
r->rweight = ro->rweight * rw; |
| 90 |
< |
/* estimate absorption */ |
| 90 |
> |
/* estimate extinction */ |
| 91 |
|
re = colval(ro->cext,RED) < colval(ro->cext,GRN) ? |
| 92 |
|
colval(ro->cext,RED) : colval(ro->cext,GRN); |
| 93 |
|
if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); |
| 94 |
< |
if (re > 0.) |
| 95 |
< |
r->rweight *= exp(-re*ro->rot); |
| 94 |
> |
re *= ro->rot; |
| 95 |
> |
if (re > .1) |
| 96 |
> |
r->rweight *= exp(-re); |
| 97 |
|
} |
| 98 |
|
rayclear(r); |
| 99 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
| 132 |
|
} else if (sourcehit(r)) |
| 133 |
|
rayshade(r, r->ro->omod); /* distant source */ |
| 134 |
|
|
| 125 |
– |
rayparticipate(r); /* for participating medium */ |
| 126 |
– |
|
| 135 |
|
if (trace != NULL) |
| 136 |
|
(*trace)(r); /* trace execution */ |
| 137 |
+ |
|
| 138 |
+ |
rayparticipate(r); /* for participating medium */ |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 157 |
|
{ |
| 158 |
|
RAY tr; |
| 159 |
|
|
| 160 |
< |
if (rayorigin(&tr, r, TRANS, 1.0) == 0) { |
| 160 |
> |
if (rayorigin(&tr, TRANS, r, NULL) == 0) { |
| 161 |
|
VCOPY(tr.rdir, r->rdir); |
| 162 |
|
rayvalue(&tr); |
| 163 |
|
copycolor(r->rcol, tr.rcol); |
| 219 |
|
ge *= 1. - colval(r->albedo,GRN); |
| 220 |
|
be *= 1. - colval(r->albedo,BLU); |
| 221 |
|
} |
| 222 |
< |
setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re), |
| 223 |
< |
ge<=0. ? 1. : ge>92. ? 0. : exp(-ge), |
| 224 |
< |
be<=0. ? 1. : be>92. ? 0. : exp(-be)); |
| 225 |
< |
multcolor(r->rcol, ce); /* path absorption */ |
| 222 |
> |
setcolor(ce, re<=FTINY ? 1. : re>92. ? 0. : exp(-re), |
| 223 |
> |
ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge), |
| 224 |
> |
be<=FTINY ? 1. : be>92. ? 0. : exp(-be)); |
| 225 |
> |
multcolor(r->rcol, ce); /* path extinction */ |
| 226 |
|
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
| 227 |
|
return; /* no scattering */ |
| 228 |
|
setcolor(ca, |
| 315 |
|
|
| 316 |
|
extern double |
| 317 |
|
raydist( /* compute (cumulative) ray distance */ |
| 318 |
< |
register RAY *r, |
| 318 |
> |
register const RAY *r, |
| 319 |
|
register int flags |
| 320 |
|
) |
| 321 |
|
{ |
| 329 |
|
} |
| 330 |
|
|
| 331 |
|
|
| 332 |
+ |
extern void |
| 333 |
+ |
raycontrib( /* compute (cumulative) ray contribution */ |
| 334 |
+ |
COLOR rc, |
| 335 |
+ |
const RAY *r, |
| 336 |
+ |
int flags |
| 337 |
+ |
) |
| 338 |
+ |
{ |
| 339 |
+ |
COLOR eext, ext1; |
| 340 |
+ |
|
| 341 |
+ |
setcolor(eext, 0., 0., 0.); |
| 342 |
+ |
setcolor(rc, 1., 1., 1.); |
| 343 |
+ |
|
| 344 |
+ |
while (r != NULL && r->crtype&flags) { |
| 345 |
+ |
multcolor(rc, r->rcoef); |
| 346 |
+ |
copycolor(ext1, r->cext); |
| 347 |
+ |
scalecolor(ext1, r->rot); |
| 348 |
+ |
addcolor(eext, ext1); |
| 349 |
+ |
r = r->parent; |
| 350 |
+ |
} |
| 351 |
+ |
if (intens(eext) > FTINY) { |
| 352 |
+ |
setcolor(ext1, exp(-colval(eext,RED)), |
| 353 |
+ |
exp(-colval(eext,GRN)), |
| 354 |
+ |
exp(-colval(eext,BLU))); |
| 355 |
+ |
multcolor(rc, ext1); |
| 356 |
+ |
} |
| 357 |
+ |
} |
| 358 |
+ |
|
| 359 |
+ |
|
| 360 |
|
extern double |
| 361 |
|
raynormal( /* compute perturbed normal for ray */ |
| 362 |
|
FVECT norm, |
| 403 |
|
FULLXF xf; |
| 404 |
|
} xfseed = { &xfseed }, *xflast = &xfseed; |
| 405 |
|
register struct xfn *xp; |
| 406 |
< |
register RAY *rp; |
| 406 |
> |
register const RAY *rp; |
| 407 |
|
|
| 408 |
|
/* |
| 409 |
|
* Search for transform in circular list that |