--- ray/src/util/cmbsdf.c 2014/01/20 22:18:29 2.2 +++ ray/src/util/cmbsdf.c 2019/07/31 22:00:08 2.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: cmbsdf.c,v 2.2 2014/01/20 22:18:29 greg Exp $"; +static const char RCSid[] = "$Id: cmbsdf.c,v 2.6 2019/07/31 22:00:08 greg Exp $"; #endif /* * Load and convert BSDF into color coefficient matrix representation. @@ -15,7 +15,7 @@ static const char RCSid[] = "$Id: cmbsdf.c,v 2.2 2014/ /* Convert a BSDF to our matrix representation */ static CMATRIX * -cm_bsdf(const COLOR diffBSDF, const COLOR specCol, const SDMat *bsdf) +cm_bsdf(const COLOR diffBSDF, const SDMat *bsdf) { CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); int nbadohm = 0; @@ -33,10 +33,13 @@ cm_bsdf(const COLOR diffBSDF, const COLOR specCol, con /* check BSDF value */ if ((f <= 0) | (dom <= 0)) { nneg += (f < -FTINY); - f = .0f; - } - copycolor(mp, specCol); - scalecolor(mp, f); + setcolor(mp, .0f, .0f, .0f); + } else if (bsdf->chroma != NULL) { + C_COLOR cxy; + c_decodeChroma(&cxy, mBSDF_chroma(bsdf,c,r)); + ccy2rgb(&cxy, f, mp); + } else + setcolor(mp, f, f, f); addcolor(mp, diffBSDF); scalecolor(mp, dom); } @@ -76,7 +79,7 @@ recip_in_from_out(const SDMat *bsdf, int out_recip) /* Convert a BSDF to our matrix representation, applying reciprocity */ static CMATRIX * -cm_bsdf_recip(const COLOR diffBSDF, const COLOR specCol, const SDMat *bsdf) +cm_bsdf_recip(const COLOR diffBSDF, const SDMat *bsdf) { CMATRIX *cm = cm_alloc(bsdf->ninc, bsdf->nout); int nbadohm = 0; @@ -96,10 +99,13 @@ cm_bsdf_recip(const COLOR diffBSDF, const COLOR specCo /* check BSDF value */ if ((f <= 0) | (dom <= 0)) { nneg += (f < -FTINY); - f = .0f; - } - copycolor(mp, specCol); - scalecolor(mp, f); + setcolor(mp, .0f, .0f, .0f); + } else if (bsdf->chroma != NULL) { + C_COLOR cxy; + c_decodeChroma(&cxy, mBSDF_chroma(bsdf,ri,ro)); + ccy2rgb(&cxy, f, mp); + } else + setcolor(mp, f, f, f); addcolor(mp, diffBSDF); scalecolor(mp, dom); } @@ -133,20 +139,14 @@ CMATRIX * cm_loadBTDF(char *fname) { CMATRIX *Tmat; - char *fpath; int recip; SDError ec; SDData myBSDF; SDSpectralDF *tdf; - COLOR diffBSDF, specCol; - /* find path to BSDF file */ - fpath = getpath(fname, getrlibpath(), R_OK); - if (fpath == NULL) { - sprintf(errmsg, "cannot find BSDF file '%s'", fname); - error(USER, errmsg); - } + COLOR diffBSDF; + SDclearBSDF(&myBSDF, fname); /* load XML and check type */ - ec = SDloadFile(&myBSDF, fpath); + ec = SDloadFile(&myBSDF, fname); if (ec) error(USER, transSDError(ec)); ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, diffBSDF); @@ -157,13 +157,12 @@ cm_loadBTDF(char *fname) return(cm_bsdf_Lamb(diffBSDF)); } if (tdf->ncomp != 1 || tdf->comp[0].func != &SDhandleMtx) { - sprintf(errmsg, "unsupported BSDF '%s'", fpath); + sprintf(errmsg, "unsupported BSDF '%s'", fname); error(USER, errmsg); } /* convert BTDF to matrix */ - ccy2rgb(&tdf->comp[0].cspec[0], 1., specCol); - Tmat = recip ? cm_bsdf_recip(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist) - : cm_bsdf(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist); + Tmat = recip ? cm_bsdf_recip(diffBSDF, (SDMat *)tdf->comp[0].dist) + : cm_bsdf(diffBSDF, (SDMat *)tdf->comp[0].dist); /* free BSDF and return */ SDfreeBSDF(&myBSDF); return(Tmat);