| 15 |
|
|
| 16 |
|
/* Convert a BSDF to our matrix representation */ |
| 17 |
|
static CMATRIX * |
| 18 |
< |
cm_bsdf(const COLOR bsdfLamb, 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); |
| 40 |
< |
addcolor(mp, bsdfLamb); |
| 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 |
|
} |
| 46 |
|
} |
| 79 |
|
|
| 80 |
|
/* Convert a BSDF to our matrix representation, applying reciprocity */ |
| 81 |
|
static CMATRIX * |
| 82 |
< |
cm_bsdf_recip(const COLOR bsdfLamb, 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); |
| 106 |
< |
addcolor(mp, bsdfLamb); |
| 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 |
|
} |
| 112 |
|
} |
| 119 |
|
return(cm); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
< |
/* Load and convert a matrix BSDF from the given XML file */ |
| 122 |
> |
/* Return a Lambertian (diffuse) matrix */ |
| 123 |
> |
static CMATRIX * |
| 124 |
> |
cm_bsdf_Lamb(const COLOR diffBSDF) |
| 125 |
> |
{ |
| 126 |
> |
CMATRIX *cm = cm_alloc(145, 145); /* this is a hack */ |
| 127 |
> |
int r, c; |
| 128 |
> |
|
| 129 |
> |
for (c = 0; c < cm->ncols; c++) |
| 130 |
> |
for (r = 0; r < cm->nrows; r++) { |
| 131 |
> |
COLORV *mp = cm_lval(cm,r,c); |
| 132 |
> |
copycolor(mp, diffBSDF); |
| 133 |
> |
} |
| 134 |
> |
return(cm); |
| 135 |
> |
} |
| 136 |
> |
|
| 137 |
> |
/* Load and convert a matrix BTDF from the given XML file */ |
| 138 |
|
CMATRIX * |
| 139 |
< |
cm_loadBSDF(char *fname, COLOR cLamb) |
| 139 |
> |
cm_loadBTDF(char *fname) |
| 140 |
|
{ |
| 141 |
|
CMATRIX *Tmat; |
| 121 |
– |
char *fpath; |
| 142 |
|
int recip; |
| 143 |
|
SDError ec; |
| 144 |
|
SDData myBSDF; |
| 145 |
|
SDSpectralDF *tdf; |
| 146 |
< |
COLOR bsdfLamb, specCol; |
| 147 |
< |
/* find path to BSDF file */ |
| 128 |
< |
fpath = getpath(fname, getrlibpath(), R_OK); |
| 129 |
< |
if (fpath == NULL) { |
| 130 |
< |
sprintf(errmsg, "cannot find BSDF file '%s'", fname); |
| 131 |
< |
error(USER, errmsg); |
| 132 |
< |
} |
| 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, bsdfLamb); |
| 152 |
> |
ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, diffBSDF); |
| 153 |
|
recip = (myBSDF.tb == NULL); |
| 154 |
|
tdf = recip ? myBSDF.tf : myBSDF.tb; |
| 155 |
|
if (tdf == NULL) { /* no non-Lambertian transmission? */ |
| 141 |
– |
if (cLamb != NULL) |
| 142 |
– |
copycolor(cLamb, bsdfLamb); |
| 156 |
|
SDfreeBSDF(&myBSDF); |
| 157 |
< |
return(NULL); |
| 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(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist) |
| 153 |
< |
: cm_bsdf(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist); |
| 154 |
< |
if (cLamb != NULL) /* Lambertian is included */ |
| 155 |
< |
setcolor(cLamb, .0, .0, .0); |
| 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); |