| 49 |
|
short specfl; /* specularity flags, defined above */ |
| 50 |
|
SCOLOR mcolor; /* color of this material */ |
| 51 |
|
SCOLOR scolor; /* color of specular component */ |
| 52 |
– |
FVECT vrefl; /* vector in reflected direction */ |
| 52 |
|
FVECT prdir; /* vector in transmitted direction */ |
| 53 |
|
FVECT u, v; /* u and v vectors orienting anisotropy */ |
| 54 |
|
double u_alpha; /* u roughness */ |
| 236 |
|
/* check threshold */ |
| 237 |
|
if (specthresh >= nd.rspec-FTINY) |
| 238 |
|
nd.specfl |= SP_RBLT; |
| 240 |
– |
/* compute refl. direction */ |
| 241 |
– |
VSUM(nd.vrefl, r->rdir, nd.pnorm, 2.0*nd.pdot); |
| 242 |
– |
if (DOT(nd.vrefl, r->ron) <= FTINY) /* penetration? */ |
| 243 |
– |
VSUM(nd.vrefl, r->rdir, r->ron, 2.0*r->rod); |
| 239 |
|
} |
| 240 |
|
/* compute transmission */ |
| 241 |
|
if (m->otype == MAT_TRANS2) { |
| 283 |
|
|
| 284 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
| 285 |
|
FVECT bnorm; |
| 291 |
– |
|
| 292 |
– |
flipsurface(r); |
| 286 |
|
bnorm[0] = -nd.pnorm[0]; |
| 287 |
|
bnorm[1] = -nd.pnorm[1]; |
| 288 |
|
bnorm[2] = -nd.pnorm[2]; |
| 294 |
|
} |
| 295 |
|
multambient(sctmp, r, bnorm); |
| 296 |
|
saddscolor(r->rcol, sctmp); |
| 304 |
– |
flipsurface(r); |
| 297 |
|
} |
| 298 |
|
/* add direct component */ |
| 299 |
|
direct(r, diraniso, &nd); |
| 316 |
|
np->u[i] = evalue(mf->ep[i]); |
| 317 |
|
if ((errno == EDOM) | (errno == ERANGE)) |
| 318 |
|
np->u[0] = np->u[1] = np->u[2] = 0.0; |
| 319 |
< |
if (mf->fxp != &unitxf) |
| 319 |
> |
else if (mf->fxp != &unitxf) |
| 320 |
|
multv3(np->u, np->u, mf->fxp->xfm); |
| 321 |
|
fcross(np->v, np->pnorm, np->u); |
| 322 |
|
if (normalize(np->v) == 0.0) { |
| 340 |
|
FVECT h; |
| 341 |
|
double rv[2]; |
| 342 |
|
double d, sinp, cosp; |
| 351 |
– |
SCOLOR scol; |
| 343 |
|
int maxiter, ntrials, nstarget, nstaken; |
| 344 |
|
int i; |
| 345 |
|
/* compute reflection */ |
| 346 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
| 347 |
< |
rayorigin(&sr, SPECULAR, np->rp, np->scolor) == 0) { |
| 347 |
> |
rayorigin(&sr, RSPECULAR, np->rp, np->scolor) == 0) { |
| 348 |
> |
SCOLOR scol; |
| 349 |
|
nstarget = 1; |
| 350 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
| 351 |
|
nstarget = specjitter*np->rp->rweight + .5; |
| 361 |
|
scolorblack(scol); |
| 362 |
|
dimlist[ndims++] = (int)(size_t)np->mp; |
| 363 |
|
maxiter = MAXITER*nstarget; |
| 364 |
< |
for (nstaken = ntrials = 0; nstaken < nstarget && |
| 365 |
< |
ntrials < maxiter; ntrials++) { |
| 364 |
> |
for (nstaken = ntrials = 0; (nstaken < nstarget) & |
| 365 |
> |
(ntrials < maxiter); ntrials++) { |
| 366 |
|
if (ntrials) |
| 367 |
|
d = frandom(); |
| 368 |
|
else |
| 376 |
|
sinp *= d; |
| 377 |
|
if ((0. <= specjitter) & (specjitter < 1.)) |
| 378 |
|
rv[1] = 1.0 - specjitter*rv[1]; |
| 379 |
< |
if (rv[1] <= FTINY) |
| 388 |
< |
d = 1.0; |
| 389 |
< |
else |
| 390 |
< |
d = sqrt(-log(rv[1]) / |
| 379 |
> |
d = (rv[1] <= FTINY) ? 1.0 : sqrt( -log(rv[1]) / |
| 380 |
|
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
| 381 |
< |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
| 381 |
> |
sinp*sinp/(np->v_alpha*np->v_alpha)) ); |
| 382 |
|
for (i = 0; i < 3; i++) |
| 383 |
|
h[i] = np->pnorm[i] + |
| 384 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
| 413 |
|
copyscolor(sr.rcoef, np->mcolor); /* modify by material color */ |
| 414 |
|
scalescolor(sr.rcoef, np->tspec); |
| 415 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
| 416 |
< |
rayorigin(&sr, SPECULAR, np->rp, sr.rcoef) == 0) { |
| 416 |
> |
rayorigin(&sr, TSPECULAR, np->rp, sr.rcoef) == 0) { |
| 417 |
|
nstarget = 1; |
| 418 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
| 419 |
|
nstarget = specjitter*np->rp->rweight + .5; |
| 428 |
|
} |
| 429 |
|
dimlist[ndims++] = (int)(size_t)np->mp; |
| 430 |
|
maxiter = MAXITER*nstarget; |
| 431 |
< |
for (nstaken = ntrials = 0; nstaken < nstarget && |
| 432 |
< |
ntrials < maxiter; ntrials++) { |
| 431 |
> |
for (nstaken = ntrials = 0; (nstaken < nstarget) & |
| 432 |
> |
(ntrials < maxiter); ntrials++) { |
| 433 |
|
if (ntrials) |
| 434 |
|
d = frandom(); |
| 435 |
|
else |
| 452 |
|
for (i = 0; i < 3; i++) |
| 453 |
|
sr.rdir[i] = np->prdir[i] + |
| 454 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
| 455 |
< |
if (DOT(sr.rdir, np->rp->ron) >= -FTINY) |
| 456 |
< |
continue; |
| 455 |
> |
if (DOT(sr.rdir,np->rp->ron) >= -FTINY) |
| 456 |
> |
continue; /* reject sample */ |
| 457 |
|
normalize(sr.rdir); /* OK, normalize */ |
| 458 |
|
if (nstaken) /* multi-sampling */ |
| 459 |
|
rayclear(&sr); |