| 41 |
|
RAY *r, |
| 42 |
|
int rt, |
| 43 |
|
const RAY *ro, |
| 44 |
< |
const COLOR rc |
| 44 |
> |
const SCOLOR rc |
| 45 |
|
) |
| 46 |
|
{ |
| 47 |
|
double rw, re; |
| 48 |
|
/* assign coefficient/weight */ |
| 49 |
|
if (rc == NULL) { |
| 50 |
|
rw = 1.0; |
| 51 |
< |
setcolor(r->rcoef, 1., 1., 1.); |
| 51 |
> |
setscolor(r->rcoef, 1., 1., 1.); |
| 52 |
|
} else { |
| 53 |
< |
rw = intens(rc); |
| 53 |
> |
rw = sintens(rc); |
| 54 |
|
if (rw > 1.0) |
| 55 |
|
rw = 1.0; /* avoid calculation growth */ |
| 56 |
|
if (rc != r->rcoef) |
| 57 |
< |
copycolor(r->rcoef, rc); |
| 57 |
> |
copyscolor(r->rcoef, rc); |
| 58 |
|
} |
| 59 |
|
if ((r->parent = ro) == NULL) { /* primary ray */ |
| 60 |
|
r->rlvl = 0; |
| 73 |
|
return(-1); /* illegal continuation */ |
| 74 |
|
} |
| 75 |
|
r->rlvl = ro->rlvl; |
| 76 |
+ |
r->rsrc = ro->rsrc; |
| 77 |
|
if (rt & RAYREFL) { |
| 78 |
|
r->rlvl++; |
| 79 |
< |
r->rsrc = -1; |
| 79 |
> |
if (r->rsrc >= 0) /* malfunctioning material? */ |
| 80 |
> |
r->rsrc = -1; |
| 81 |
|
r->clipset = ro->clipset; |
| 82 |
|
r->rmax = 0.0; |
| 83 |
|
} else { |
| 82 |
– |
r->rsrc = ro->rsrc; |
| 84 |
|
r->clipset = ro->newcset; |
| 85 |
< |
r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot; |
| 85 |
> |
r->rmax = (ro->rmax > FTINY)*(ro->rmax - ro->rot); |
| 86 |
|
} |
| 87 |
|
r->revf = ro->revf; |
| 88 |
|
copycolor(r->cext, ro->cext); |
| 127 |
|
if (frandom() > r->rweight/minweight) |
| 128 |
|
return(-1); |
| 129 |
|
rw = minweight/r->rweight; /* promote survivor */ |
| 130 |
< |
scalecolor(r->rcoef, rw); |
| 130 |
> |
scalescolor(r->rcoef, rw); |
| 131 |
|
r->rweight = minweight; |
| 132 |
|
return(0); |
| 133 |
|
} |
| 148 |
|
r->rox = NULL; |
| 149 |
|
r->rxt = r->rmt = r->rot = FHUGE; |
| 150 |
|
VCOPY(r->rop, r->rorg); |
| 151 |
+ |
r->ron[0] = -r->rdir[0]; r->ron[1] = -r->rdir[1]; r->ron[2] = -r->rdir[2]; |
| 152 |
+ |
r->rod = 1.0; |
| 153 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
| 154 |
|
r->rflips = 0; |
| 155 |
|
r->uv[0] = r->uv[1] = 0.0; |
| 156 |
< |
setcolor(r->pcol, 1.0, 1.0, 1.0); |
| 157 |
< |
setcolor(r->mcol, 0.0, 0.0, 0.0); |
| 158 |
< |
setcolor(r->rcol, 0.0, 0.0, 0.0); |
| 156 |
> |
setscolor(r->pcol, 1.0, 1.0, 1.0); |
| 157 |
> |
scolorblack(r->mcol); |
| 158 |
> |
scolorblack(r->rcol); |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 200 |
|
rayorigin(&tr, TRANS, r, NULL); /* always continue */ |
| 201 |
|
VCOPY(tr.rdir, r->rdir); |
| 202 |
|
rayvalue(&tr); |
| 203 |
< |
copycolor(r->mcol, tr.mcol); |
| 204 |
< |
copycolor(r->rcol, tr.rcol); |
| 203 |
> |
copyscolor(r->mcol, tr.mcol); |
| 204 |
> |
copyscolor(r->rcol, tr.rcol); |
| 205 |
|
r->rmt = r->rot + tr.rmt; |
| 206 |
|
r->rxt = r->rot + tr.rxt; |
| 207 |
|
} |
| 213 |
|
RAY *r |
| 214 |
|
) |
| 215 |
|
{ |
| 216 |
< |
if (ofun[m->otype].flags & (T_M|T_X) && m->otype != MAT_CLIP) { |
| 217 |
< |
if (istransp(m->otype) || isBSDFproxy(m)) { |
| 216 |
> |
if (m->otype != MAT_CLIP && ismaterial(m->otype)) { |
| 217 |
> |
if (istransp(m) || isBSDFproxy(m)) { |
| 218 |
|
raytrans(r); |
| 219 |
|
return(1); |
| 220 |
|
} |
| 221 |
< |
if (!islight(m->otype)) |
| 221 |
> |
if (!islight(m->otype)) { |
| 222 |
> |
setscolor(r->pcol, 1.0, 1.0, 1.0); |
| 223 |
|
return((*ofun[Lamb.otype].funp)(&Lamb, r)); |
| 224 |
+ |
} |
| 225 |
|
} |
| 226 |
|
return(0); /* not a qualifying surface */ |
| 227 |
|
} |
| 261 |
|
RAY *r |
| 262 |
|
) |
| 263 |
|
{ |
| 264 |
< |
COLOR ce, ca; |
| 264 |
> |
COLOR ce; |
| 265 |
|
double re, ge, be; |
| 266 |
|
|
| 267 |
|
if (intens(r->cext) <= 1./FHUGE) |
| 277 |
|
setcolor(ce, re<=FTINY ? 1. : re>92. ? 0. : exp(-re), |
| 278 |
|
ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge), |
| 279 |
|
be<=FTINY ? 1. : be>92. ? 0. : exp(-be)); |
| 280 |
< |
multcolor(r->rcol, ce); /* path extinction */ |
| 280 |
> |
smultcolor(r->rcol, ce); /* path extinction */ |
| 281 |
|
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
| 282 |
|
return; /* no scattering */ |
| 283 |
|
|
| 284 |
|
/* PMAP: indirect inscattering accounted for by volume photons? */ |
| 285 |
|
if (!volumePhotonMapping) { |
| 286 |
< |
setcolor(ca, |
| 286 |
> |
SCOLOR ca; |
| 287 |
> |
setscolor(ca, |
| 288 |
|
colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)), |
| 289 |
|
colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
| 290 |
|
colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
| 291 |
< |
addcolor(r->rcol, ca); /* ambient in scattering */ |
| 291 |
> |
saddscolor(r->rcol, ca); /* ambient in scattering */ |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
srcscatter(r); /* source in scattering */ |
| 343 |
|
fr = *r; |
| 344 |
|
if (coef > FTINY) { |
| 345 |
|
fr.rweight *= coef; |
| 346 |
< |
scalecolor(fr.rcoef, coef); |
| 346 |
> |
scalescolor(fr.rcoef, coef); |
| 347 |
|
foremat = rayshade(&fr, fore); |
| 348 |
|
} |
| 349 |
|
/* background */ |
| 350 |
|
br = *r; |
| 351 |
|
if (coef < 1.0-FTINY) { |
| 352 |
|
br.rweight *= 1.0-coef; |
| 353 |
< |
scalecolor(br.rcoef, 1.0-coef); |
| 353 |
> |
scalescolor(br.rcoef, 1.0-coef); |
| 354 |
|
backmat = rayshade(&br, back); |
| 355 |
|
} |
| 356 |
|
/* check for transparency */ |
| 364 |
|
for (i = 0; i < 3; i++) |
| 365 |
|
r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i]; |
| 366 |
|
/* mix pattern colors */ |
| 367 |
< |
scalecolor(fr.pcol, coef); |
| 368 |
< |
scalecolor(br.pcol, 1.0-coef); |
| 369 |
< |
copycolor(r->pcol, fr.pcol); |
| 370 |
< |
addcolor(r->pcol, br.pcol); |
| 367 |
> |
scalescolor(fr.pcol, coef); |
| 368 |
> |
scalescolor(br.pcol, 1.0-coef); |
| 369 |
> |
copyscolor(r->pcol, fr.pcol); |
| 370 |
> |
saddscolor(r->pcol, br.pcol); |
| 371 |
|
/* return value tells if material */ |
| 372 |
|
if (!foremat & !backmat) |
| 373 |
|
return(0); |
| 374 |
|
/* mix returned ray values */ |
| 375 |
< |
scalecolor(fr.rcol, coef); |
| 376 |
< |
scalecolor(br.rcol, 1.0-coef); |
| 377 |
< |
copycolor(r->rcol, fr.rcol); |
| 378 |
< |
addcolor(r->rcol, br.rcol); |
| 379 |
< |
scalecolor(fr.mcol, coef); |
| 380 |
< |
scalecolor(br.mcol, 1.0-coef); |
| 381 |
< |
copycolor(r->mcol, fr.mcol); |
| 382 |
< |
addcolor(r->mcol, br.mcol); |
| 383 |
< |
mfore = bright(fr.mcol); mback = bright(br.mcol); |
| 375 |
> |
scalescolor(fr.rcol, coef); |
| 376 |
> |
scalescolor(br.rcol, 1.0-coef); |
| 377 |
> |
copyscolor(r->rcol, fr.rcol); |
| 378 |
> |
saddscolor(r->rcol, br.rcol); |
| 379 |
> |
scalescolor(fr.mcol, coef); |
| 380 |
> |
scalescolor(br.mcol, 1.0-coef); |
| 381 |
> |
copyscolor(r->mcol, fr.mcol); |
| 382 |
> |
saddscolor(r->mcol, br.mcol); |
| 383 |
> |
mfore = pbright(fr.mcol); mback = pbright(br.mcol); |
| 384 |
|
r->rmt = mfore > mback ? fr.rmt : br.rmt; |
| 385 |
< |
r->rxt = bright(fr.rcol)-mfore > bright(br.rcol)-mback ? |
| 385 |
> |
r->rxt = pbright(fr.rcol)-mfore > pbright(br.rcol)-mback ? |
| 386 |
|
fr.rxt : br.rxt; |
| 387 |
|
return(1); |
| 388 |
|
} |
| 406 |
|
|
| 407 |
|
void |
| 408 |
|
raycontrib( /* compute (cumulative) ray contribution */ |
| 409 |
< |
RREAL rc[3], |
| 409 |
> |
SCOLOR rc, |
| 410 |
|
const RAY *r, |
| 411 |
|
int flags |
| 412 |
|
) |
| 413 |
|
{ |
| 414 |
|
static int warnedPM = 0; |
| 415 |
+ |
double re, ge, be; |
| 416 |
+ |
SCOLOR ce; |
| 417 |
|
|
| 418 |
< |
rc[0] = rc[1] = rc[2] = 1.; |
| 418 |
> |
setscolor(rc, 1., 1., 1.); |
| 419 |
> |
re = ge = be = 0.; |
| 420 |
|
|
| 421 |
|
while (r != NULL && r->crtype&flags) { |
| 422 |
< |
int i = 3; |
| 423 |
< |
while (i--) |
| 424 |
< |
rc[i] *= colval(r->rcoef,i); |
| 425 |
< |
/* check for participating medium */ |
| 417 |
< |
if (!warnedPM && (bright(r->cext) > FTINY) | |
| 418 |
< |
(bright(r->albedo) > FTINY)) { |
| 422 |
> |
/* include this ray coefficient */ |
| 423 |
> |
smultscolor(rc, r->rcoef); |
| 424 |
> |
/* check participating medium */ |
| 425 |
> |
if (!warnedPM && bright(r->albedo) > FTINY) { |
| 426 |
|
error(WARNING, |
| 427 |
|
"ray contribution calculation does not support participating media"); |
| 428 |
|
warnedPM++; |
| 429 |
|
} |
| 430 |
+ |
/* sum PM extinction */ |
| 431 |
+ |
re += r->rot*colval(r->cext,RED); |
| 432 |
+ |
ge += r->rot*colval(r->cext,GRN); |
| 433 |
+ |
be += r->rot*colval(r->cext,BLU); |
| 434 |
+ |
/* descend the tree */ |
| 435 |
|
r = r->parent; |
| 436 |
|
} |
| 437 |
+ |
/* cumulative extinction */ |
| 438 |
+ |
setscolor(ce, re<=FTINY ? 1. : re>92. ? 0. : exp(-re), |
| 439 |
+ |
ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge), |
| 440 |
+ |
be<=FTINY ? 1. : be>92. ? 0. : exp(-be)); |
| 441 |
+ |
smultscolor(rc, ce); |
| 442 |
|
} |
| 443 |
|
|
| 444 |
|
|
| 469 |
|
return(r->rod); |
| 470 |
|
} |
| 471 |
|
newdot = -DOT(norm, r->rdir); |
| 472 |
< |
if ((newdot > 0.0) != (r->rod > 0.0)) { /* fix orientation */ |
| 472 |
> |
if ((newdot > 0.0) ^ (r->rod > 0.0)) { /* fix orientation */ |
| 473 |
|
for (i = 0; i < 3; i++) |
| 474 |
|
norm[i] += 2.0*newdot*r->rdir[i]; |
| 475 |
|
newdot = -newdot; |
| 531 |
|
r->rflips++; |
| 532 |
|
} |
| 533 |
|
|
| 534 |
+ |
|
| 535 |
+ |
int |
| 536 |
+ |
rayreject( /* check if candidate hit is worse than current */ |
| 537 |
+ |
OBJREC *o, |
| 538 |
+ |
RAY *r, |
| 539 |
+ |
double t, |
| 540 |
+ |
double rod |
| 541 |
+ |
) |
| 542 |
+ |
{ |
| 543 |
+ |
OBJREC *mnew, *mray; |
| 544 |
+ |
|
| 545 |
+ |
if ((t <= FTINY) | (t > r->rot + FTINY)) |
| 546 |
+ |
return(1); |
| 547 |
+ |
if (t < r->rot - FTINY) /* is new hit significantly closer? */ |
| 548 |
+ |
return(0); |
| 549 |
+ |
/* coincident point, so decide... */ |
| 550 |
+ |
if (o == r->ro) |
| 551 |
+ |
return(1); /* shouldn't happen */ |
| 552 |
+ |
if (r->ro == NULL) |
| 553 |
+ |
return(0); /* ditto */ |
| 554 |
+ |
mnew = findmaterial(o); |
| 555 |
+ |
mray = findmaterial(r->ro); /* check material transparencies */ |
| 556 |
+ |
if (mnew == NULL) { |
| 557 |
+ |
if (mray != NULL) |
| 558 |
+ |
return(1); /* old has material, new does not */ |
| 559 |
+ |
} else if (mray == NULL) { |
| 560 |
+ |
return(0); /* new has material, old does not */ |
| 561 |
+ |
} else if (istransp(mnew)) { |
| 562 |
+ |
if (!istransp(mray)) |
| 563 |
+ |
return(1); /* new is transparent, old is not */ |
| 564 |
+ |
} else if (istransp(mray)) { |
| 565 |
+ |
return(0); /* old is transparent, new is not */ |
| 566 |
+ |
} |
| 567 |
+ |
if (rod <= 0) { /* check which side we hit */ |
| 568 |
+ |
if (r->rod > 0) |
| 569 |
+ |
return(1); /* old hit front, new did not */ |
| 570 |
+ |
} else if (r->rod <= 0) { |
| 571 |
+ |
return(0); /* new hit front, old did not */ |
| 572 |
+ |
} |
| 573 |
+ |
/* earlier modifier definition wins tie */ |
| 574 |
+ |
return (r->ro->omod >= o->omod); |
| 575 |
+ |
} |
| 576 |
|
|
| 577 |
|
void |
| 578 |
|
rayhit( /* standard ray hit test */ |