--- ray/src/common/bsdf.c 2013/07/03 18:56:19 2.45 +++ ray/src/common/bsdf.c 2015/02/08 22:14:50 2.50 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf.c,v 2.45 2013/07/03 18:56:19 greg Exp $"; +static const char RCSid[] = "$Id: bsdf.c,v 2.50 2015/02/08 22:14:50 greg Exp $"; #endif /* * bsdf.c @@ -199,7 +199,7 @@ SDloadFile(SDData *sd, const char *fname) } wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); if (wtl == NULL) { - sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'", + sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers", sd->name); ezxml_free(fl); return SDEformat; @@ -558,8 +558,7 @@ SDdiffuseSamp(FVECT outVec, int outFront, double randX SDmultiSamp(outVec, 2, randX); SDsquare2disk(outVec, outVec[0], outVec[1]); outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1]; - if (outVec[2] > 0) /* a bit of paranoia */ - outVec[2] = sqrt(outVec[2]); + outVec[2] = sqrt(outVec[2]*(outVec[2]>0)); if (!outFront) /* going out back? */ outVec[2] = -outVec[2]; } @@ -618,7 +617,8 @@ SDsizeBSDF(double *projSA, const FVECT v1, const RREAL projSA[0] = M_PI; if (qflags == SDqueryMin+SDqueryMax) projSA[1] = M_PI; - } + } else if (qflags == SDqueryMin+SDqueryMax && projSA[0] > projSA[1]) + projSA[0] = projSA[1]; return SDEnone; } @@ -763,8 +763,7 @@ SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int cdarr[i] = (*rdf->comp[i].func->getCDist)(inVec, &rdf->comp[i]); if (cdarr[i] == NULL) cdarr[i] = &SDemptyCD; - else - sv->cieY += cdarr[i]->cTotal; + sv->cieY += cdarr[i]->cTotal; } if (sv->cieY <= 1e-6) { /* anything to sample? */ sv->cieY = .0; @@ -789,7 +788,7 @@ SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int randX -= sd->tLamb.cieY; } /* else one of cumulative dist. */ - for (i = 0; i < n && randX < cdarr[i]->cTotal; i++) + for (i = 0; i < n && randX > cdarr[i]->cTotal; i++) randX -= cdarr[i]->cTotal; if (i >= n) return SDEinternal;