--- ray/src/rt/pmapkdt.c 2018/01/24 19:39:05 1.3 +++ ray/src/rt/pmapkdt.c 2018/11/08 00:54:07 1.5 @@ -8,13 +8,15 @@ supported by the Swiss National Science Foundation (SNSF, #147053) ====================================================================== - $Id: pmapkdt.c,v 1.3 2018/01/24 19:39:05 rschregle Exp $ + $Id: pmapkdt.c,v 1.5 2018/11/08 00:54:07 greg Exp $ */ #include "pmapdata.h" /* Includes pmapkdt.h */ #include "source.h" +#include "otspecial.h" +#include "random.h" @@ -424,8 +426,9 @@ void kdT_FindPhotons (struct PhotonMap *pmap, const FV /* Photon pos & normal stored at lower precision */ VCOPY(p, pos); - VCOPY(n, norm); - kdT_FindNearest(pmap, p, n, 1); + if (norm) + VCOPY(n, norm); + kdT_FindNearest(pmap, p, norm ? n : NULL, 1); } @@ -464,7 +467,7 @@ static void kdT_Find1Nearest (PhotonMap *pmap, const f d2 = DOT(dv, dv); if (d2 < pmap -> maxDist2 && - DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom()) { + (!norm || DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom())) { /* Closest photon so far with similar normal. We allow for tolerance * to account for perturbation in the latter; note the photon normal * is coded in the range [-127,127], hence we factor this in */ @@ -483,8 +486,9 @@ void kdT_Find1Photon (struct PhotonMap *pmap, const FV /* Photon pos & normal stored at lower precision */ VCOPY(p, pos); - VCOPY(n, norm); - kdT_Find1Nearest(pmap, p, n, &pnn, 1); + if (norm) + VCOPY(n, norm); + kdT_Find1Nearest(pmap, p, norm ? n : NULL, &pnn, 1); memcpy(photon, pnn, sizeof(Photon)); }