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 */ |
160 |
|
if (dtmp > FTINY*FTINY) { |
161 |
|
dtmp1 = DOT(h,np->pnorm); |
162 |
|
dtmp = 1.0 - dtmp1*dtmp1/dtmp; |
163 |
< |
if (dtmp > FTINY*FTINY) { |
164 |
< |
dtmp1 = DOT(h,np->u); |
165 |
< |
dtmp1 *= dtmp1 / au2; |
166 |
< |
dtmp2 = DOT(h,np->v); |
167 |
< |
dtmp2 *= dtmp2 / av2; |
168 |
< |
dtmp = (dtmp1 + dtmp2) / dtmp; |
169 |
< |
} |
163 |
> |
} |
164 |
> |
if (dtmp > FTINY*FTINY) { |
165 |
> |
dtmp1 = DOT(h,np->u); |
166 |
> |
dtmp1 *= dtmp1 / au2; |
167 |
> |
dtmp2 = DOT(h,np->v); |
168 |
> |
dtmp2 *= dtmp2 / av2; |
169 |
> |
dtmp = (dtmp1 + dtmp2) / dtmp; |
170 |
> |
dtmp = exp(-dtmp); |
171 |
|
} else |
172 |
< |
dtmp = 0.0; |
172 |
> |
dtmp = 1.0; |
173 |
|
/* Gaussian */ |
174 |
< |
dtmp = exp(-dtmp) * (1.0/PI) * sqrt(-ldot/(np->pdot*au2*av2)); |
174 |
> |
dtmp *= (1.0/PI) * sqrt(-ldot/(np->pdot*au2*av2)); |
175 |
|
/* worth using? */ |
176 |
|
if (dtmp > FTINY) { |
177 |
|
copyscolor(sctmp, np->mcolor); |
237 |
|
/* check threshold */ |
238 |
|
if (specthresh >= nd.rspec-FTINY) |
239 |
|
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); |
240 |
|
} |
241 |
|
/* compute transmission */ |
242 |
|
if (m->otype == MAT_TRANS2) { |
284 |
|
|
285 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
286 |
|
FVECT bnorm; |
291 |
– |
|
292 |
– |
flipsurface(r); |
287 |
|
bnorm[0] = -nd.pnorm[0]; |
288 |
|
bnorm[1] = -nd.pnorm[1]; |
289 |
|
bnorm[2] = -nd.pnorm[2]; |
295 |
|
} |
296 |
|
multambient(sctmp, r, bnorm); |
297 |
|
saddscolor(r->rcol, sctmp); |
304 |
– |
flipsurface(r); |
298 |
|
} |
299 |
|
/* add direct component */ |
300 |
|
direct(r, diraniso, &nd); |
317 |
|
np->u[i] = evalue(mf->ep[i]); |
318 |
|
if ((errno == EDOM) | (errno == ERANGE)) |
319 |
|
np->u[0] = np->u[1] = np->u[2] = 0.0; |
320 |
< |
if (mf->fxp != &unitxf) |
320 |
> |
else if (mf->fxp != &unitxf) |
321 |
|
multv3(np->u, np->u, mf->fxp->xfm); |
322 |
|
fcross(np->v, np->pnorm, np->u); |
323 |
|
if (normalize(np->v) == 0.0) { |
341 |
|
FVECT h; |
342 |
|
double rv[2]; |
343 |
|
double d, sinp, cosp; |
351 |
– |
SCOLOR scol; |
344 |
|
int maxiter, ntrials, nstarget, nstaken; |
345 |
|
int i; |
346 |
|
/* compute reflection */ |
347 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
348 |
< |
rayorigin(&sr, SPECULAR, np->rp, np->scolor) == 0) { |
348 |
> |
rayorigin(&sr, RSPECULAR, np->rp, np->scolor) == 0) { |
349 |
> |
SCOLOR scol; |
350 |
|
nstarget = 1; |
351 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
352 |
|
nstarget = specjitter*np->rp->rweight + .5; |
362 |
|
scolorblack(scol); |
363 |
|
dimlist[ndims++] = (int)(size_t)np->mp; |
364 |
|
maxiter = MAXITER*nstarget; |
365 |
< |
for (nstaken = ntrials = 0; nstaken < nstarget && |
366 |
< |
ntrials < maxiter; ntrials++) { |
365 |
> |
for (nstaken = ntrials = 0; (nstaken < nstarget) & |
366 |
> |
(ntrials < maxiter); ntrials++) { |
367 |
|
if (ntrials) |
368 |
|
d = frandom(); |
369 |
|
else |
377 |
|
sinp *= d; |
378 |
|
if ((0. <= specjitter) & (specjitter < 1.)) |
379 |
|
rv[1] = 1.0 - specjitter*rv[1]; |
380 |
< |
if (rv[1] <= FTINY) |
388 |
< |
d = 1.0; |
389 |
< |
else |
390 |
< |
d = sqrt(-log(rv[1]) / |
380 |
> |
d = (rv[1] <= FTINY) ? 1.0 : sqrt( -log(rv[1]) / |
381 |
|
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
382 |
< |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
382 |
> |
sinp*sinp/(np->v_alpha*np->v_alpha)) ); |
383 |
|
for (i = 0; i < 3; i++) |
384 |
|
h[i] = np->pnorm[i] + |
385 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
414 |
|
copyscolor(sr.rcoef, np->mcolor); /* modify by material color */ |
415 |
|
scalescolor(sr.rcoef, np->tspec); |
416 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
417 |
< |
rayorigin(&sr, SPECULAR, np->rp, sr.rcoef) == 0) { |
417 |
> |
rayorigin(&sr, TSPECULAR, np->rp, sr.rcoef) == 0) { |
418 |
|
nstarget = 1; |
419 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
420 |
|
nstarget = specjitter*np->rp->rweight + .5; |
429 |
|
} |
430 |
|
dimlist[ndims++] = (int)(size_t)np->mp; |
431 |
|
maxiter = MAXITER*nstarget; |
432 |
< |
for (nstaken = ntrials = 0; nstaken < nstarget && |
433 |
< |
ntrials < maxiter; ntrials++) { |
432 |
> |
for (nstaken = ntrials = 0; (nstaken < nstarget) & |
433 |
> |
(ntrials < maxiter); ntrials++) { |
434 |
|
if (ntrials) |
435 |
|
d = frandom(); |
436 |
|
else |
453 |
|
for (i = 0; i < 3; i++) |
454 |
|
sr.rdir[i] = np->prdir[i] + |
455 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
456 |
< |
if (DOT(sr.rdir, np->rp->ron) >= -FTINY) |
457 |
< |
continue; |
456 |
> |
if (DOT(sr.rdir,np->rp->ron) >= -FTINY) |
457 |
> |
continue; /* reject sample */ |
458 |
|
normalize(sr.rdir); /* OK, normalize */ |
459 |
|
if (nstaken) /* multi-sampling */ |
460 |
|
rayclear(&sr); |