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; |
28 |
|
nbadohm += (dom <= 0); |
29 |
|
|
30 |
|
for (r = 0; r < cm->nrows; r++) { |
31 |
< |
float f = mBSDF_value(bsdf,c,r); |
31 |
> |
float f = mBSDF_value(bsdf,r,c); |
32 |
|
COLORV *mp = cm_lval(cm,r,c); |
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,r,c)); |
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; |
94 |
|
|
95 |
|
for (r = 0; r < cm->nrows; r++) { |
96 |
|
const int ri = recip_in_from_out(bsdf,r); |
97 |
< |
float f = mBSDF_value(bsdf,ri,ro); |
97 |
> |
float f = mBSDF_value(bsdf,ro,ri); |
98 |
|
COLORV *mp = cm_lval(cm,r,c); |
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,ro,ri)); |
106 |
> |
ccy2rgb(&cxy, f, mp); |
107 |
> |
} else |
108 |
> |
setcolor(mp, f, f, f); |
109 |
|
addcolor(mp, diffBSDF); |
110 |
|
scalecolor(mp, dom); |
111 |
|
} |
139 |
|
cm_loadBTDF(char *fname) |
140 |
|
{ |
141 |
|
CMATRIX *Tmat; |
136 |
– |
char *fpath; |
142 |
|
int recip; |
143 |
|
SDError ec; |
144 |
|
SDData myBSDF; |
145 |
|
SDSpectralDF *tdf; |
146 |
< |
COLOR diffBSDF, specCol; |
147 |
< |
/* find path to BSDF file */ |
143 |
< |
fpath = getpath(fname, getrlibpath(), R_OK); |
144 |
< |
if (fpath == NULL) { |
145 |
< |
sprintf(errmsg, "cannot find BSDF file '%s'", fname); |
146 |
< |
error(USER, errmsg); |
147 |
< |
} |
146 |
> |
COLOR diffBSDF; |
147 |
> |
|
148 |
|
SDclearBSDF(&myBSDF, fname); /* load XML and check type */ |
149 |
< |
ec = SDloadFile(&myBSDF, fpath); |
149 |
> |
ec = SDloadFile(&myBSDF, fname); |
150 |
|
if (ec) |
151 |
|
error(USER, transSDError(ec)); |
152 |
|
ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, diffBSDF); |
157 |
|
return(cm_bsdf_Lamb(diffBSDF)); |
158 |
|
} |
159 |
|
if (tdf->ncomp != 1 || tdf->comp[0].func != &SDhandleMtx) { |
160 |
< |
sprintf(errmsg, "unsupported BSDF '%s'", fpath); |
160 |
> |
sprintf(errmsg, "unsupported BSDF '%s'", fname); |
161 |
|
error(USER, errmsg); |
162 |
|
} |
163 |
|
/* convert BTDF to matrix */ |
164 |
< |
ccy2rgb(&tdf->comp[0].cspec[0], 1., specCol); |
165 |
< |
Tmat = recip ? cm_bsdf_recip(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist) |
166 |
< |
: cm_bsdf(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist); |
164 |
> |
Tmat = recip ? cm_bsdf_recip(diffBSDF, (SDMat *)tdf->comp[0].dist) |
165 |
> |
: cm_bsdf(diffBSDF, (SDMat *)tdf->comp[0].dist); |
166 |
|
/* free BSDF and return */ |
167 |
|
SDfreeBSDF(&myBSDF); |
168 |
|
return(Tmat); |