106 |
|
{0, -1.6}, |
107 |
|
{1.6, 0}, |
108 |
|
}; |
109 |
< |
const double peak_over = 2.0; |
109 |
> |
const double peak_over = 1.5; |
110 |
|
SDSpectralDF *dfp; |
111 |
|
FVECT pdir; |
112 |
|
double tomega, srchrad; |
116 |
|
|
117 |
|
setcolor(ndp->cthru, 0, 0, 0); /* starting assumption */ |
118 |
|
|
119 |
+ |
if (ndp->pr->crtype & (SPECULAR|AMBIENT) && !(ndp->pr->crtype & SHADOW)) |
120 |
+ |
return; /* no need for through comp. */ |
121 |
+ |
|
122 |
|
if (ndp->pr->rod > 0) |
123 |
|
dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb; |
124 |
|
else |
131 |
|
srchrad = sqrt(dfp->minProjSA); /* else search for peak */ |
132 |
|
setcolor(vpeak, 0, 0, 0); |
133 |
|
setcolor(vsum, 0, 0, 0); |
134 |
+ |
pdir[2] = 0.0; |
135 |
|
for (i = 0; i < NDIR2CHECK; i++) { |
136 |
|
FVECT tdir; |
137 |
|
SDValue sv; |
145 |
|
goto baderror; |
146 |
|
cvt_sdcolor(vcol, &sv); |
147 |
|
addcolor(vsum, vcol); |
148 |
< |
if (bright(vcol) > bright(vpeak)) { |
148 |
> |
if (sv.cieY > bright(vpeak)) { |
149 |
|
copycolor(vpeak, vcol); |
150 |
|
VCOPY(pdir, tdir); |
151 |
|
} |
152 |
|
} |
153 |
+ |
if (pdir[2] == 0.0) |
154 |
+ |
return; /* zero neighborhood */ |
155 |
|
ec = SDsizeBSDF(&tomega, pdir, ndp->vray, SDqueryMin, ndp->sd); |
156 |
|
if (ec) |
157 |
|
goto baderror; |
158 |
|
if (tomega > 1.5*dfp->minProjSA) |
159 |
|
return; /* not really a peak? */ |
160 |
+ |
tomega /= fabs(pdir[2]); /* remove cosine factor */ |
161 |
|
if ((bright(vpeak) - ndp->sd->tLamb.cieY*(1./PI))*tomega <= .001) |
162 |
|
return; /* < 0.1% transmission */ |
163 |
|
for (i = 3; i--; ) /* remove peak from average */ |
191 |
|
static int |
192 |
|
direct_specular_OK(COLOR cval, FVECT ldir, double omega, BSDFDAT *ndp) |
193 |
|
{ |
194 |
< |
int nsamp, ok = 0; |
194 |
> |
int nsamp; |
195 |
> |
double wtot = 0; |
196 |
|
FVECT vsrc, vsmp, vjit; |
197 |
|
double tomega, tomega2; |
198 |
|
double sf, tsr, sd[2]; |
277 |
|
if (tomega2 < .12*tomega) |
278 |
|
continue; /* not safe to include */ |
279 |
|
cvt_sdcolor(csmp, &sv); |
280 |
< |
addcolor(cval, csmp); /* else average it in */ |
281 |
< |
++ok; |
280 |
> |
|
281 |
> |
if (sf < 2.5*tsr) { /* weight by Y for small sources */ |
282 |
> |
scalecolor(csmp, sv.cieY); |
283 |
> |
wtot += sv.cieY; |
284 |
> |
} else |
285 |
> |
wtot += 1.; |
286 |
> |
addcolor(cval, csmp); |
287 |
|
} |
288 |
< |
if (!ok) /* no valid specular samples? */ |
288 |
> |
if (wtot <= FTINY) /* no valid specular samples? */ |
289 |
|
return(0); |
290 |
|
|
291 |
< |
sf = 1./(double)ok; /* compute average BSDF */ |
291 |
> |
sf = 1./wtot; /* weighted average BSDF */ |
292 |
|
scalecolor(cval, sf); |
293 |
|
/* subtract diffuse contribution */ |
294 |
|
for (i = 3*(diffY > FTINY); i--; ) |
444 |
|
static int |
445 |
|
sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int xmit) |
446 |
|
{ |
447 |
< |
int hasthru = (xmit && !(ndp->pr->crtype & (SPECULAR|AMBIENT)) |
448 |
< |
&& bright(ndp->cthru) > FTINY); |
449 |
< |
int nstarget = 1; |
450 |
< |
int nsent = 0; |
451 |
< |
int n; |
452 |
< |
SDError ec; |
453 |
< |
SDValue bsv; |
454 |
< |
double xrand; |
455 |
< |
FVECT vsmp, vinc; |
443 |
< |
RAY sr; |
447 |
> |
const int hasthru = (xmit && bright(ndp->cthru) > FTINY); |
448 |
> |
int nstarget = 1; |
449 |
> |
int nsent = 0; |
450 |
> |
int n; |
451 |
> |
SDError ec; |
452 |
> |
SDValue bsv; |
453 |
> |
double xrand; |
454 |
> |
FVECT vsmp, vinc; |
455 |
> |
RAY sr; |
456 |
|
/* multiple samples? */ |
457 |
|
if (specjitter > 1.5) { |
458 |
|
nstarget = specjitter*ndp->pr->rweight + .5; |
509 |
|
static int |
510 |
|
sample_sdf(BSDFDAT *ndp, int sflags) |
511 |
|
{ |
512 |
< |
int hasthru = (sflags == SDsampSpT |
513 |
< |
&& !(ndp->pr->crtype & (SPECULAR|AMBIENT)) |
502 |
< |
&& bright(ndp->cthru) > FTINY); |
512 |
> |
int hasthru = (sflags == SDsampSpT && |
513 |
> |
bright(ndp->cthru) > FTINY); |
514 |
|
int n, ntotal = 0; |
515 |
|
double b = 0; |
516 |
|
SDSpectralDF *dfp; |
533 |
|
if (dfp == NULL) /* no specular component? */ |
534 |
|
return(0); |
535 |
|
|
525 |
– |
dimlist[ndims++] = (int)(size_t)ndp->mp; |
536 |
|
if (hasthru) { /* separate view sample? */ |
537 |
|
RAY tr; |
538 |
|
if (rayorigin(&tr, TRANS, ndp->pr, ndp->cthru) == 0) { |
545 |
|
} else |
546 |
|
hasthru = 0; |
547 |
|
} |
548 |
< |
ndims--; |
539 |
< |
if (dfp->maxHemi - b <= FTINY) { /* how specular to sample? */ |
548 |
> |
if (dfp->maxHemi - b <= FTINY) { /* have specular to sample? */ |
549 |
|
b = 0; |
550 |
|
} else { |
551 |
|
FVECT vjit; |
563 |
|
} |
564 |
|
return(ntotal); |
565 |
|
} |
566 |
< |
ndims += 2; /* else sample specular */ |
566 |
> |
dimlist[ndims] = (int)(size_t)ndp->mp; /* else sample specular */ |
567 |
> |
ndims += 2; |
568 |
|
for (n = dfp->ncomp; n--; ) { /* loop over components */ |
569 |
|
dimlist[ndims-1] = n + 9438; |
570 |
|
ntotal += sample_sdcomp(ndp, &dfp->comp[n], sflags==SDsampSpT); |
676 |
|
if (r->crtype & SHADOW) { |
677 |
|
RAY tr; /* attempt to pass shadow ray */ |
678 |
|
if (rayorigin(&tr, TRANS, r, nd.cthru) < 0) |
679 |
< |
return(1); /* blocked */ |
679 |
> |
return(1); /* no through component */ |
680 |
|
VCOPY(tr.rdir, r->rdir); |
681 |
|
rayvalue(&tr); /* transmit with scaling */ |
682 |
|
multcolor(tr.rcol, tr.rcoef); |