68 |
|
FVECT pnorm; /* perturbed surface normal */ |
69 |
|
FVECT vray; /* local outgoing (return) vector */ |
70 |
|
double sr_vpsa[2]; /* sqrt of BSDF projected solid angle extrema */ |
71 |
– |
double thru_psa; /* through direction projected solid angle */ |
71 |
|
RREAL toloc[3][3]; /* world to local BSDF coords */ |
72 |
|
RREAL fromloc[3][3]; /* local BSDF coords to world */ |
73 |
|
double thick; /* surface thickness */ |
98 |
|
|
99 |
|
/* Evaluate BSDF for direct component, returning true if OK to proceed */ |
100 |
|
static int |
101 |
< |
direct_bsdf_OK(COLOR cval, FVECT ldir, BSDFDAT *ndp) |
101 |
> |
direct_bsdf_OK(COLOR cval, FVECT ldir, double omega, BSDFDAT *ndp) |
102 |
|
{ |
103 |
< |
FVECT vsrc, vjit; |
103 |
> |
int nsamp, ok = 0; |
104 |
> |
FVECT vsrc, vsmp, vjit; |
105 |
> |
double tomega; |
106 |
> |
double sf, sd[2]; |
107 |
> |
COLOR csmp; |
108 |
|
SDValue sv; |
109 |
|
SDError ec; |
110 |
+ |
int i; |
111 |
|
/* transform source direction */ |
112 |
|
if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone) |
113 |
|
return(0); |
114 |
< |
/* jitter query direction */ |
115 |
< |
bsdf_jitter(vjit, ndp, 0); |
116 |
< |
/* avoid indirect over-counting */ |
117 |
< |
if (ndp->thick != 0 && ndp->pr->crtype & (SPECULAR|AMBIENT) && |
118 |
< |
vsrc[2] > 0 ^ vjit[2] > 0) { |
119 |
< |
double dx = vsrc[0] + vjit[0]; |
116 |
< |
double dy = vsrc[1] + vjit[1]; |
117 |
< |
if (dx*dx + dy*dy <= ndp->thru_psa) |
114 |
> |
/* check indirect over-counting */ |
115 |
> |
if (ndp->thick != 0 && ndp->pr->crtype & (SPECULAR|AMBIENT) |
116 |
> |
&& vsrc[2] > 0 ^ ndp->vray[2] > 0) { |
117 |
> |
double dx = vsrc[0] + ndp->vray[0]; |
118 |
> |
double dy = vsrc[1] + ndp->vray[1]; |
119 |
> |
if (dx*dx + dy*dy <= omega*(1./PI)) |
120 |
|
return(0); |
121 |
|
} |
122 |
< |
ec = SDevalBSDF(&sv, vjit, vsrc, ndp->sd); |
122 |
> |
/* get local BSDF resolution */ |
123 |
> |
ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd); |
124 |
|
if (ec) |
125 |
< |
objerror(ndp->mp, USER, transSDError(ec)); |
126 |
< |
|
127 |
< |
if (sv.cieY <= FTINY) /* not worth using? */ |
128 |
< |
return(0); |
129 |
< |
/* else we're good to go */ |
130 |
< |
cvt_sdcolor(cval, &sv); |
131 |
< |
return(1); |
125 |
> |
goto baderror; |
126 |
> |
/* assign number of samples */ |
127 |
> |
if (tomega <= omega*.02) |
128 |
> |
nsamp = 50; |
129 |
> |
else |
130 |
> |
nsamp = 2.*omega/tomega + 1.; |
131 |
> |
sf = sqrt(omega); |
132 |
> |
setcolor(cval, .0, .0, .0); /* sample our source area */ |
133 |
> |
for (i = nsamp; i--; ) { |
134 |
> |
VCOPY(vsmp, vsrc); /* jitter query directions */ |
135 |
> |
if (nsamp > 1) { |
136 |
> |
multisamp(sd, 2, (i + frandom())/(double)nsamp); |
137 |
> |
vsmp[0] += (sd[0] - .5)*sf; |
138 |
> |
vsmp[1] += (sd[1] - .5)*sf; |
139 |
> |
if (normalize(vsmp) == 0) { |
140 |
> |
--nsamp; |
141 |
> |
continue; |
142 |
> |
} |
143 |
> |
} |
144 |
> |
bsdf_jitter(vjit, ndp, 0); |
145 |
> |
/* compute BSDF */ |
146 |
> |
ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd); |
147 |
> |
if (ec) |
148 |
> |
goto baderror; |
149 |
> |
if (sv.cieY <= FTINY) /* worth using? */ |
150 |
> |
continue; |
151 |
> |
cvt_sdcolor(csmp, &sv); |
152 |
> |
addcolor(cval, csmp); /* average it in */ |
153 |
> |
++ok; |
154 |
> |
} |
155 |
> |
sf = 1./(double)nsamp; |
156 |
> |
scalecolor(cval, sf); |
157 |
> |
return(ok); |
158 |
> |
baderror: |
159 |
> |
objerror(ndp->mp, USER, transSDError(ec)); |
160 |
|
} |
161 |
|
|
162 |
|
/* Compute source contribution for BSDF (reflected & transmitted) */ |
200 |
|
/* |
201 |
|
* Compute scattering coefficient using BSDF. |
202 |
|
*/ |
203 |
< |
if (!direct_bsdf_OK(ctmp, ldir, np)) |
203 |
> |
if (!direct_bsdf_OK(ctmp, ldir, omega, np)) |
204 |
|
return; |
205 |
|
if (ldot > 0) { /* pattern only diffuse reflection */ |
206 |
|
COLOR ctmp1, ctmp2; |
255 |
|
/* |
256 |
|
* Compute reflection coefficient using BSDF. |
257 |
|
*/ |
258 |
< |
if (!direct_bsdf_OK(ctmp, ldir, np)) |
258 |
> |
if (!direct_bsdf_OK(ctmp, ldir, omega, np)) |
259 |
|
return; |
260 |
|
/* pattern only diffuse reflection */ |
261 |
|
dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY |
304 |
|
/* |
305 |
|
* Compute scattering coefficient using BSDF. |
306 |
|
*/ |
307 |
< |
if (!direct_bsdf_OK(ctmp, ldir, np)) |
307 |
> |
if (!direct_bsdf_OK(ctmp, ldir, omega, np)) |
308 |
|
return; |
309 |
|
/* full pattern on transmission */ |
310 |
|
multcolor(ctmp, np->pr->pcol); |
516 |
|
if (!ec) |
517 |
|
ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, |
518 |
|
SDqueryMin+SDqueryMax, nd.sd); |
488 |
– |
nd.thru_psa = .0; |
489 |
– |
if (!ec && nd.thick != 0 && r->crtype & (SPECULAR|AMBIENT)) { |
490 |
– |
FVECT vthru; |
491 |
– |
vthru[0] = -nd.vray[0]; |
492 |
– |
vthru[1] = -nd.vray[1]; |
493 |
– |
vthru[2] = -nd.vray[2]; |
494 |
– |
ec = SDsizeBSDF(&nd.thru_psa, nd.vray, vthru, |
495 |
– |
SDqueryMin, nd.sd); |
496 |
– |
} |
519 |
|
if (ec) { |
520 |
|
objerror(m, WARNING, transSDError(ec)); |
521 |
|
SDfreeCache(nd.sd); |