238 |
|
{ |
239 |
|
int nsamp = 1; |
240 |
|
int scnt = 0; |
241 |
< |
FVECT vsrc, vjit; |
241 |
> |
FVECT vsrc; |
242 |
|
double tomega, tomega2; |
243 |
|
double tsr, sd[2]; |
244 |
|
SCOLOR csmp, cdiff; |
306 |
|
nsamp = 4.*specjitter*ndp->pr->rweight + .5; |
307 |
|
nsamp += !nsamp; |
308 |
|
} |
309 |
< |
/* jitter to fuzz BSDF cells */ |
310 |
< |
for (i = nsamp; i--; ) { |
309 |
> |
for (i = nsamp; i--; ) { /* jitter to fuzz BSDF cells */ |
310 |
> |
FVECT vjit; |
311 |
|
bsdf_jitter(vjit, ndp, tsr); |
312 |
|
/* compute BSDF */ |
313 |
|
ec = SDevalBSDF(&sv, vjit, vsrc, ndp->sd); |
314 |
|
if (ec) |
315 |
|
goto baderror; |
316 |
< |
if (sv.cieY - diffY <= FTINY) |
317 |
< |
continue; /* no specular part */ |
316 |
> |
if (sv.cieY - diffY <= FTINY) { |
317 |
> |
++scnt; /* still counts as 0 contribution */ |
318 |
> |
continue; |
319 |
> |
} |
320 |
|
/* check for variable resolution */ |
321 |
|
ec = SDsizeBSDF(&tomega2, vjit, vsrc, SDqueryMin, ndp->sd); |
322 |
|
if (ec) |
533 |
|
cvt_sdcolor(sr.rcoef, &bsv); /* use sample color */ |
534 |
|
if (xmit) /* apply pattern on transmit */ |
535 |
|
smultscolor(sr.rcoef, ndp->pr->pcol); |
536 |
< |
if (rayorigin(&sr, SPECULAR, ndp->pr, sr.rcoef) < 0) { |
536 |
> |
if (rayorigin(&sr, xmit ? TSPECULAR : RSPECULAR, ndp->pr, sr.rcoef) < 0) { |
537 |
|
if (!n & (nstarget > 1)) { |
538 |
|
n = nstarget; /* avoid infinitue loop */ |
539 |
< |
nstarget = nstarget*sr.rweight/minweight; |
539 |
> |
nstarget = nstarget*sr.rweight/(minweight + 1e-20); |
540 |
|
if (n == nstarget) break; |
541 |
|
n = -1; /* moved target */ |
542 |
|
} |
768 |
|
copyscolor(sctmp, nd.rdiff); |
769 |
|
saddscolor(sctmp, nd.runsamp); |
770 |
|
if (sintens(sctmp) > FTINY) { /* ambient from reflection */ |
769 |
– |
if (!hitfront) |
770 |
– |
flipsurface(r); |
771 |
|
multambient(sctmp, r, nd.pnorm); |
772 |
|
saddscolor(r->rcol, sctmp); |
773 |
– |
if (!hitfront) |
774 |
– |
flipsurface(r); |
773 |
|
} |
774 |
|
copyscolor(sctmp, nd.tdiff); |
775 |
|
saddscolor(sctmp, nd.tunsamp); |
776 |
|
if (sintens(sctmp) > FTINY) { /* ambient from other side */ |
777 |
|
FVECT bnorm; |
780 |
– |
if (hitfront) |
781 |
– |
flipsurface(r); |
778 |
|
bnorm[0] = -nd.pnorm[0]; |
779 |
|
bnorm[1] = -nd.pnorm[1]; |
780 |
|
bnorm[2] = -nd.pnorm[2]; |
786 |
|
} else |
787 |
|
multambient(sctmp, r, bnorm); |
788 |
|
saddscolor(r->rcol, sctmp); |
793 |
– |
if (hitfront) |
794 |
– |
flipsurface(r); |
789 |
|
} |
790 |
|
/* add direct component */ |
791 |
|
if ((nd.sd->tf == NULL) & (nd.sd->tb == NULL) && |