--- ray/src/cv/checkBSDF.c 2021/12/15 02:13:27 2.2 +++ ray/src/cv/checkBSDF.c 2022/01/26 17:30:07 2.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: checkBSDF.c,v 2.2 2021/12/15 02:13:27 greg Exp $"; +static const char RCSid[] = "$Id: checkBSDF.c,v 2.6 2022/01/26 17:30:07 greg Exp $"; #endif /* * checkBSDF.c @@ -29,7 +29,7 @@ typedef struct { const SimpleStats SSinit = {FHUGE, -FHUGE, .0, 0}; /* relative difference formula */ -#define rdiff(a,b) ((a)>(b) ? ((a)-(b))/(a) : ((b)-(a))/(b)) +#define rdiff(a,b) ((a)>(b) ? ((a)-(b))/((a)+FTINY) : ((b)-(a))/((b)+FTINY)) /* Figure out BSDF type (and optionally determine if in color) */ const char * @@ -177,9 +177,15 @@ checkReciprocity(const char *nm, const int side1, cons if (fl & F_MATRIX) { /* special case for matrix BSDF */ const SDMat *m = (const SDMat *)df->comp[0].dist; int i = m->ninc; + double diffuseY; FVECT vin, vout; double fwdY; SDValue rev; + if (side1 == side2) + diffuseY = (side1 > 0) ? bsdf->rLambFront.cieY : bsdf->rLambBack.cieY; + else + diffuseY = (side1 > 0) ? bsdf->tLambFront.cieY : bsdf->tLambBack.cieY; + diffuseY /= M_PI; while (i--) { int o = m->nout; if (!mBSDF_incvec(vin, m, i+.5)) @@ -187,7 +193,7 @@ checkReciprocity(const char *nm, const int side1, cons while (o--) { if (!mBSDF_outvec(vout, m, o+.5)) continue; - fwdY = mBSDF_value(m, o, i); + fwdY = mBSDF_value(m, o, i) + diffuseY; if (fwdY <= 1e-4) continue; if (SDreportError( SDevalBSDF(&rev, vout, vin, bsdf), stderr)) @@ -196,7 +202,7 @@ checkReciprocity(const char *nm, const int side1, cons addStat(&myStats, rdiff(fwdY, rev.cieY)); } } - } if (fl & F_ISOTROPIC) { /* isotropic case */ + } else if (fl & F_ISOTROPIC) { /* isotropic case */ const double stepSize = sqrt(df->minProjSA/M_PI); FVECT vin; vin[1] = 0; @@ -230,7 +236,7 @@ checkXML(char *fname) puts("====================================================="); printf("File: '%s'\n", fname); SDclearBSDF(&myBSDF, fname); - pth = getpath(fname, getrlibpath(), R_OK); + pth = getpath(fname, getrlibpath(), 0); if (!pth) { fprintf(stderr, "Cannot find file '%s'\n", fname); return 0; @@ -245,13 +251,13 @@ checkXML(char *fname) printf("Color: %d\n", (flags & F_IN_COLOR) != 0); printf("Has Geometry: %d\n", (myBSDF.mgf != NULL)); puts("Component\tLambertian XYZ %\tMax. Dir\tMin. Angle"); - detailComponent("Internal Refl", &myBSDF.rLambFront, myBSDF.rf); - detailComponent("External Refl", &myBSDF.rLambBack, myBSDF.rb); + detailComponent("Interior Refl", &myBSDF.rLambFront, myBSDF.rf); + detailComponent("Exterior Refl", &myBSDF.rLambBack, myBSDF.rb); detailComponent("Int->Ext Trans", &myBSDF.tLambFront, myBSDF.tf); detailComponent("Ext->Int Trans", &myBSDF.tLambBack, myBSDF.tb); puts("Component\tReciprocity Error (min avg max %)"); - checkReciprocity("Front Refl", 1, 1, &myBSDF, flags); - checkReciprocity("Back Refl", -1, -1, &myBSDF, flags); + checkReciprocity("Interior Refl", 1, 1, &myBSDF, flags); + checkReciprocity("Exterior Refl", -1, -1, &myBSDF, flags); checkReciprocity("Transmission", -1, 1, &myBSDF, flags); SDfreeBSDF(&myBSDF); return 1;