| 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 |
|
|
| 20 |
< |
unsigned long raynum = 0; /* next unique ray number */ |
| 21 |
< |
unsigned long nrays = 0; /* number of calls to localhit */ |
| 20 |
> |
RNUMBER raynum = 0; /* next unique ray number */ |
| 21 |
> |
RNUMBER nrays = 0; /* number of calls to localhit */ |
| 22 |
|
|
| 23 |
|
static RREAL Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
| 24 |
|
OBJREC Lamb = { |
| 25 |
|
OVOID, MAT_PLASTIC, "Lambertian", |
| 26 |
< |
{0, 5, NULL, Lambfa}, NULL, |
| 26 |
> |
{NULL, Lambfa, 0, 5}, NULL |
| 27 |
|
}; /* a Lambertian surface */ |
| 28 |
|
|
| 29 |
|
OBJREC Aftplane; /* aft clipping plane object */ |
| 59 |
|
r->crtype = r->rtype = rt; |
| 60 |
|
r->rsrc = -1; |
| 61 |
|
r->clipset = NULL; |
| 62 |
+ |
r->revf = raytrace; |
| 63 |
|
copycolor(r->cext, cextinction); |
| 64 |
|
copycolor(r->albedo, salbedo); |
| 65 |
|
r->gecc = seccg; |
| 80 |
|
r->clipset = ro->newcset; |
| 81 |
|
r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot; |
| 82 |
|
} |
| 83 |
+ |
r->revf = ro->revf; |
| 84 |
|
copycolor(r->cext, ro->cext); |
| 85 |
|
copycolor(r->albedo, ro->albedo); |
| 86 |
|
r->gecc = ro->gecc; |
| 93 |
|
colval(ro->cext,RED) : colval(ro->cext,GRN); |
| 94 |
|
if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); |
| 95 |
|
re *= ro->rot; |
| 96 |
< |
if (re > .1) |
| 97 |
< |
r->rweight *= exp(-re); |
| 96 |
> |
if (re > 0.1) { |
| 97 |
> |
if (re > 92.) { |
| 98 |
> |
r->rweight = 0.0; |
| 99 |
> |
} else { |
| 100 |
> |
r->rweight *= exp(-re); |
| 101 |
> |
} |
| 102 |
> |
} |
| 103 |
|
} |
| 104 |
|
rayclear(r); |
| 105 |
< |
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
| 105 |
> |
if (r->rweight <= 0.0) /* check for expiration */ |
| 106 |
> |
return(-1); |
| 107 |
> |
if (r->crtype & SHADOW) /* shadow commitment */ |
| 108 |
> |
return(0); |
| 109 |
> |
if (maxdepth <= 0 && rc != NULL) { /* Russian roulette */ |
| 110 |
> |
if (minweight <= 0.0) |
| 111 |
> |
error(USER, "zero ray weight in Russian roulette"); |
| 112 |
> |
if (maxdepth < 0 && r->rlvl > -maxdepth) |
| 113 |
> |
return(-1); /* upper reflection limit */ |
| 114 |
> |
if (r->rweight >= minweight) |
| 115 |
> |
return(0); |
| 116 |
> |
if (frandom() > r->rweight/minweight) |
| 117 |
> |
return(-1); |
| 118 |
> |
rw = minweight/r->rweight; /* promote survivor */ |
| 119 |
> |
scalecolor(r->rcoef, rw); |
| 120 |
> |
r->rweight = minweight; |
| 121 |
> |
return(0); |
| 122 |
> |
} |
| 123 |
> |
return(r->rlvl <= abs(maxdepth) && r->rweight >= minweight ? 0 : -1); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
extern void |
| 147 |
< |
rayvalue( /* trace a ray and compute its value */ |
| 147 |
> |
raytrace( /* trace a ray and compute its value */ |
| 148 |
|
RAY *r |
| 149 |
|
) |
| 150 |
|
{ |
| 303 |
|
foremat = backmat = 0; |
| 304 |
|
/* foreground */ |
| 305 |
|
fr = *r; |
| 306 |
< |
if (coef > FTINY) |
| 306 |
> |
if (coef > FTINY) { |
| 307 |
> |
fr.rweight *= coef; |
| 308 |
> |
scalecolor(fr.rcoef, coef); |
| 309 |
|
foremat = rayshade(&fr, fore); |
| 310 |
+ |
} |
| 311 |
|
/* background */ |
| 312 |
|
br = *r; |
| 313 |
< |
if (coef < 1.0-FTINY) |
| 313 |
> |
if (coef < 1.0-FTINY) { |
| 314 |
> |
br.rweight *= 1.0-coef; |
| 315 |
> |
scalecolor(br.rcoef, 1.0-coef); |
| 316 |
|
backmat = rayshade(&br, back); |
| 317 |
+ |
} |
| 318 |
|
/* check for transparency */ |
| 319 |
|
if (backmat ^ foremat) { |
| 320 |
|
if (backmat && coef > FTINY) |
| 361 |
|
|
| 362 |
|
extern void |
| 363 |
|
raycontrib( /* compute (cumulative) ray contribution */ |
| 364 |
< |
COLOR rc, |
| 364 |
> |
RREAL rc[3], |
| 365 |
|
const RAY *r, |
| 366 |
|
int flags |
| 367 |
|
) |
| 368 |
|
{ |
| 369 |
< |
COLOR eext, ext1; |
| 370 |
< |
|
| 339 |
< |
setcolor(eext, 0., 0., 0.); |
| 340 |
< |
setcolor(rc, 1., 1., 1.); |
| 369 |
> |
double eext[3]; |
| 370 |
> |
int i; |
| 371 |
|
|
| 372 |
+ |
eext[0] = eext[1] = eext[2] = 0.; |
| 373 |
+ |
rc[0] = rc[1] = rc[2] = 1.; |
| 374 |
+ |
|
| 375 |
|
while (r != NULL && r->crtype&flags) { |
| 376 |
< |
multcolor(rc, r->rcoef); |
| 377 |
< |
copycolor(ext1, r->cext); |
| 378 |
< |
scalecolor(ext1, r->rot); |
| 379 |
< |
addcolor(eext, ext1); |
| 376 |
> |
for (i = 3; i--; ) { |
| 377 |
> |
rc[i] *= colval(r->rcoef,i); |
| 378 |
> |
eext[i] += r->rot * colval(r->cext,i); |
| 379 |
> |
} |
| 380 |
|
r = r->parent; |
| 381 |
|
} |
| 382 |
< |
if (intens(eext) > FTINY) { |
| 383 |
< |
setcolor(ext1, exp(-colval(eext,RED)), |
| 384 |
< |
exp(-colval(eext,GRN)), |
| 352 |
< |
exp(-colval(eext,BLU))); |
| 353 |
< |
multcolor(rc, ext1); |
| 354 |
< |
} |
| 382 |
> |
for (i = 3; i--; ) |
| 383 |
> |
rc[i] *= (eext[i] <= FTINY) ? 1. : |
| 384 |
> |
(eext[i] > 92.) ? 0. : exp(-eext[i]); |
| 385 |
|
} |
| 386 |
|
|
| 387 |
|
|
| 512 |
|
else if (r->rdir[i] < -1e-7) |
| 513 |
|
sflags |= 0x10 << i; |
| 514 |
|
} |
| 515 |
< |
if (sflags == 0) |
| 516 |
< |
error(CONSISTENCY, "zero ray direction in localhit"); |
| 515 |
> |
if (!sflags) { |
| 516 |
> |
error(WARNING, "zero ray direction in localhit"); |
| 517 |
> |
return(0); |
| 518 |
> |
} |
| 519 |
|
/* start off assuming nothing hit */ |
| 520 |
|
if (r->rmax > FTINY) { /* except aft plane if one */ |
| 521 |
|
r->ro = &Aftplane; |
| 522 |
|
r->rot = r->rmax; |
| 523 |
< |
for (i = 0; i < 3; i++) |
| 492 |
< |
r->rop[i] = r->rorg[i] + r->rot*r->rdir[i]; |
| 523 |
> |
VSUM(r->rop, r->rorg, r->rdir, r->rot); |
| 524 |
|
} |
| 525 |
|
/* find global cube entrance point */ |
| 526 |
|
t = 0.0; |
| 543 |
|
if (t >= r->rot) /* clipped already */ |
| 544 |
|
return(0); |
| 545 |
|
/* advance position */ |
| 546 |
< |
for (i = 0; i < 3; i++) |
| 516 |
< |
curpos[i] += r->rdir[i]*t; |
| 546 |
> |
VSUM(curpos, curpos, r->rdir, t); |
| 547 |
|
|
| 548 |
|
if (!incube(scene, curpos)) /* non-intersecting ray */ |
| 549 |
|
return(0); |
| 634 |
|
ax = 2; |
| 635 |
|
} |
| 636 |
|
} |
| 637 |
< |
pos[0] += r->rdir[0]*t; |
| 608 |
< |
pos[1] += r->rdir[1]*t; |
| 609 |
< |
pos[2] += r->rdir[2]*t; |
| 637 |
> |
VSUM(pos, pos, r->rdir, t); |
| 638 |
|
return(ax); |
| 639 |
|
} |
| 640 |
|
|