--- ray/src/util/cmbsdf.c 2016/03/22 03:56:17 2.5 +++ ray/src/util/cmbsdf.c 2020/03/17 23:24:05 2.8 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: cmbsdf.c,v 2.5 2016/03/22 03:56:17 greg Exp $"; +static const char RCSid[] = "$Id: cmbsdf.c,v 2.8 2020/03/17 23:24:05 greg Exp $"; #endif /* * Load and convert BSDF into color coefficient matrix representation. @@ -28,7 +28,7 @@ cm_bsdf(const COLOR diffBSDF, const SDMat *bsdf) nbadohm += (dom <= 0); for (r = 0; r < cm->nrows; r++) { - float f = mBSDF_value(bsdf,c,r); + float f = mBSDF_value(bsdf,r,c); COLORV *mp = cm_lval(cm,r,c); /* check BSDF value */ if ((f <= 0) | (dom <= 0)) { @@ -36,7 +36,7 @@ cm_bsdf(const COLOR diffBSDF, const SDMat *bsdf) setcolor(mp, .0f, .0f, .0f); } else if (bsdf->chroma != NULL) { C_COLOR cxy; - c_decodeChroma(&cxy, mBSDF_chroma(bsdf,c,r)); + c_decodeChroma(&cxy, mBSDF_chroma(bsdf,r,c)); ccy2rgb(&cxy, f, mp); } else setcolor(mp, f, f, f); @@ -94,7 +94,7 @@ cm_bsdf_recip(const COLOR diffBSDF, const SDMat *bsdf) for (r = 0; r < cm->nrows; r++) { const int ri = recip_in_from_out(bsdf,r); - float f = mBSDF_value(bsdf,ri,ro); + float f = mBSDF_value(bsdf,ro,ri); COLORV *mp = cm_lval(cm,r,c); /* check BSDF value */ if ((f <= 0) | (dom <= 0)) { @@ -102,7 +102,7 @@ cm_bsdf_recip(const COLOR diffBSDF, const SDMat *bsdf) setcolor(mp, .0f, .0f, .0f); } else if (bsdf->chroma != NULL) { C_COLOR cxy; - c_decodeChroma(&cxy, mBSDF_chroma(bsdf,ri,ro)); + c_decodeChroma(&cxy, mBSDF_chroma(bsdf,ro,ri)); ccy2rgb(&cxy, f, mp); } else setcolor(mp, f, f, f); @@ -123,14 +123,22 @@ cm_bsdf_recip(const COLOR diffBSDF, const SDMat *bsdf) static CMATRIX * cm_bsdf_Lamb(const COLOR diffBSDF) { - CMATRIX *cm = cm_alloc(145, 145); /* this is a hack */ - int r, c; + CMATRIX *cm = cm_alloc(145, 145); /* this is a hack */ + ANGLE_BASIS *abase = abase_list; + int r, c; - for (c = 0; c < cm->ncols; c++) + while (abase->nangles != cm->nrows) + if (++abase >= abase_list+nabases) + error(INTERNAL, "Code error in cm_bsdf_Lamb()"); + + for (c = 0; c < cm->ncols; c++) { + const double dom = io_getohm(c,abase); for (r = 0; r < cm->nrows; r++) { COLORV *mp = cm_lval(cm,r,c); copycolor(mp, diffBSDF); + scalecolor(mp, dom); } + } return(cm); } @@ -139,20 +147,14 @@ CMATRIX * cm_loadBTDF(char *fname) { CMATRIX *Tmat; - char *fpath; int recip; SDError ec; SDData myBSDF; SDSpectralDF *tdf; COLOR diffBSDF; - /* find path to BSDF file */ - fpath = getpath(fname, getrlibpath(), R_OK); - if (fpath == NULL) { - sprintf(errmsg, "cannot find BSDF file '%s'", fname); - error(SYSTEM, errmsg); - } + 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); @@ -163,7 +165,7 @@ 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 */