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 */ |
75 |
+ |
COLOR cthru; /* through component multiplier */ |
76 |
|
SDData *sd; /* loaded BSDF data */ |
77 |
|
COLOR rdiff; /* diffuse reflection */ |
78 |
|
COLOR tdiff; /* diffuse transmission */ |
80 |
|
|
81 |
|
#define cvt_sdcolor(cv, svp) ccy2rgb(&(svp)->spec, (svp)->cieY, cv) |
82 |
|
|
83 |
+ |
/* Compute through component color */ |
84 |
+ |
static void |
85 |
+ |
compute_through(BSDFDAT *ndp) |
86 |
+ |
{ |
87 |
+ |
#define NDIR2CHECK 13 |
88 |
+ |
static const float dir2check[NDIR2CHECK][2] = { |
89 |
+ |
{0, 0}, |
90 |
+ |
{-0.8, 0}, |
91 |
+ |
{0, 0.8}, |
92 |
+ |
{0, -0.8}, |
93 |
+ |
{0.8, 0}, |
94 |
+ |
{-0.8, 0.8}, |
95 |
+ |
{-0.8, -0.8}, |
96 |
+ |
{0.8, 0.8}, |
97 |
+ |
{0.8, -0.8}, |
98 |
+ |
{-1.6, 0}, |
99 |
+ |
{0, 1.6}, |
100 |
+ |
{0, -1.6}, |
101 |
+ |
{1.6, 0}, |
102 |
+ |
}; |
103 |
+ |
const double peak_over = 2.0; |
104 |
+ |
SDSpectralDF *dfp; |
105 |
+ |
FVECT pdir; |
106 |
+ |
double tomega, srchrad; |
107 |
+ |
COLOR vpeak, vsum; |
108 |
+ |
int nsum, i; |
109 |
+ |
SDError ec; |
110 |
+ |
|
111 |
+ |
setcolor(ndp->cthru, .0, .0, .0); /* starting assumption */ |
112 |
+ |
|
113 |
+ |
if (ndp->pr->rod > 0) |
114 |
+ |
dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb; |
115 |
+ |
else |
116 |
+ |
dfp = (ndp->sd->tb != NULL) ? ndp->sd->tb : ndp->sd->tf; |
117 |
+ |
|
118 |
+ |
if (dfp == NULL) |
119 |
+ |
return; /* no specular transmission */ |
120 |
+ |
if (bright(ndp->pr->pcol) <= FTINY) |
121 |
+ |
return; /* pattern is black, here */ |
122 |
+ |
srchrad = sqrt(dfp->minProjSA); /* else search for peak */ |
123 |
+ |
setcolor(vpeak, .0, .0, .0); |
124 |
+ |
setcolor(vsum, .0, .0, .0); |
125 |
+ |
nsum = 0; |
126 |
+ |
for (i = 0; i < NDIR2CHECK; i++) { |
127 |
+ |
FVECT tdir; |
128 |
+ |
SDValue sv; |
129 |
+ |
COLOR vcol; |
130 |
+ |
tdir[0] = -ndp->vray[0] + dir2check[i][0]*srchrad; |
131 |
+ |
tdir[1] = -ndp->vray[1] + dir2check[i][1]*srchrad; |
132 |
+ |
tdir[2] = -ndp->vray[2]; |
133 |
+ |
if (normalize(tdir) == 0) |
134 |
+ |
continue; |
135 |
+ |
ec = SDevalBSDF(&sv, tdir, ndp->vray, ndp->sd); |
136 |
+ |
if (ec) |
137 |
+ |
goto baderror; |
138 |
+ |
cvt_sdcolor(vcol, &sv); |
139 |
+ |
addcolor(vsum, vcol); |
140 |
+ |
++nsum; |
141 |
+ |
if (bright(vcol) > bright(vpeak)) { |
142 |
+ |
copycolor(vpeak, vcol); |
143 |
+ |
VCOPY(pdir, tdir); |
144 |
+ |
} |
145 |
+ |
} |
146 |
+ |
ec = SDsizeBSDF(&tomega, pdir, ndp->vray, SDqueryMin, ndp->sd); |
147 |
+ |
if (ec) |
148 |
+ |
goto baderror; |
149 |
+ |
if (tomega > 1.5*dfp->minProjSA) |
150 |
+ |
return; /* not really a peak? */ |
151 |
+ |
if ((bright(vpeak) - ndp->sd->tLamb.cieY*(1./PI))*tomega <= .001) |
152 |
+ |
return; /* < 0.1% transmission */ |
153 |
+ |
for (i = 3; i--; ) /* remove peak from average */ |
154 |
+ |
colval(vsum,i) -= colval(vpeak,i); |
155 |
+ |
--nsum; |
156 |
+ |
if (peak_over*bright(vsum) >= nsum*bright(vpeak)) |
157 |
+ |
return; /* not peaky enough */ |
158 |
+ |
copycolor(ndp->cthru, vpeak); /* else use it */ |
159 |
+ |
scalecolor(ndp->cthru, tomega); |
160 |
+ |
multcolor(ndp->cthru, ndp->pr->pcol); /* modify by pattern */ |
161 |
+ |
return; |
162 |
+ |
baderror: |
163 |
+ |
objerror(ndp->mp, USER, transSDError(ec)); |
164 |
+ |
#undef NDIR2CHECK |
165 |
+ |
} |
166 |
+ |
|
167 |
|
/* Jitter ray sample according to projected solid angle and specjitter */ |
168 |
|
static void |
169 |
|
bsdf_jitter(FVECT vres, BSDFDAT *ndp, double sr_psa) |
224 |
|
if (ec) |
225 |
|
goto baderror; |
226 |
|
/* check indirect over-counting */ |
227 |
< |
if (ndp->thick != 0 && ndp->pr->crtype & (SPECULAR|AMBIENT) |
227 |
> |
if ((ndp->thick != 0 || bright(ndp->cthru) > FTINY) |
228 |
> |
&& ndp->pr->crtype & (SPECULAR|AMBIENT) |
229 |
|
&& (vsrc[2] > 0) ^ (ndp->vray[2] > 0)) { |
230 |
|
double dx = vsrc[0] + ndp->vray[0]; |
231 |
|
double dy = vsrc[1] + ndp->vray[1]; |
553 |
|
nd.thick = evalue(mf->ep[0]); |
554 |
|
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
555 |
|
nd.thick = .0; |
470 |
– |
/* check shadow */ |
471 |
– |
if (r->crtype & SHADOW) { |
472 |
– |
if (nd.thick != 0) |
473 |
– |
raytrans(r); /* pass-through */ |
474 |
– |
return(1); /* or shadow */ |
475 |
– |
} |
556 |
|
/* check backface visibility */ |
557 |
|
if (!hitfront & !backvis) { |
558 |
|
raytrans(r); |
559 |
|
return(1); |
560 |
|
} |
561 |
|
/* check other rays to pass */ |
562 |
< |
if (nd.thick != 0 && (!(r->crtype & (SPECULAR|AMBIENT)) || |
562 |
> |
if (nd.thick != 0 && (r->crtype & SHADOW || |
563 |
> |
!(r->crtype & (SPECULAR|AMBIENT)) || |
564 |
|
(nd.thick > 0) ^ hitfront)) { |
565 |
|
raytrans(r); /* hide our proxy */ |
566 |
|
return(1); |
569 |
|
nd.pr = r; |
570 |
|
/* get BSDF data */ |
571 |
|
nd.sd = loadBSDF(m->oargs.sarg[1]); |
572 |
+ |
/* early shadow check */ |
573 |
+ |
if (r->crtype & SHADOW && (nd.sd->tf == NULL) & (nd.sd->tb == NULL)) |
574 |
+ |
return(1); |
575 |
|
/* diffuse reflectance */ |
576 |
|
if (hitfront) { |
577 |
|
cvt_sdcolor(nd.rdiff, &nd.sd->rLambFront); |
625 |
|
nd.vray[2] = -r->rdir[2]; |
626 |
|
ec = SDmapDir(nd.vray, nd.toloc, nd.vray); |
627 |
|
} |
544 |
– |
if (!ec) |
545 |
– |
ec = SDinvXform(nd.fromloc, nd.toloc); |
628 |
|
if (ec) { |
629 |
|
objerror(m, WARNING, "Illegal orientation vector"); |
630 |
|
return(1); |
631 |
|
} |
632 |
< |
/* determine BSDF resolution */ |
633 |
< |
ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, SDqueryMin+SDqueryMax, nd.sd); |
632 |
> |
compute_through(&nd); /* compute through component */ |
633 |
> |
if (r->crtype & SHADOW) { |
634 |
> |
RAY tr; /* attempt to pass shadow ray */ |
635 |
> |
if (rayorigin(&tr, TRANS, r, nd.cthru) < 0) |
636 |
> |
return(1); /* blocked */ |
637 |
> |
VCOPY(tr.rdir, r->rdir); |
638 |
> |
rayvalue(&tr); /* transmit with scaling */ |
639 |
> |
multcolor(tr.rcol, tr.rcoef); |
640 |
> |
copycolor(r->rcol, tr.rcol); |
641 |
> |
return(1); /* we're done */ |
642 |
> |
} |
643 |
> |
ec = SDinvXform(nd.fromloc, nd.toloc); |
644 |
> |
if (!ec) /* determine BSDF resolution */ |
645 |
> |
ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, |
646 |
> |
SDqueryMin+SDqueryMax, nd.sd); |
647 |
|
if (ec) |
648 |
|
objerror(m, USER, transSDError(ec)); |
649 |
|
|