23 |
|
* (opposite the surface normal) to bypass any intervening geometry. |
24 |
|
* Translation only affects scattered, non-source-directed samples. |
25 |
|
* A non-zero thickness has the further side-effect that an unscattered |
26 |
< |
* (view) ray will pass right through our material if it has any |
27 |
< |
* non-diffuse transmission, making the BSDF surface invisible. This |
28 |
< |
* shows the proxied geometry instead. Thickness has the further |
29 |
< |
* effect of turning off reflection on the hidden side so that rays |
30 |
< |
* heading in the opposite direction pass unimpeded through the BSDF |
26 |
> |
* (view) ray will pass right through our material, making the BSDF |
27 |
> |
* surface invisible and showing the proxied geometry instead. Thickness |
28 |
> |
* has the further effect of turning off reflection on the reverse side so |
29 |
> |
* rays heading in the opposite direction pass unimpeded through the BSDF |
30 |
|
* surface. A paired surface may be placed on the opposide side of |
31 |
|
* the detail geometry, less than this thickness away, if a two-way |
32 |
|
* proxy is desired. Note that the sign of the thickness is important. |
35 |
|
* hides geometry in front of the surface when rays hit from behind, |
36 |
|
* and applies only the transmission and backside reflectance properties. |
37 |
|
* Reflection is ignored on the hidden side, as those rays pass through. |
38 |
+ |
* When thickness is set to zero, shadow rays will be blocked unless |
39 |
+ |
* a BTDF has a strong "through" component in the source direction. |
40 |
+ |
* A separate test prevents over-counting by dropping specular & ambient |
41 |
+ |
* samples that are too close to this "through" direction. The same |
42 |
+ |
* restriction applies for the proxy case (thickness != 0). |
43 |
|
* The "up" vector for the BSDF is given by three variables, defined |
44 |
|
* (along with the thickness) by the named function file, or '.' if none. |
45 |
|
* Together with the surface normal, this defines the local coordinate |
47 |
|
* We do not reorient the surface, so if the BSDF has no back-side |
48 |
|
* reflectance and none is given in the real arguments, a BSDF surface |
49 |
|
* with zero thickness will appear black when viewed from behind |
50 |
< |
* unless backface visibility is off. |
50 |
> |
* unless backface visibility is on, when it becomes invisible. |
51 |
|
* The diffuse arguments are added to components in the BSDF file, |
52 |
|
* not multiplied. However, patterns affect this material as a multiplier |
53 |
|
* on everything except non-diffuse reflection. |
63 |
|
/* |
64 |
|
* Note that our reverse ray-tracing process means that the positions |
65 |
|
* of incoming and outgoing vectors may be reversed in our calls |
66 |
< |
* to the BSDF library. This is fine, since the bidirectional nature |
66 |
> |
* to the BSDF library. This is usually fine, since the bidirectional nature |
67 |
|
* of the BSDF (that's what the 'B' stands for) means it all works out. |
68 |
|
*/ |
69 |
|
|
76 |
|
RREAL toloc[3][3]; /* world to local BSDF coords */ |
77 |
|
RREAL fromloc[3][3]; /* local BSDF coords to world */ |
78 |
|
double thick; /* surface thickness */ |
79 |
< |
COLOR cthru; /* through component multiplier */ |
79 |
> |
COLOR cthru; /* "through" component multiplier */ |
80 |
|
SDData *sd; /* loaded BSDF data */ |
81 |
|
COLOR rdiff; /* diffuse reflection */ |
82 |
|
COLOR tdiff; /* diffuse transmission */ |
84 |
|
|
85 |
|
#define cvt_sdcolor(cv, svp) ccy2rgb(&(svp)->spec, (svp)->cieY, cv) |
86 |
|
|
87 |
< |
/* Compute through component color */ |
87 |
> |
/* Compute "through" component color */ |
88 |
|
static void |
89 |
|
compute_through(BSDFDAT *ndp) |
90 |
|
{ |
114 |
|
|
115 |
|
setcolor(ndp->cthru, .0, .0, .0); /* starting assumption */ |
116 |
|
|
117 |
+ |
if (!(ndp->pr->crtype & (SPECULAR|AMBIENT|SHADOW))) |
118 |
+ |
return; /* simply don't need to know */ |
119 |
+ |
|
120 |
|
if (ndp->pr->rod > 0) |
121 |
|
dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb; |
122 |
|
else |
137 |
|
tdir[0] = -ndp->vray[0] + dir2check[i][0]*srchrad; |
138 |
|
tdir[1] = -ndp->vray[1] + dir2check[i][1]*srchrad; |
139 |
|
tdir[2] = -ndp->vray[2]; |
140 |
< |
if (normalize(tdir) == 0) |
134 |
< |
continue; |
140 |
> |
normalize(tdir); |
141 |
|
ec = SDevalBSDF(&sv, tdir, ndp->vray, ndp->sd); |
142 |
|
if (ec) |
143 |
|
goto baderror; |
154 |
|
goto baderror; |
155 |
|
if (tomega > 1.5*dfp->minProjSA) |
156 |
|
return; /* not really a peak? */ |
157 |
< |
if ((bright(vpeak) - ndp->sd->tLamb.cieY*(1./PI))*tomega <= .001) |
158 |
< |
return; /* < 0.1% transmission */ |
157 |
> |
if ((bright(vpeak) - ndp->sd->tLamb.cieY*(1./PI))*tomega <= .007) |
158 |
> |
return; /* < 0.7% transmission */ |
159 |
|
for (i = 3; i--; ) /* remove peak from average */ |
160 |
|
colval(vsum,i) -= colval(vpeak,i); |
161 |
|
--nsum; |
190 |
|
{ |
191 |
|
int nsamp, ok = 0; |
192 |
|
FVECT vsrc, vsmp, vjit; |
193 |
< |
double tomega; |
193 |
> |
double tomega, tomega2; |
194 |
|
double sf, tsr, sd[2]; |
195 |
|
COLOR csmp, cdiff; |
196 |
|
double diffY; |
197 |
|
SDValue sv; |
198 |
|
SDError ec; |
199 |
|
int i; |
200 |
+ |
/* in case we fail */ |
201 |
+ |
setcolor(cval, .0, .0, .0); |
202 |
|
/* transform source direction */ |
203 |
|
if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone) |
204 |
|
return(0); |
227 |
|
diffY = .0; |
228 |
|
setcolor(cdiff, .0, .0, .0); |
229 |
|
} |
230 |
< |
/* assign number of samples */ |
230 |
> |
/* need projected solid angles */ |
231 |
> |
omega *= fabs(vsrc[2]); |
232 |
|
ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd); |
233 |
|
if (ec) |
234 |
|
goto baderror; |
235 |
|
/* check indirect over-counting */ |
236 |
< |
if ((ndp->thick != 0 || bright(ndp->cthru) > FTINY) |
237 |
< |
&& ndp->pr->crtype & (SPECULAR|AMBIENT) |
238 |
< |
&& (vsrc[2] > 0) ^ (ndp->vray[2] > 0)) { |
236 |
> |
if (ndp->pr->crtype & (SPECULAR|AMBIENT) |
237 |
> |
&& (vsrc[2] > 0) ^ (ndp->vray[2] > 0) |
238 |
> |
&& bright(ndp->cthru) > FTINY) { |
239 |
|
double dx = vsrc[0] + ndp->vray[0]; |
240 |
|
double dy = vsrc[1] + ndp->vray[1]; |
241 |
< |
if (dx*dx + dy*dy <= omega+tomega) |
241 |
> |
if (dx*dx + dy*dy <= (4./PI)*(omega + tomega + |
242 |
> |
2.*sqrt(omega*tomega))) |
243 |
|
return(0); |
244 |
|
} |
245 |
+ |
/* assign number of samples */ |
246 |
|
sf = specjitter * ndp->pr->rweight; |
247 |
|
if (tomega <= .0) |
248 |
|
nsamp = 1; |
251 |
|
else |
252 |
|
nsamp = 4.*sf*omega/tomega + .5; |
253 |
|
nsamp += !nsamp; |
254 |
< |
setcolor(cval, .0, .0, .0); /* sample our source area */ |
244 |
< |
sf = sqrt(omega); |
254 |
> |
sf = sqrt(omega); /* sample our source area */ |
255 |
|
tsr = sqrt(tomega); |
256 |
|
for (i = nsamp; i--; ) { |
257 |
|
VCOPY(vsmp, vsrc); /* jitter query directions */ |
259 |
|
multisamp(sd, 2, (i + frandom())/(double)nsamp); |
260 |
|
vsmp[0] += (sd[0] - .5)*sf; |
261 |
|
vsmp[1] += (sd[1] - .5)*sf; |
262 |
< |
if (normalize(vsmp) == 0) { |
253 |
< |
--nsamp; |
254 |
< |
continue; |
255 |
< |
} |
262 |
> |
normalize(vsmp); |
263 |
|
} |
264 |
|
bsdf_jitter(vjit, ndp, tsr); |
265 |
|
/* compute BSDF */ |
266 |
|
ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd); |
267 |
|
if (ec) |
268 |
|
goto baderror; |
269 |
< |
if (sv.cieY - diffY <= FTINY) { |
263 |
< |
addcolor(cval, cdiff); |
269 |
> |
if (sv.cieY - diffY <= FTINY) |
270 |
|
continue; /* no specular part */ |
271 |
< |
} |
271 |
> |
/* check for variable resolution */ |
272 |
> |
ec = SDsizeBSDF(&tomega2, vjit, vsmp, SDqueryMin, ndp->sd); |
273 |
> |
if (ec) |
274 |
> |
goto baderror; |
275 |
> |
if (tomega2 < .12*tomega) |
276 |
> |
continue; /* not safe to include */ |
277 |
|
cvt_sdcolor(csmp, &sv); |
278 |
|
addcolor(cval, csmp); /* else average it in */ |
279 |
|
++ok; |
280 |
|
} |
281 |
< |
if (!ok) { |
282 |
< |
setcolor(cval, .0, .0, .0); |
283 |
< |
return(0); /* no valid specular samples */ |
284 |
< |
} |
274 |
< |
sf = 1./(double)nsamp; |
281 |
> |
if (!ok) /* no valid specular samples? */ |
282 |
> |
return(0); |
283 |
> |
|
284 |
> |
sf = 1./(double)ok; /* compute average BSDF */ |
285 |
|
scalecolor(cval, sf); |
286 |
|
/* subtract diffuse contribution */ |
287 |
|
for (i = 3*(diffY > FTINY); i--; ) |