--- ray/src/rt/pmcontrib2.c 2016/09/29 21:51:58 2.1 +++ ray/src/rt/pmcontrib2.c 2018/02/09 14:59:08 2.4 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pmcontrib2.c,v 2.1 2016/09/29 21:51:58 greg Exp $"; +static const char RCSid[] = "$Id: pmcontrib2.c,v 2.4 2018/02/09 14:59:08 rschregle Exp $"; #endif /* @@ -11,7 +11,7 @@ static const char RCSid[] = "$Id: pmcontrib2.c,v 2.1 2 supported by the Swiss National Science Foundation (SNSF, #147053) ====================================================================== - $Id: pmcontrib2.c,v 2.1 2016/09/29 21:51:58 greg Exp $ + $Id: pmcontrib2.c,v 2.4 2018/02/09 14:59:08 rschregle Exp $ */ @@ -23,8 +23,6 @@ static const char RCSid[] = "$Id: pmcontrib2.c,v 2.1 2 #include "pmapdiag.h" #include "rcontrib.h" #include "otypes.h" -#include -#include @@ -83,11 +81,18 @@ void initPmapContrib (LUTAB *srcContrib, unsigned numS if (contribPhotonMapping) { if (contribPmap -> maxGather < numSrcContrib) { +#if 0 /* Adjust density estimate bandwidth if lower than modifier * count, otherwise contributions are missing */ error(WARNING, "contrib density estimate bandwidth too low, " "adjusting to modifier count"); contribPmap -> maxGather = numSrcContrib; +#else + /* Warn if density estimate bandwidth is lower than modifier + * count, since some contributions will be missing */ + error(WARNING, "photon density estimate bandwidth too low," + " contributions may be underestimated"); +#endif } /* Sanity check */ @@ -102,10 +107,10 @@ void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i { unsigned i; PhotonSearchQueueNode *sqn; - float r, invArea; + float r2, invArea; RREAL rayCoeff [3]; Photon *photon; - static char warn = 1; + static char warnPos = 1, warnDir = 1; setcolor(irrad, 0, 0, 0); @@ -135,13 +140,13 @@ void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i return; } - /* Average (squared) radius between furthest two photons to improve - * accuracy and get inverse search area 1 / (PI * r^2), with extra - * normalisation factor 1 / PI for ambient calculation */ + /* Average radius^2 between furthest two photons to improve accuracy and + * get inverse search area 1 / (PI * r^2), with extra normalisation + * factor 1 / PI for ambient calculation */ sqn = pmap -> squeue.node + 1; - r = max(sqn -> dist2, (sqn + 1) -> dist2); - r = 0.25 * (pmap -> maxDist2 + r + 2 * sqrt(pmap -> maxDist2 * r)); - invArea = 1 / (PI * PI * r); + r2 = max(sqn -> dist2, (sqn + 1) -> dist2); + r2 = 0.25 * (pmap -> maxDist2 + r2 + 2 * sqrt(pmap -> maxDist2 * r2)); + invArea = 1 / (PI * PI * r2); /* Skip the extra photon */ for (i = 1 ; i < pmap -> squeue.tail; i++, sqn++) { @@ -153,7 +158,7 @@ void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i scalecolor(flux, invArea); #ifdef PMAP_EPANECHNIKOV /* Apply Epanechnikov kernel to photon flux based on photon distance */ - scalecolor(flux, 2 * (1 - sqn -> dist2 / r)); + scalecolor(flux, 2 * (1 - sqn -> dist2 / r2)); #endif addcolor(irrad, flux); @@ -183,13 +188,25 @@ void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i #else /* No primary hitpoints; set dummy ray origin and warn once */ srcRay.rorg [0] = srcRay.rorg [1] = srcRay.rorg [2] = 0; - if (warn) { - error(WARNING, "no photon primary hitpoints for bin evaluation;" - " using dummy (0,0,0) !"); - warn = 0; + if (warnPos) { + error(WARNING, + "no photon primary hitpoints for bin evaluation; " + "using dummy (0,0,0)! Recompile with -DPMAP_CBDM."); + warnPos = 0; } #endif +#ifdef PMAP_PRIMARYDIR decodedir(srcRay.rdir, primary -> dir); +#else + /* No primary incident direction; set dummy and warn once */ + if (warnDir) { + error(WARNING, + "no photon primary directions for bin evaluation; " + "using dummy (0,0,0)! Recompile with -DPMAP_CBDM."); + warnDir = 0; + } + srcRay.rdir [0] = srcRay.rdir [1] = srcRay.rdir [2] = 0; +#endif if (!(sp->sflags & SDISTANT ? sourcehit(&srcRay)