13 |
|
#include "func.h" |
14 |
|
#include "bsdf.h" |
15 |
|
#include "random.h" |
16 |
+ |
#include "pmapmat.h" |
17 |
|
|
18 |
|
/* |
19 |
|
* Arguments to this material include optional diffuse colors. |
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 |
29 |
< |
* 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 */ |
80 |
|
SDData *sd; /* loaded BSDF data */ |
81 |
+ |
COLOR rdiff; /* diffuse reflection */ |
82 |
|
COLOR runsamp; /* BSDF hemispherical reflection */ |
83 |
< |
COLOR rdiff; /* added diffuse reflection */ |
83 |
> |
COLOR tdiff; /* diffuse transmission */ |
84 |
|
COLOR tunsamp; /* BSDF hemispherical transmission */ |
78 |
– |
COLOR tdiff; /* added diffuse transmission */ |
85 |
|
} BSDFDAT; /* BSDF material data */ |
86 |
|
|
87 |
|
#define cvt_sdcolor(cv, svp) ccy2rgb(&(svp)->spec, (svp)->cieY, cv) |
88 |
|
|
89 |
+ |
/* Compute "through" component color */ |
90 |
+ |
static void |
91 |
+ |
compute_through(BSDFDAT *ndp) |
92 |
+ |
{ |
93 |
+ |
#define NDIR2CHECK 13 |
94 |
+ |
static const float dir2check[NDIR2CHECK][2] = { |
95 |
+ |
{0, 0}, |
96 |
+ |
{-0.8, 0}, |
97 |
+ |
{0, 0.8}, |
98 |
+ |
{0, -0.8}, |
99 |
+ |
{0.8, 0}, |
100 |
+ |
{-0.8, 0.8}, |
101 |
+ |
{-0.8, -0.8}, |
102 |
+ |
{0.8, 0.8}, |
103 |
+ |
{0.8, -0.8}, |
104 |
+ |
{-1.6, 0}, |
105 |
+ |
{0, 1.6}, |
106 |
+ |
{0, -1.6}, |
107 |
+ |
{1.6, 0}, |
108 |
+ |
}; |
109 |
+ |
const double peak_over = 2.0; |
110 |
+ |
SDSpectralDF *dfp; |
111 |
+ |
FVECT pdir; |
112 |
+ |
double tomega, srchrad; |
113 |
+ |
COLOR vpeak, vsum; |
114 |
+ |
int nsum, i; |
115 |
+ |
SDError ec; |
116 |
+ |
|
117 |
+ |
setcolor(ndp->cthru, .0, .0, .0); /* starting assumption */ |
118 |
+ |
|
119 |
+ |
if (!(ndp->pr->crtype & (SPECULAR|AMBIENT|SHADOW))) |
120 |
+ |
return; /* simply don't need to know */ |
121 |
+ |
|
122 |
+ |
if (ndp->pr->rod > 0) |
123 |
+ |
dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb; |
124 |
+ |
else |
125 |
+ |
dfp = (ndp->sd->tb != NULL) ? ndp->sd->tb : ndp->sd->tf; |
126 |
+ |
|
127 |
+ |
if (dfp == NULL) |
128 |
+ |
return; /* no specular transmission */ |
129 |
+ |
if (bright(ndp->pr->pcol) <= FTINY) |
130 |
+ |
return; /* pattern is black, here */ |
131 |
+ |
srchrad = sqrt(dfp->minProjSA); /* else search for peak */ |
132 |
+ |
setcolor(vpeak, .0, .0, .0); |
133 |
+ |
setcolor(vsum, .0, .0, .0); |
134 |
+ |
nsum = 0; |
135 |
+ |
for (i = 0; i < NDIR2CHECK; i++) { |
136 |
+ |
FVECT tdir; |
137 |
+ |
SDValue sv; |
138 |
+ |
COLOR vcol; |
139 |
+ |
tdir[0] = -ndp->vray[0] + dir2check[i][0]*srchrad; |
140 |
+ |
tdir[1] = -ndp->vray[1] + dir2check[i][1]*srchrad; |
141 |
+ |
tdir[2] = -ndp->vray[2]; |
142 |
+ |
normalize(tdir); |
143 |
+ |
ec = SDevalBSDF(&sv, tdir, ndp->vray, ndp->sd); |
144 |
+ |
if (ec) |
145 |
+ |
goto baderror; |
146 |
+ |
cvt_sdcolor(vcol, &sv); |
147 |
+ |
addcolor(vsum, vcol); |
148 |
+ |
++nsum; |
149 |
+ |
if (bright(vcol) > bright(vpeak)) { |
150 |
+ |
copycolor(vpeak, vcol); |
151 |
+ |
VCOPY(pdir, tdir); |
152 |
+ |
} |
153 |
+ |
} |
154 |
+ |
ec = SDsizeBSDF(&tomega, pdir, ndp->vray, SDqueryMin, ndp->sd); |
155 |
+ |
if (ec) |
156 |
+ |
goto baderror; |
157 |
+ |
if (tomega > 1.5*dfp->minProjSA) |
158 |
+ |
return; /* not really a peak? */ |
159 |
+ |
if ((bright(vpeak) - ndp->sd->tLamb.cieY*(1./PI))*tomega <= .007) |
160 |
+ |
return; /* < 0.7% transmission */ |
161 |
+ |
for (i = 3; i--; ) /* remove peak from average */ |
162 |
+ |
colval(vsum,i) -= colval(vpeak,i); |
163 |
+ |
--nsum; |
164 |
+ |
if (peak_over*bright(vsum) >= nsum*bright(vpeak)) |
165 |
+ |
return; /* not peaky enough */ |
166 |
+ |
copycolor(ndp->cthru, vpeak); /* else use it */ |
167 |
+ |
scalecolor(ndp->cthru, tomega); |
168 |
+ |
multcolor(ndp->cthru, ndp->pr->pcol); /* modify by pattern */ |
169 |
+ |
return; |
170 |
+ |
baderror: |
171 |
+ |
objerror(ndp->mp, USER, transSDError(ec)); |
172 |
+ |
#undef NDIR2CHECK |
173 |
+ |
} |
174 |
+ |
|
175 |
|
/* Jitter ray sample according to projected solid angle and specjitter */ |
176 |
|
static void |
177 |
|
bsdf_jitter(FVECT vres, BSDFDAT *ndp, double sr_psa) |
186 |
|
normalize(vres); |
187 |
|
} |
188 |
|
|
189 |
< |
/* Evaluate BSDF for direct component, returning true if OK to proceed */ |
189 |
> |
/* Get BSDF specular for direct component, returning true if OK to proceed */ |
190 |
|
static int |
191 |
< |
direct_bsdf_OK(COLOR cval, FVECT ldir, double omega, BSDFDAT *ndp) |
191 |
> |
direct_specular_OK(COLOR cval, FVECT ldir, double omega, BSDFDAT *ndp) |
192 |
|
{ |
193 |
|
int nsamp, ok = 0; |
194 |
|
FVECT vsrc, vsmp, vjit; |
195 |
< |
double tomega; |
195 |
> |
double tomega, tomega2; |
196 |
|
double sf, tsr, sd[2]; |
197 |
< |
COLOR csmp; |
197 |
> |
COLOR csmp, cdiff; |
198 |
> |
double diffY; |
199 |
|
SDValue sv; |
200 |
|
SDError ec; |
201 |
|
int i; |
202 |
+ |
/* in case we fail */ |
203 |
+ |
setcolor(cval, .0, .0, .0); |
204 |
|
/* transform source direction */ |
205 |
|
if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone) |
206 |
|
return(0); |
207 |
< |
/* assign number of samples */ |
207 |
> |
/* will discount diffuse portion */ |
208 |
> |
switch ((vsrc[2] > 0)<<1 | (ndp->vray[2] > 0)) { |
209 |
> |
case 3: |
210 |
> |
if (ndp->sd->rf == NULL) |
211 |
> |
return(0); /* all diffuse */ |
212 |
> |
sv = ndp->sd->rLambFront; |
213 |
> |
break; |
214 |
> |
case 0: |
215 |
> |
if (ndp->sd->rb == NULL) |
216 |
> |
return(0); /* all diffuse */ |
217 |
> |
sv = ndp->sd->rLambBack; |
218 |
> |
break; |
219 |
> |
default: |
220 |
> |
if ((ndp->sd->tf == NULL) & (ndp->sd->tb == NULL)) |
221 |
> |
return(0); /* all diffuse */ |
222 |
> |
sv = ndp->sd->tLamb; |
223 |
> |
break; |
224 |
> |
} |
225 |
> |
if (sv.cieY > FTINY) { |
226 |
> |
diffY = sv.cieY *= 1./PI; |
227 |
> |
cvt_sdcolor(cdiff, &sv); |
228 |
> |
} else { |
229 |
> |
diffY = .0; |
230 |
> |
setcolor(cdiff, .0, .0, .0); |
231 |
> |
} |
232 |
> |
/* need projected solid angles */ |
233 |
> |
omega *= fabs(vsrc[2]); |
234 |
|
ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd); |
235 |
|
if (ec) |
236 |
|
goto baderror; |
237 |
|
/* check indirect over-counting */ |
238 |
< |
if (ndp->thick != 0 && ndp->pr->crtype & (SPECULAR|AMBIENT) |
239 |
< |
&& vsrc[2] > 0 ^ ndp->vray[2] > 0) { |
238 |
> |
if (ndp->pr->crtype & (SPECULAR|AMBIENT) |
239 |
> |
&& (vsrc[2] > 0) ^ (ndp->vray[2] > 0) |
240 |
> |
&& bright(ndp->cthru) > FTINY) { |
241 |
|
double dx = vsrc[0] + ndp->vray[0]; |
242 |
|
double dy = vsrc[1] + ndp->vray[1]; |
243 |
< |
if (dx*dx + dy*dy <= omega+tomega) |
243 |
> |
if (dx*dx + dy*dy <= (4./PI)*(omega + tomega + |
244 |
> |
2.*sqrt(omega*tomega))) |
245 |
|
return(0); |
246 |
|
} |
247 |
+ |
/* assign number of samples */ |
248 |
|
sf = specjitter * ndp->pr->rweight; |
249 |
< |
if (25.*tomega <= omega) |
249 |
> |
if (tomega <= .0) |
250 |
> |
nsamp = 1; |
251 |
> |
else if (25.*tomega <= omega) |
252 |
|
nsamp = 100.*sf + .5; |
253 |
|
else |
254 |
|
nsamp = 4.*sf*omega/tomega + .5; |
255 |
|
nsamp += !nsamp; |
256 |
< |
setcolor(cval, .0, .0, .0); /* sample our source area */ |
131 |
< |
sf = sqrt(omega); |
256 |
> |
sf = sqrt(omega); /* sample our source area */ |
257 |
|
tsr = sqrt(tomega); |
258 |
|
for (i = nsamp; i--; ) { |
259 |
|
VCOPY(vsmp, vsrc); /* jitter query directions */ |
261 |
|
multisamp(sd, 2, (i + frandom())/(double)nsamp); |
262 |
|
vsmp[0] += (sd[0] - .5)*sf; |
263 |
|
vsmp[1] += (sd[1] - .5)*sf; |
264 |
< |
if (normalize(vsmp) == 0) { |
140 |
< |
--nsamp; |
141 |
< |
continue; |
142 |
< |
} |
264 |
> |
normalize(vsmp); |
265 |
|
} |
266 |
|
bsdf_jitter(vjit, ndp, tsr); |
267 |
|
/* compute BSDF */ |
268 |
|
ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd); |
269 |
|
if (ec) |
270 |
|
goto baderror; |
271 |
< |
if (sv.cieY <= FTINY) /* worth using? */ |
272 |
< |
continue; |
271 |
> |
if (sv.cieY - diffY <= FTINY) |
272 |
> |
continue; /* no specular part */ |
273 |
> |
/* check for variable resolution */ |
274 |
> |
ec = SDsizeBSDF(&tomega2, vjit, vsmp, SDqueryMin, ndp->sd); |
275 |
> |
if (ec) |
276 |
> |
goto baderror; |
277 |
> |
if (tomega2 < .12*tomega) |
278 |
> |
continue; /* not safe to include */ |
279 |
|
cvt_sdcolor(csmp, &sv); |
280 |
< |
addcolor(cval, csmp); /* average it in */ |
280 |
> |
addcolor(cval, csmp); /* else average it in */ |
281 |
|
++ok; |
282 |
|
} |
283 |
< |
sf = 1./(double)nsamp; |
283 |
> |
if (!ok) /* no valid specular samples? */ |
284 |
> |
return(0); |
285 |
> |
|
286 |
> |
sf = 1./(double)ok; /* compute average BSDF */ |
287 |
|
scalecolor(cval, sf); |
288 |
< |
return(ok); |
288 |
> |
/* subtract diffuse contribution */ |
289 |
> |
for (i = 3*(diffY > FTINY); i--; ) |
290 |
> |
if ((colval(cval,i) -= colval(cdiff,i)) < .0) |
291 |
> |
colval(cval,i) = .0; |
292 |
> |
return(1); |
293 |
|
baderror: |
294 |
|
objerror(ndp->mp, USER, transSDError(ec)); |
295 |
|
return(0); /* gratis return */ |
317 |
|
|
318 |
|
if (ldot > 0 && bright(np->rdiff) > FTINY) { |
319 |
|
/* |
320 |
< |
* Compute added diffuse reflected component. |
320 |
> |
* Compute diffuse reflected component |
321 |
|
*/ |
322 |
|
copycolor(ctmp, np->rdiff); |
323 |
|
dtmp = ldot * omega * (1./PI); |
326 |
|
} |
327 |
|
if (ldot < 0 && bright(np->tdiff) > FTINY) { |
328 |
|
/* |
329 |
< |
* Compute added diffuse transmission. |
329 |
> |
* Compute diffuse transmission |
330 |
|
*/ |
331 |
|
copycolor(ctmp, np->tdiff); |
332 |
|
dtmp = -ldot * omega * (1.0/PI); |
333 |
|
scalecolor(ctmp, dtmp); |
334 |
|
addcolor(cval, ctmp); |
335 |
|
} |
336 |
+ |
if (ambRayInPmap(np->pr)) |
337 |
+ |
return; /* specular already in photon map */ |
338 |
|
/* |
339 |
< |
* Compute scattering coefficient using BSDF. |
339 |
> |
* Compute specular scattering coefficient using BSDF |
340 |
|
*/ |
341 |
< |
if (!direct_bsdf_OK(ctmp, ldir, omega, np)) |
341 |
> |
if (!direct_specular_OK(ctmp, ldir, omega, np)) |
342 |
|
return; |
343 |
< |
if (ldot > 0) { /* pattern only diffuse reflection */ |
207 |
< |
COLOR ctmp1, ctmp2; |
208 |
< |
dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY |
209 |
< |
: np->sd->rLambBack.cieY; |
210 |
< |
/* diffuse fraction */ |
211 |
< |
dtmp /= PI * bright(ctmp); |
212 |
< |
copycolor(ctmp2, np->pr->pcol); |
213 |
< |
scalecolor(ctmp2, dtmp); |
214 |
< |
setcolor(ctmp1, 1.-dtmp, 1.-dtmp, 1.-dtmp); |
215 |
< |
addcolor(ctmp1, ctmp2); |
216 |
< |
multcolor(ctmp, ctmp1); /* apply derated pattern */ |
217 |
< |
dtmp = ldot * omega; |
218 |
< |
} else { /* full pattern on transmission */ |
343 |
> |
if (ldot < 0) { /* pattern for specular transmission */ |
344 |
|
multcolor(ctmp, np->pr->pcol); |
345 |
|
dtmp = -ldot * omega; |
346 |
< |
} |
346 |
> |
} else |
347 |
> |
dtmp = ldot * omega; |
348 |
|
scalecolor(ctmp, dtmp); |
349 |
|
addcolor(cval, ctmp); |
350 |
|
} |
372 |
|
|
373 |
|
if (bright(np->rdiff) > FTINY) { |
374 |
|
/* |
375 |
< |
* Compute added diffuse reflected component. |
375 |
> |
* Compute diffuse reflected component |
376 |
|
*/ |
377 |
|
copycolor(ctmp, np->rdiff); |
378 |
|
dtmp = ldot * omega * (1./PI); |
379 |
|
scalecolor(ctmp, dtmp); |
380 |
|
addcolor(cval, ctmp); |
381 |
|
} |
382 |
+ |
if (ambRayInPmap(np->pr)) |
383 |
+ |
return; /* specular already in photon map */ |
384 |
|
/* |
385 |
< |
* Compute reflection coefficient using BSDF. |
385 |
> |
* Compute specular reflection coefficient using BSDF |
386 |
|
*/ |
387 |
< |
if (!direct_bsdf_OK(ctmp, ldir, omega, np)) |
387 |
> |
if (!direct_specular_OK(ctmp, ldir, omega, np)) |
388 |
|
return; |
261 |
– |
/* pattern only diffuse reflection */ |
262 |
– |
dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY |
263 |
– |
: np->sd->rLambBack.cieY; |
264 |
– |
dtmp /= PI * bright(ctmp); /* diffuse fraction */ |
265 |
– |
copycolor(ctmp2, np->pr->pcol); |
266 |
– |
scalecolor(ctmp2, dtmp); |
267 |
– |
setcolor(ctmp1, 1.-dtmp, 1.-dtmp, 1.-dtmp); |
268 |
– |
addcolor(ctmp1, ctmp2); |
269 |
– |
multcolor(ctmp, ctmp1); /* apply derated pattern */ |
389 |
|
dtmp = ldot * omega; |
390 |
|
scalecolor(ctmp, dtmp); |
391 |
|
addcolor(cval, ctmp); |
414 |
|
|
415 |
|
if (bright(np->tdiff) > FTINY) { |
416 |
|
/* |
417 |
< |
* Compute added diffuse transmission. |
417 |
> |
* Compute diffuse transmission |
418 |
|
*/ |
419 |
|
copycolor(ctmp, np->tdiff); |
420 |
|
dtmp = -ldot * omega * (1.0/PI); |
421 |
|
scalecolor(ctmp, dtmp); |
422 |
|
addcolor(cval, ctmp); |
423 |
|
} |
424 |
+ |
if (ambRayInPmap(np->pr)) |
425 |
+ |
return; /* specular already in photon map */ |
426 |
|
/* |
427 |
< |
* Compute scattering coefficient using BSDF. |
427 |
> |
* Compute specular scattering coefficient using BSDF |
428 |
|
*/ |
429 |
< |
if (!direct_bsdf_OK(ctmp, ldir, omega, np)) |
429 |
> |
if (!direct_specular_OK(ctmp, ldir, omega, np)) |
430 |
|
return; |
431 |
|
/* full pattern on transmission */ |
432 |
|
multcolor(ctmp, np->pr->pcol); |
482 |
|
continue; /* Russian roulette victim */ |
483 |
|
} |
484 |
|
/* need to offset origin? */ |
485 |
< |
if (ndp->thick != 0 && ndp->pr->rod > 0 ^ vsmp[2] > 0) |
485 |
> |
if (ndp->thick != 0 && (ndp->pr->rod > 0) ^ (vsmp[2] > 0)) |
486 |
|
VSUM(sr.rorg, sr.rorg, ndp->pr->ron, -ndp->thick); |
487 |
|
rayvalue(&sr); /* send & evaluate sample */ |
488 |
|
multcolor(sr.rcol, sr.rcoef); |
501 |
|
|
502 |
|
if (sflags == SDsampSpT) { |
503 |
|
unsc = ndp->tunsamp; |
504 |
< |
dfp = ndp->sd->tf; |
505 |
< |
cvt_sdcolor(unsc, &ndp->sd->tLamb); |
504 |
> |
if (ndp->pr->rod > 0) |
505 |
> |
dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb; |
506 |
> |
else |
507 |
> |
dfp = (ndp->sd->tb != NULL) ? ndp->sd->tb : ndp->sd->tf; |
508 |
|
} else /* sflags == SDsampSpR */ { |
509 |
|
unsc = ndp->runsamp; |
510 |
< |
if (ndp->pr->rod > 0) { |
510 |
> |
if (ndp->pr->rod > 0) |
511 |
|
dfp = ndp->sd->rf; |
512 |
< |
cvt_sdcolor(unsc, &ndp->sd->rLambFront); |
390 |
< |
} else { |
512 |
> |
else |
513 |
|
dfp = ndp->sd->rb; |
392 |
– |
cvt_sdcolor(unsc, &ndp->sd->rLambBack); |
393 |
– |
} |
514 |
|
} |
515 |
< |
multcolor(unsc, ndp->pr->pcol); |
515 |
> |
setcolor(unsc, 0., 0., 0.); |
516 |
|
if (dfp == NULL) /* no specular component? */ |
517 |
|
return(0); |
518 |
|
/* below sampling threshold? */ |
520 |
|
if (dfp->maxHemi > FTINY) { /* XXX no color from BSDF */ |
521 |
|
FVECT vjit; |
522 |
|
double d; |
403 |
– |
COLOR ctmp; |
523 |
|
bsdf_jitter(vjit, ndp, ndp->sr_vpsa[1]); |
524 |
|
d = SDdirectHemi(vjit, sflags, ndp->sd); |
525 |
|
if (sflags == SDsampSpT) { |
526 |
< |
copycolor(ctmp, ndp->pr->pcol); |
527 |
< |
scalecolor(ctmp, d); |
526 |
> |
copycolor(unsc, ndp->pr->pcol); |
527 |
> |
scalecolor(unsc, d); |
528 |
|
} else /* no pattern on reflection */ |
529 |
< |
setcolor(ctmp, d, d, d); |
411 |
< |
addcolor(unsc, ctmp); |
529 |
> |
setcolor(unsc, d, d, d); |
530 |
|
} |
531 |
|
return(0); |
532 |
|
} |
559 |
|
hitfront = (r->rod > 0); |
560 |
|
/* load cal file */ |
561 |
|
mf = getfunc(m, 5, 0x1d, 1); |
562 |
+ |
setfunc(m, r); |
563 |
|
/* get thickness */ |
564 |
|
nd.thick = evalue(mf->ep[0]); |
565 |
|
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
566 |
|
nd.thick = .0; |
567 |
< |
/* check shadow */ |
568 |
< |
if (r->crtype & SHADOW) { |
569 |
< |
if (nd.thick != 0) |
570 |
< |
raytrans(r); /* pass-through */ |
452 |
< |
return(1); /* or shadow */ |
567 |
> |
/* check backface visibility */ |
568 |
> |
if (!hitfront & !backvis) { |
569 |
> |
raytrans(r); |
570 |
> |
return(1); |
571 |
|
} |
572 |
|
/* check other rays to pass */ |
573 |
< |
if (nd.thick != 0 && (!(r->crtype & (SPECULAR|AMBIENT)) || |
574 |
< |
nd.thick > 0 ^ hitfront)) { |
573 |
> |
if (nd.thick != 0 && (r->crtype & SHADOW || |
574 |
> |
!(r->crtype & (SPECULAR|AMBIENT)) || |
575 |
> |
(nd.thick > 0) ^ hitfront)) { |
576 |
|
raytrans(r); /* hide our proxy */ |
577 |
|
return(1); |
578 |
|
} |
579 |
+ |
nd.mp = m; |
580 |
+ |
nd.pr = r; |
581 |
|
/* get BSDF data */ |
582 |
|
nd.sd = loadBSDF(m->oargs.sarg[1]); |
583 |
+ |
/* early shadow check */ |
584 |
+ |
if (r->crtype & SHADOW && (nd.sd->tf == NULL) & (nd.sd->tb == NULL)) |
585 |
+ |
return(1); |
586 |
|
/* diffuse reflectance */ |
587 |
|
if (hitfront) { |
588 |
< |
if (m->oargs.nfargs < 3) |
589 |
< |
setcolor(nd.rdiff, .0, .0, .0); |
590 |
< |
else |
467 |
< |
setcolor(nd.rdiff, m->oargs.farg[0], |
588 |
> |
cvt_sdcolor(nd.rdiff, &nd.sd->rLambFront); |
589 |
> |
if (m->oargs.nfargs >= 3) { |
590 |
> |
setcolor(ctmp, m->oargs.farg[0], |
591 |
|
m->oargs.farg[1], |
592 |
|
m->oargs.farg[2]); |
593 |
+ |
addcolor(nd.rdiff, ctmp); |
594 |
+ |
} |
595 |
|
} else { |
596 |
< |
if (m->oargs.nfargs < 6) { /* check invisible backside */ |
597 |
< |
if (!backvis && (nd.sd->rb == NULL) & |
598 |
< |
(nd.sd->tf == NULL)) { |
474 |
< |
SDfreeCache(nd.sd); |
475 |
< |
raytrans(r); |
476 |
< |
return(1); |
477 |
< |
} |
478 |
< |
setcolor(nd.rdiff, .0, .0, .0); |
479 |
< |
} else |
480 |
< |
setcolor(nd.rdiff, m->oargs.farg[3], |
596 |
> |
cvt_sdcolor(nd.rdiff, &nd.sd->rLambBack); |
597 |
> |
if (m->oargs.nfargs >= 6) { |
598 |
> |
setcolor(ctmp, m->oargs.farg[3], |
599 |
|
m->oargs.farg[4], |
600 |
|
m->oargs.farg[5]); |
601 |
+ |
addcolor(nd.rdiff, ctmp); |
602 |
+ |
} |
603 |
|
} |
604 |
|
/* diffuse transmittance */ |
605 |
< |
if (m->oargs.nfargs < 9) |
606 |
< |
setcolor(nd.tdiff, .0, .0, .0); |
607 |
< |
else |
488 |
< |
setcolor(nd.tdiff, m->oargs.farg[6], |
605 |
> |
cvt_sdcolor(nd.tdiff, &nd.sd->tLamb); |
606 |
> |
if (m->oargs.nfargs >= 9) { |
607 |
> |
setcolor(ctmp, m->oargs.farg[6], |
608 |
|
m->oargs.farg[7], |
609 |
|
m->oargs.farg[8]); |
610 |
< |
nd.mp = m; |
611 |
< |
nd.pr = r; |
610 |
> |
addcolor(nd.tdiff, ctmp); |
611 |
> |
} |
612 |
|
/* get modifiers */ |
613 |
|
raytexture(r, m->omod); |
614 |
|
/* modify diffuse values */ |
623 |
|
multv3(upvec, upvec, mf->fxp->xfm); |
624 |
|
nd.thick *= mf->fxp->sca; |
625 |
|
} |
626 |
+ |
if (r->rox != NULL) { |
627 |
+ |
multv3(upvec, upvec, r->rox->f.xfm); |
628 |
+ |
nd.thick *= r->rox->f.sca; |
629 |
+ |
} |
630 |
|
raynormal(nd.pnorm, r); |
631 |
|
/* compute local BSDF xform */ |
632 |
|
ec = SDcompXform(nd.toloc, nd.pnorm, upvec); |
636 |
|
nd.vray[2] = -r->rdir[2]; |
637 |
|
ec = SDmapDir(nd.vray, nd.toloc, nd.vray); |
638 |
|
} |
516 |
– |
if (!ec) |
517 |
– |
ec = SDinvXform(nd.fromloc, nd.toloc); |
639 |
|
if (ec) { |
640 |
|
objerror(m, WARNING, "Illegal orientation vector"); |
641 |
|
return(1); |
642 |
|
} |
643 |
< |
/* determine BSDF resolution */ |
644 |
< |
ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, SDqueryMin+SDqueryMax, nd.sd); |
643 |
> |
compute_through(&nd); /* compute through component */ |
644 |
> |
if (r->crtype & SHADOW) { |
645 |
> |
RAY tr; /* attempt to pass shadow ray */ |
646 |
> |
if (rayorigin(&tr, TRANS, r, nd.cthru) < 0) |
647 |
> |
return(1); /* blocked */ |
648 |
> |
VCOPY(tr.rdir, r->rdir); |
649 |
> |
rayvalue(&tr); /* transmit with scaling */ |
650 |
> |
multcolor(tr.rcol, tr.rcoef); |
651 |
> |
copycolor(r->rcol, tr.rcol); |
652 |
> |
return(1); /* we're done */ |
653 |
> |
} |
654 |
> |
ec = SDinvXform(nd.fromloc, nd.toloc); |
655 |
> |
if (!ec) /* determine BSDF resolution */ |
656 |
> |
ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, |
657 |
> |
SDqueryMin+SDqueryMax, nd.sd); |
658 |
|
if (ec) |
659 |
|
objerror(m, USER, transSDError(ec)); |
660 |
|
|
701 |
|
flipsurface(r); |
702 |
|
} |
703 |
|
/* add direct component */ |
704 |
< |
if ((bright(nd.tdiff) <= FTINY) & (nd.sd->tf == NULL)) { |
704 |
> |
if ((bright(nd.tdiff) <= FTINY) & (nd.sd->tf == NULL) & |
705 |
> |
(nd.sd->tb == NULL)) { |
706 |
|
direct(r, dir_brdf, &nd); /* reflection only */ |
707 |
|
} else if (nd.thick == 0) { |
708 |
|
direct(r, dir_bsdf, &nd); /* thin surface scattering */ |