50 |
|
* Arguments for MAT_BSDF are: |
51 |
|
* 6+ thick BSDFfile ux uy uz funcfile transform |
52 |
|
* 0 |
53 |
< |
* 0|3|9 rdf gdf bdf |
53 |
> |
* 0|3|6|9 rdf gdf bdf |
54 |
|
* rdb gdb bdb |
55 |
|
* rdt gdt bdt |
56 |
|
*/ |
67 |
|
RAY *pr; /* intersected ray */ |
68 |
|
FVECT pnorm; /* perturbed surface normal */ |
69 |
|
FVECT vray; /* local outgoing (return) vector */ |
70 |
< |
double sr_vpsa; /* sqrt of BSDF projected solid angle */ |
70 |
> |
double sr_vpsa[2]; /* sqrt of BSDF projected solid angle extrema */ |
71 |
> |
double thru_psa; /* through direction projected solid angle */ |
72 |
|
RREAL toloc[3][3]; /* world to local BSDF coords */ |
73 |
|
RREAL fromloc[3][3]; /* local BSDF coords to world */ |
74 |
|
double thick; /* surface thickness */ |
83 |
|
|
84 |
|
/* Jitter ray sample according to projected solid angle and specjitter */ |
85 |
|
static void |
86 |
< |
bsdf_jitter(FVECT vres, BSDFDAT *ndp) |
86 |
> |
bsdf_jitter(FVECT vres, BSDFDAT *ndp, int domax) |
87 |
|
{ |
88 |
< |
double sr_psa = ndp->sr_vpsa; |
88 |
> |
double sr_psa = ndp->sr_vpsa[domax]; |
89 |
|
|
90 |
|
VCOPY(vres, ndp->vray); |
91 |
|
if (specjitter < 1.) |
108 |
|
if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone) |
109 |
|
return(0); |
110 |
|
/* jitter query direction */ |
111 |
< |
bsdf_jitter(vjit, ndp); |
111 |
> |
bsdf_jitter(vjit, ndp, 0); |
112 |
|
/* avoid indirect over-counting */ |
113 |
< |
if (ndp->thick != .0 && ndp->pr->crtype & (SPECULAR|AMBIENT) && |
114 |
< |
vsrc[2] > .0 ^ vjit[2] > .0) { |
113 |
> |
if (ndp->thick != 0 && ndp->pr->crtype & (SPECULAR|AMBIENT) && |
114 |
> |
vsrc[2] > 0 ^ vjit[2] > 0) { |
115 |
|
double dx = vsrc[0] + vjit[0]; |
116 |
|
double dy = vsrc[1] + vjit[1]; |
117 |
< |
if (dx*dx + dy*dy <= ndp->sr_vpsa*ndp->sr_vpsa) |
117 |
> |
if (dx*dx + dy*dy <= ndp->thru_psa) |
118 |
|
return(0); |
119 |
|
} |
120 |
|
ec = SDevalBSDF(&sv, vjit, vsrc, ndp->sd); |
148 |
|
if ((-FTINY <= ldot) & (ldot <= FTINY)) |
149 |
|
return; |
150 |
|
|
151 |
< |
if (ldot > .0 && bright(np->rdiff) > FTINY) { |
151 |
> |
if (ldot > 0 && bright(np->rdiff) > FTINY) { |
152 |
|
/* |
153 |
|
* Compute added diffuse reflected component. |
154 |
|
*/ |
157 |
|
scalecolor(ctmp, dtmp); |
158 |
|
addcolor(cval, ctmp); |
159 |
|
} |
160 |
< |
if (ldot < .0 && bright(np->tdiff) > FTINY) { |
160 |
> |
if (ldot < 0 && bright(np->tdiff) > FTINY) { |
161 |
|
/* |
162 |
|
* Compute added diffuse transmission. |
163 |
|
*/ |
171 |
|
*/ |
172 |
|
if (!direct_bsdf_OK(ctmp, ldir, np)) |
173 |
|
return; |
174 |
< |
if (ldot > .0) { /* pattern only diffuse reflection */ |
174 |
> |
if (ldot > 0) { /* pattern only diffuse reflection */ |
175 |
|
COLOR ctmp1, ctmp2; |
176 |
< |
dtmp = (np->pr->rod > .0) ? np->sd->rLambFront.cieY |
176 |
> |
dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY |
177 |
|
: np->sd->rLambBack.cieY; |
178 |
|
/* diffuse fraction */ |
179 |
|
dtmp /= PI * bright(ctmp); |
227 |
|
if (!direct_bsdf_OK(ctmp, ldir, np)) |
228 |
|
return; |
229 |
|
/* pattern only diffuse reflection */ |
230 |
< |
dtmp = (np->pr->rod > .0) ? np->sd->rLambFront.cieY |
230 |
> |
dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY |
231 |
|
: np->sd->rLambBack.cieY; |
232 |
|
dtmp /= PI * bright(ctmp); /* diffuse fraction */ |
233 |
|
copycolor(ctmp2, np->pr->pcol); |
304 |
|
for (ntrials = 0; nsent < nstarget && ntrials < 9*nstarget; ntrials++) { |
305 |
|
SDerrorDetail[0] = '\0'; |
306 |
|
/* sample direction & coef. */ |
307 |
< |
bsdf_jitter(vjit, ndp); |
307 |
> |
bsdf_jitter(vjit, ndp, 0); |
308 |
|
ec = SDsampComponent(&bsv, vsmp, vjit, ntrials ? frandom() |
309 |
|
: urand(ilhash(dimlist,ndims)+samplendx), dcp); |
310 |
|
if (ec) |
316 |
|
if (SDmapDir(sr.rdir, ndp->fromloc, vsmp) != SDEnone) |
317 |
|
break; |
318 |
|
/* unintentional penetration? */ |
319 |
< |
if (DOT(sr.rdir, ndp->pr->ron) > .0 ^ vsmp[2] > .0) |
319 |
> |
if (DOT(sr.rdir, ndp->pr->ron) > 0 ^ vsmp[2] > 0) |
320 |
|
continue; |
321 |
|
/* spawn a specular ray */ |
322 |
|
if (nstarget > 1) |
331 |
|
continue; |
332 |
|
} |
333 |
|
/* need to offset origin? */ |
334 |
< |
if (ndp->thick != .0 && ndp->pr->rod > .0 ^ vsmp[2] > .0) |
334 |
> |
if (ndp->thick != 0 && ndp->pr->rod > 0 ^ vsmp[2] > 0) |
335 |
|
VSUM(sr.rorg, sr.rorg, ndp->pr->ron, -ndp->thick); |
336 |
|
rayvalue(&sr); /* send & evaluate sample */ |
337 |
|
multcolor(sr.rcol, sr.rcoef); |
355 |
|
cvt_sdcolor(unsc, &ndp->sd->tLamb); |
356 |
|
} else /* sflags == SDsampSpR */ { |
357 |
|
unsc = ndp->runsamp; |
358 |
< |
if (ndp->pr->rod > .0) { |
358 |
> |
if (ndp->pr->rod > 0) { |
359 |
|
dfp = ndp->sd->rf; |
360 |
|
cvt_sdcolor(unsc, &ndp->sd->rLambFront); |
361 |
|
} else { |
372 |
|
FVECT vjit; |
373 |
|
double d; |
374 |
|
COLOR ctmp; |
375 |
< |
bsdf_jitter(vjit, ndp); |
375 |
> |
bsdf_jitter(vjit, ndp, 1); |
376 |
|
d = SDdirectHemi(vjit, sflags, ndp->sd); |
377 |
|
if (sflags == SDsampSpT) { |
378 |
|
copycolor(ctmp, ndp->pr->pcol); |
409 |
|
(m->oargs.nfargs % 3)) |
410 |
|
objerror(m, USER, "bad # arguments"); |
411 |
|
/* record surface struck */ |
412 |
< |
hitfront = (r->rod > .0); |
412 |
> |
hitfront = (r->rod > 0); |
413 |
|
/* load cal file */ |
414 |
|
mf = getfunc(m, 5, 0x1d, 1); |
415 |
|
/* get thickness */ |
418 |
|
nd.thick = .0; |
419 |
|
/* check shadow */ |
420 |
|
if (r->crtype & SHADOW) { |
421 |
< |
if (nd.thick != .0) |
421 |
> |
if (nd.thick != 0) |
422 |
|
raytrans(r); /* pass-through */ |
423 |
|
return(1); /* or shadow */ |
424 |
|
} |
425 |
|
/* check other rays to pass */ |
426 |
< |
if (nd.thick != .0 && (!(r->crtype & (SPECULAR|AMBIENT)) || |
427 |
< |
nd.thick > .0 ^ hitfront)) { |
426 |
> |
if (nd.thick != 0 && (!(r->crtype & (SPECULAR|AMBIENT)) || |
427 |
> |
nd.thick > 0 ^ hitfront)) { |
428 |
|
raytrans(r); /* hide our proxy */ |
429 |
|
return(1); |
430 |
|
} |
488 |
|
ec = SDinvXform(nd.fromloc, nd.toloc); |
489 |
|
/* determine BSDF resolution */ |
490 |
|
if (!ec) |
491 |
< |
ec = SDsizeBSDF(&nd.sr_vpsa, nd.vray, SDqueryMin, nd.sd); |
492 |
< |
if (!ec) |
493 |
< |
nd.sr_vpsa = sqrt(nd.sr_vpsa); |
494 |
< |
else { |
491 |
> |
ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, |
492 |
> |
SDqueryMin+SDqueryMax, nd.sd); |
493 |
> |
nd.thru_psa = .0; |
494 |
> |
if (!ec && nd.thick != 0 && r->crtype & (SPECULAR|AMBIENT)) { |
495 |
> |
FVECT vthru; |
496 |
> |
vthru[0] = -nd.vray[0]; |
497 |
> |
vthru[1] = -nd.vray[1]; |
498 |
> |
vthru[2] = -nd.vray[2]; |
499 |
> |
ec = SDsizeBSDF(&nd.thru_psa, nd.vray, vthru, |
500 |
> |
SDqueryMin, nd.sd); |
501 |
> |
} |
502 |
> |
if (ec) { |
503 |
|
objerror(m, WARNING, transSDError(ec)); |
504 |
|
SDfreeCache(nd.sd); |
505 |
|
return(1); |
506 |
|
} |
507 |
+ |
nd.sr_vpsa[0] = sqrt(nd.sr_vpsa[0]); |
508 |
+ |
nd.sr_vpsa[1] = sqrt(nd.sr_vpsa[1]); |
509 |
|
if (!hitfront) { /* perturb normal towards hit */ |
510 |
|
nd.pnorm[0] = -nd.pnorm[0]; |
511 |
|
nd.pnorm[1] = -nd.pnorm[1]; |
535 |
|
bnorm[0] = -nd.pnorm[0]; |
536 |
|
bnorm[1] = -nd.pnorm[1]; |
537 |
|
bnorm[2] = -nd.pnorm[2]; |
538 |
< |
if (nd.thick != .0) { /* proxy with offset? */ |
538 |
> |
if (nd.thick != 0) { /* proxy with offset? */ |
539 |
|
VCOPY(vtmp, r->rop); |
540 |
|
VSUM(r->rop, vtmp, r->ron, -nd.thick); |
541 |
|
multambient(ctmp, r, bnorm); |
549 |
|
/* add direct component */ |
550 |
|
if ((bright(nd.tdiff) <= FTINY) & (nd.sd->tf == NULL)) { |
551 |
|
direct(r, dir_brdf, &nd); /* reflection only */ |
552 |
< |
} else if (nd.thick == .0) { |
552 |
> |
} else if (nd.thick == 0) { |
553 |
|
direct(r, dir_bsdf, &nd); /* thin surface scattering */ |
554 |
|
} else { |
555 |
|
direct(r, dir_brdf, &nd); /* reflection first */ |