15 |
|
|
16 |
|
/* Convert a BSDF to our matrix representation */ |
17 |
|
static CMATRIX * |
18 |
< |
cm_bsdf(const COLOR diffBSDF, const COLOR specCol, const SDMat *bsdf) |
18 |
> |
cm_bsdf(const COLOR diffBSDF, const SDMat *bsdf) |
19 |
|
{ |
20 |
|
CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); |
21 |
|
int nbadohm = 0; |
33 |
|
/* check BSDF value */ |
34 |
|
if ((f <= 0) | (dom <= 0)) { |
35 |
|
nneg += (f < -FTINY); |
36 |
< |
f = .0f; |
37 |
< |
} |
38 |
< |
copycolor(mp, specCol); |
39 |
< |
scalecolor(mp, f); |
36 |
> |
setcolor(mp, .0f, .0f, .0f); |
37 |
> |
} else if (bsdf->chroma != NULL) { |
38 |
> |
C_COLOR cxy; |
39 |
> |
c_decodeChroma(&cxy, mBSDF_chroma(bsdf,c,r)); |
40 |
> |
ccy2rgb(&cxy, f, mp); |
41 |
> |
} else |
42 |
> |
setcolor(mp, f, f, f); |
43 |
|
addcolor(mp, diffBSDF); |
44 |
|
scalecolor(mp, dom); |
45 |
|
} |
79 |
|
|
80 |
|
/* Convert a BSDF to our matrix representation, applying reciprocity */ |
81 |
|
static CMATRIX * |
82 |
< |
cm_bsdf_recip(const COLOR diffBSDF, const COLOR specCol, const SDMat *bsdf) |
82 |
> |
cm_bsdf_recip(const COLOR diffBSDF, const SDMat *bsdf) |
83 |
|
{ |
84 |
|
CMATRIX *cm = cm_alloc(bsdf->ninc, bsdf->nout); |
85 |
|
int nbadohm = 0; |
99 |
|
/* check BSDF value */ |
100 |
|
if ((f <= 0) | (dom <= 0)) { |
101 |
|
nneg += (f < -FTINY); |
102 |
< |
f = .0f; |
103 |
< |
} |
104 |
< |
copycolor(mp, specCol); |
105 |
< |
scalecolor(mp, f); |
102 |
> |
setcolor(mp, .0f, .0f, .0f); |
103 |
> |
} else if (bsdf->chroma != NULL) { |
104 |
> |
C_COLOR cxy; |
105 |
> |
c_decodeChroma(&cxy, mBSDF_chroma(bsdf,ri,ro)); |
106 |
> |
ccy2rgb(&cxy, f, mp); |
107 |
> |
} else |
108 |
> |
setcolor(mp, f, f, f); |
109 |
|
addcolor(mp, diffBSDF); |
110 |
|
scalecolor(mp, dom); |
111 |
|
} |
144 |
|
SDError ec; |
145 |
|
SDData myBSDF; |
146 |
|
SDSpectralDF *tdf; |
147 |
< |
COLOR diffBSDF, specCol; |
147 |
> |
COLOR diffBSDF; |
148 |
|
/* find path to BSDF file */ |
149 |
|
fpath = getpath(fname, getrlibpath(), R_OK); |
150 |
|
if (fpath == NULL) { |
151 |
|
sprintf(errmsg, "cannot find BSDF file '%s'", fname); |
152 |
< |
error(USER, errmsg); |
152 |
> |
error(SYSTEM, errmsg); |
153 |
|
} |
154 |
|
SDclearBSDF(&myBSDF, fname); /* load XML and check type */ |
155 |
|
ec = SDloadFile(&myBSDF, fpath); |
167 |
|
error(USER, errmsg); |
168 |
|
} |
169 |
|
/* convert BTDF to matrix */ |
170 |
< |
ccy2rgb(&tdf->comp[0].cspec[0], 1., specCol); |
171 |
< |
Tmat = recip ? cm_bsdf_recip(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist) |
166 |
< |
: cm_bsdf(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist); |
170 |
> |
Tmat = recip ? cm_bsdf_recip(diffBSDF, (SDMat *)tdf->comp[0].dist) |
171 |
> |
: cm_bsdf(diffBSDF, (SDMat *)tdf->comp[0].dist); |
172 |
|
/* free BSDF and return */ |
173 |
|
SDfreeBSDF(&myBSDF); |
174 |
|
return(Tmat); |