--- ray/src/common/bsdf_t.c 2011/08/21 22:38:12 3.20 +++ ray/src/common/bsdf_t.c 2011/08/22 05:48:39 3.21 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf_t.c,v 3.20 2011/08/21 22:38:12 greg Exp $"; +static const char RCSid[] = "$Id: bsdf_t.c,v 3.21 2011/08/22 05:48:39 greg Exp $"; #endif /* * bsdf_t.c @@ -607,19 +607,23 @@ const SDCDst * SDgetTreCDist(const FVECT inVec, SDComponent *sdc) { const SDTre *sdt; - double inCoord[2]; + double inCoord[2], quantum; int i; SDTreCDst *cd, *cdlast; /* check arguments */ if ((inVec == NULL) | (sdc == NULL) || (sdt = (SDTre *)sdc->dist) == NULL) return NULL; - if (sdt->st->ndim == 3) /* isotropic BSDF? */ + if (sdt->st->ndim == 3) { /* isotropic BSDF? */ inCoord[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]); - else if (sdt->st->ndim == 4) + } else if (sdt->st->ndim == 4) { SDdisk2square(inCoord, -inVec[0], -inVec[1]); - else + } else return NULL; /* should be internal error */ + /* quantize to avoid f.p. errors */ + quantum = SDsmallestLeaf(sdt->st); + for (i = sdt->st->ndim - 2; i--; ) + inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum; cdlast = NULL; /* check for direction in cache list */ for (cd = (SDTreCDst *)sdc->cdList; cd != NULL; cdlast = cd, cd = cd->next) {