--- ray/src/common/bsdf.c 2013/07/04 15:14:45 2.46 +++ ray/src/common/bsdf.c 2014/03/24 04:00:45 2.48 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf.c,v 2.46 2013/07/04 15:14:45 greg Exp $"; +static const char RCSid[] = "$Id: bsdf.c,v 2.48 2014/03/24 04:00:45 greg Exp $"; #endif /* * bsdf.c @@ -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]; } @@ -790,7 +789,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;