8 |
|
#include "copyright.h" |
9 |
|
|
10 |
|
#include "ray.h" |
11 |
– |
#include "paths.h" |
11 |
|
#include "ambient.h" |
12 |
|
#include "source.h" |
13 |
|
#include "func.h" |
64 |
|
|
65 |
|
#define cvt_sdcolor(cv, svp) ccy2rgb(&(svp)->spec, (svp)->cieY, cv) |
66 |
|
|
68 |
– |
/* Convert error from BSDF library */ |
69 |
– |
static char * |
70 |
– |
cvt_sderr(SDError ec) |
71 |
– |
{ |
72 |
– |
if (!SDerrorDetail[0]) |
73 |
– |
return(strcpy(errmsg, SDerrorEnglish[ec])); |
74 |
– |
sprintf(errmsg, "%s: %s", SDerrorEnglish[ec], SDerrorDetail); |
75 |
– |
return(errmsg); |
76 |
– |
} |
77 |
– |
|
67 |
|
/* Compute source contribution for BSDF */ |
68 |
|
static void |
69 |
|
dirbsdf( |
73 |
|
double omega /* light source size */ |
74 |
|
) |
75 |
|
{ |
76 |
< |
BSDFDAT *np = nnp; |
76 |
> |
BSDFDAT *np = (BSDFDAT *)nnp; |
77 |
|
SDError ec; |
78 |
|
SDValue sv; |
79 |
|
FVECT vout; |
112 |
|
return; |
113 |
|
ec = SDevalBSDF(&sv, vout, np->vinc, np->sd); |
114 |
|
if (ec) |
115 |
< |
objerror(np->mp, USER, cvt_sderr(ec)); |
115 |
> |
objerror(np->mp, USER, transSDError(ec)); |
116 |
|
|
117 |
|
if (sv.cieY <= FTINY) /* not worth using? */ |
118 |
|
return; |
126 |
|
scalecolor(ctmp2, dtmp); |
127 |
|
setcolor(ctmp1, 1.-dtmp, 1.-dtmp, 1.-dtmp); |
128 |
|
addcolor(ctmp1, ctmp2); |
129 |
< |
multcolor(ctmp, ctmp1); /* apply desaturated pattern */ |
129 |
> |
multcolor(ctmp, ctmp1); /* apply derated pattern */ |
130 |
|
dtmp = ldot * omega; |
131 |
|
} else { /* full pattern on transmission */ |
132 |
|
multcolor(ctmp, np->pr->pcol); |
163 |
|
: urand(ilhash(dimlist,ndims)+samplendx), |
164 |
|
dcp); |
165 |
|
if (ec) |
166 |
< |
objerror(ndp->mp, USER, cvt_sderr(ec)); |
166 |
> |
objerror(ndp->mp, USER, transSDError(ec)); |
167 |
|
/* zero component? */ |
168 |
|
if (bsv.cieY <= FTINY) |
169 |
|
break; |
185 |
|
++nsent; /* Russian roulette victim */ |
186 |
|
continue; |
187 |
|
} |
188 |
< |
/* need to move origin? */ |
189 |
< |
sthick = (ndp->pr->rod > .0) ? -ndp->thick : ndp->thick; |
190 |
< |
if (sthick < .0 ^ vout[2] > .0) |
191 |
< |
VSUM(sr.rorg, sr.rorg, ndp->pr->ron, sthick); |
192 |
< |
|
188 |
> |
if (ndp->thick > FTINY) { /* need to move origin? */ |
189 |
> |
sthick = (ndp->pr->rod > .0) ? -ndp->thick : ndp->thick; |
190 |
> |
if (sthick < .0 ^ vout[2] > .0) |
191 |
> |
VSUM(sr.rorg, sr.rorg, ndp->pr->ron, sthick); |
192 |
> |
} |
193 |
|
rayvalue(&sr); /* send & evaluate sample */ |
194 |
|
multcolor(sr.rcol, sr.rcoef); |
195 |
|
addcolor(ndp->pr->rcol, sr.rcol); |
225 |
|
return(0); |
226 |
|
/* below sampling threshold? */ |
227 |
|
if (dfp->maxHemi <= specthresh+FTINY) { |
228 |
< |
if (dfp->maxHemi > FTINY) { /* XXX no color from BSDF! */ |
228 |
> |
if (dfp->maxHemi > FTINY) { /* XXX no color from BSDF */ |
229 |
|
double d = SDdirectHemi(ndp->vinc, sflags, ndp->sd); |
230 |
|
COLOR ctmp; |
231 |
|
if (sflags == SDsampSpT) { |
262 |
|
(m->oargs.nfargs % 3)) |
263 |
|
objerror(m, USER, "bad # arguments"); |
264 |
|
|
265 |
< |
SDerrorDetail[0] = '\0'; /* get BSDF data */ |
266 |
< |
nd.sd = SDgetCache(m->oargs.sarg[1]); |
278 |
< |
if (nd.sd == NULL) |
279 |
< |
error(SYSTEM, "out of memory in m_bsdf"); |
280 |
< |
if (!SDisLoaded(nd.sd)) { |
281 |
< |
char *pname = getpath(m->oargs.sarg[1], getrlibpath(), R_OK); |
282 |
< |
if (pname == NULL) { |
283 |
< |
sprintf(errmsg, "cannot find BSDF file \"%s\"", |
284 |
< |
m->oargs.sarg[1]); |
285 |
< |
objerror(m, USER, errmsg); |
286 |
< |
} |
287 |
< |
ec = SDloadFile(nd.sd, pname); |
288 |
< |
if (ec) |
289 |
< |
objerror(m, USER, cvt_sderr(ec)); |
290 |
< |
SDretainSet = SDretainAll; |
291 |
< |
} |
265 |
> |
/* get BSDF data */ |
266 |
> |
nd.sd = loadBSDF(m->oargs.sarg[1]); |
267 |
|
/* load cal file */ |
268 |
|
mf = getfunc(m, 5, 0x1d, 1); |
269 |
|
/* get thickness */ |
272 |
|
nd.thick = .0; |
273 |
|
/* check shadow */ |
274 |
|
if (r->crtype & SHADOW) { |
275 |
< |
SDfreeCache(nd.sd); |
301 |
< |
if (nd.thick > FTINY && nd.sd->tf != NULL && |
302 |
< |
nd.sd->tf->maxHemi > FTINY) |
275 |
> |
if ((nd.thick > FTINY) & (nd.sd->tf != NULL)) |
276 |
|
raytrans(r); /* pass-through */ |
277 |
+ |
SDfreeCache(nd.sd); |
278 |
|
return(1); /* else shadow */ |
279 |
|
} |
280 |
|
/* check unscattered ray */ |
281 |
< |
if (!(r->crtype & (SPECULAR|AMBIENT)) && nd.thick > FTINY && |
282 |
< |
nd.sd->tf != NULL && nd.sd->tf->maxHemi > FTINY) { |
281 |
> |
if (!(r->crtype & (SPECULAR|AMBIENT)) && |
282 |
> |
(nd.thick > FTINY) & (nd.sd->tf != NULL)) { |
283 |
|
SDfreeCache(nd.sd); |
284 |
|
raytrans(r); /* pass-through */ |
285 |
|
return(1); |
294 |
|
m->oargs.farg[2]); |
295 |
|
} else { |
296 |
|
if (m->oargs.nfargs < 6) { /* check invisible backside */ |
297 |
< |
if (!backvis && (nd.sd->rb == NULL || |
298 |
< |
nd.sd->rb->maxHemi <= FTINY) && |
325 |
< |
(nd.sd->tf == NULL || |
326 |
< |
nd.sd->tf->maxHemi <= FTINY)) { |
297 |
> |
if (!backvis && (nd.sd->rb == NULL) & |
298 |
> |
(nd.sd->tf == NULL)) { |
299 |
|
SDfreeCache(nd.sd); |
300 |
|
raytrans(r); |
301 |
|
return(1); |
345 |
|
if (!ec) |
346 |
|
ec = SDinvXform(nd.fromloc, nd.toloc); |
347 |
|
if (ec) { |
348 |
< |
objerror(m, WARNING, cvt_sderr(ec)); |
348 |
> |
objerror(m, WARNING, transSDError(ec)); |
349 |
|
SDfreeCache(nd.sd); |
350 |
|
return(1); |
351 |
|
} |