--- ray/src/rt/pmapdata.c 2015/05/08 13:20:23 2.3 +++ ray/src/rt/pmapdata.c 2015/05/26 11:26:27 2.7 @@ -8,7 +8,7 @@ supported by the Swiss National Science Foundation (SNSF, #147053) ================================================================== - $Id: pmapdata.c,v 2.3 2015/05/08 13:20:23 rschregle Exp $ + $Id: pmapdata.c,v 2.7 2015/05/26 11:26:27 rschregle Exp $ */ @@ -19,6 +19,7 @@ #include "otypes.h" #include "source.h" #include "rcontrib.h" +#include "random.h" @@ -66,6 +67,7 @@ void initPhotonMap (PhotonMap *pmap, PhotonMapType t) const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap, const RAY *ray) { PhotonPrimary *prim = NULL; + FVECT dvec; if (!pmap || !ray) return NULL; @@ -98,11 +100,12 @@ const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap prim -> srcIdx = -1; /* Reverse incident direction to point to light source */ - prim -> dir [0] = -ray -> rdir [0]; - prim -> dir [1] = -ray -> rdir [1]; - prim -> dir [2] = -ray -> rdir [2]; + dvec [0] = -ray -> rdir [0]; + dvec [1] = -ray -> rdir [1]; + dvec [2] = -ray -> rdir [2]; + prim -> dir = encodedir(dvec); - VCOPY(prim -> org, ray -> rorg); + VCOPY(prim -> pos, ray -> rop); return prim; } @@ -227,7 +230,7 @@ static void nearestNeighbours (PhotonMap* pmap, const } /* Reject photon if normal faces away (ignored for volume photons) */ - if (norm && DOT(norm, p -> norm) <= 0) + if (norm && DOT(norm, p -> norm) <= 0.5 * frandom()) return; if (isContribPmap(pmap) && pmap -> srcContrib) { @@ -238,7 +241,7 @@ static void nearestNeighbours (PhotonMap* pmap, const if (srcIdx < 0 || srcIdx >= nsources) error(INTERNAL, "invalid light source index in photon map"); - srcMod = objptr(source [srcIdx].so -> omod); + srcMod = findmaterial(source [srcIdx].so); /* Reject photon if contributions from light source which emitted it * are not sought */ @@ -453,7 +456,7 @@ static void nearest1Neighbour (PhotonMap *pmap, const dv [2] = pos [2] - p -> pos [2]; d2 = DOT(dv, dv); - if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0) { + if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0.5 * frandom()) { /* Closest photon so far with similar normal */ pmap -> maxDist = d2; *photon = p;