56 |
|
short specfl; /* specularity flags, defined above */ |
57 |
|
SCOLOR mcolor; /* color of this material */ |
58 |
|
SCOLOR scolor; /* color of specular component */ |
59 |
– |
FVECT vrefl; /* vector in direction of reflected ray */ |
59 |
|
FVECT prdir; /* vector in transmitted direction */ |
60 |
|
double alpha2; /* roughness squared */ |
61 |
|
double rdiff, rspec; /* reflected specular, diffuse */ |
303 |
|
/* check threshold */ |
304 |
|
if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY) |
305 |
|
nd.specfl |= SP_RBLT; |
307 |
– |
/* compute reflected ray */ |
308 |
– |
VSUM(nd.vrefl, r->rdir, nd.pnorm, 2.*nd.pdot); |
309 |
– |
/* penetration? */ |
310 |
– |
if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY) |
311 |
– |
VSUM(nd.vrefl, r->rdir, r->ron, 2.*r->rod); |
312 |
– |
checknorm(nd.vrefl); |
306 |
|
} |
307 |
|
/* reflected ray */ |
308 |
|
if ((nd.specfl&(SP_REFL|SP_PURE|SP_RBLT)) == (SP_REFL|SP_PURE)) { |
309 |
|
RAY lr; |
310 |
|
if (rayorigin(&lr, REFLECTED, r, nd.scolor) == 0) { |
311 |
< |
VCOPY(lr.rdir, nd.vrefl); |
311 |
> |
/* compute reflected ray */ |
312 |
> |
VSUM(lr.rdir, r->rdir, nd.pnorm, 2.*nd.pdot); |
313 |
> |
/* penetration? */ |
314 |
> |
if (hastexture && DOT(lr.rdir, r->ron) <= FTINY) |
315 |
> |
VSUM(lr.rdir, r->rdir, r->ron, 2.*r->rod); |
316 |
> |
checknorm(lr.rdir); |
317 |
|
rayvalue(&lr); |
318 |
|
smultscolor(lr.rcol, lr.rcoef); |
319 |
|
copyscolor(r->mcol, lr.rcol); |
336 |
|
scalescolor(sctmp, nd.rdiff); |
337 |
|
if (nd.specfl & SP_RBLT) /* add in specular as well? */ |
338 |
|
saddscolor(sctmp, nd.scolor); |
339 |
< |
multambient(sctmp, r, hastexture ? nd.pnorm : r->ron); |
339 |
> |
multambient(sctmp, r, nd.pnorm); |
340 |
|
saddscolor(r->rcol, sctmp); /* add to returned color */ |
341 |
|
} |
342 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
343 |
+ |
FVECT bnorm; |
344 |
|
copyscolor(sctmp, nd.mcolor); /* modified by color */ |
345 |
|
if (nd.specfl & SP_TBLT) { |
346 |
|
scalescolor(sctmp, nd.trans); |
347 |
|
} else { |
348 |
|
scalescolor(sctmp, nd.tdiff); |
349 |
|
} |
350 |
< |
flipsurface(r); |
351 |
< |
if (hastexture) { |
352 |
< |
FVECT bnorm; |
353 |
< |
bnorm[0] = -nd.pnorm[0]; |
355 |
< |
bnorm[1] = -nd.pnorm[1]; |
356 |
< |
bnorm[2] = -nd.pnorm[2]; |
357 |
< |
multambient(sctmp, r, bnorm); |
358 |
< |
} else |
359 |
< |
multambient(sctmp, r, r->ron); |
350 |
> |
bnorm[0] = -nd.pnorm[0]; |
351 |
> |
bnorm[1] = -nd.pnorm[1]; |
352 |
> |
bnorm[2] = -nd.pnorm[2]; |
353 |
> |
multambient(sctmp, r, bnorm); |
354 |
|
saddscolor(r->rcol, sctmp); |
361 |
– |
flipsurface(r); |
355 |
|
} |
356 |
|
/* add direct component */ |
357 |
|
direct(r, dirnorm, &nd); |
381 |
|
fcross(v, np->pnorm, u); |
382 |
|
/* compute reflection */ |
383 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
384 |
< |
rayorigin(&sr, SPECULAR, np->rp, np->scolor) == 0) { |
384 |
> |
rayorigin(&sr, RSPECULAR, np->rp, np->scolor) == 0) { |
385 |
|
nstarget = 1; |
386 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
387 |
|
nstarget = specjitter*np->rp->rweight + .5; |
446 |
|
copyscolor(sr.rcoef, np->mcolor); /* modified by color */ |
447 |
|
scalescolor(sr.rcoef, np->tspec); |
448 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
449 |
< |
rayorigin(&sr, SPECULAR, np->rp, sr.rcoef) == 0) { |
449 |
> |
rayorigin(&sr, TSPECULAR, np->rp, sr.rcoef) == 0) { |
450 |
|
nstarget = 1; |
451 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
452 |
|
nstarget = specjitter*np->rp->rweight + .5; |