Page MenuHomec4science

pmcontrib2.c
No OneTemporary

File Metadata

Created
Wed, May 22, 18:01

pmcontrib2.c

#ifndef lint
static const char RCSid[] = "$Id: pmcontrib2.c,v 2.5 2018/11/08 00:54:07 greg Exp $";
#endif
/*
=========================================================================
Photon map routines for precomputed light source contributions; these
routines interface to rcontrib.
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
(c) Lucerne University of Applied Sciences and Arts,
supported by the Swiss National Science Foundation
(SNSF #147053, "Daylight Redirecting Components",
SNSF #179067, "Light Fields for Spatio-Temporal Glare Assessment")
=========================================================================
$Id: pmcontrib2.c,v 2.5 2018/11/08 00:54:07 greg Exp $
*/
#include "pmapcontrib.h"
#include "pmapmat.h"
#include "pmapsrc.h"
#include "pmaprand.h"
#include "pmapio.h"
#include "pmapdiag.h"
#include "otypes.h"
#include "otspecial.h"
static void setPmapContribParams (PhotonMap *pmap, LUTAB *srcContrib)
/* Set parameters for light source contributions */
{
/* Set light source modifier list and appropriate callback to extract
* their contributions from the photon map */
if (pmap) {
pmap -> srcContrib = srcContrib;
pmap -> lookup = photonContrib;
/* XXX: Need tighter tolerance for contribution photon lookups? */
pmap -> gatherTolerance = 1.0;
}
}
static int checkSourceContrib (const LUENT *lutEntry, void *p)
/* Check lookup table entry for light source contributions;
Returns 0 on success. */
{
char *modName = (char *)((MODCONT *)lutEntry -> data) -> modname;
OBJECT modObj = modifier(modName);
if (modObj == OVOID) {
sprintf(errmsg, "invalid modifier %s", modName);
error(USER, errmsg);
}
else if (!islight(objptr(modObj) -> otype)) {
sprintf(errmsg, "%s is not a light source modifier", modName);
error(USER, errmsg);
}
else return 0;
}
void initPmapContrib (LUTAB *srcContrib)
{
unsigned t;
/* XXX: Redundant check? */
for (t = 0; t < NUM_PMAP_TYPES; t++)
if (photonMaps [t] && t != PMAP_TYPE_CONTRIB) {
sprintf(
errmsg,
"%s photon map does not support contributions", pmapName [t]
);
error(USER, errmsg);
}
/* Check for valid modifiers in lookup table;
this doesn't return on error. */
lu_doall(srcContrib, checkSourceContrib, NULL);
/* Get params */
setPmapContribParams(contribPmap, srcContrib);
#if 0
if (contribPhotonMapping) {
if (contribPmap -> maxGather < numSrcContrib) {
/* 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");
/* Sanity check */
checkPmapContribs(contribPmap, srcContrib);
}
#endif
}
void preCompPhotonContrib (PhotonMap *pmap, RAY *ray, COLOR totalContrib)
/* Fetch and decode light source contributions from single closest
precomputed contribution photon at ray -> rop, and accumulate them in
pmap -> srcContrib. Also returns total precomputed contributions. */
{
unsigned b;
RREAL rayCoeff [3];
Photon photon;
/* Get cumulative path coefficient up to photon lookup point */
raycontrib(rayCoeff, ray, PRIMARY);
setcolor(totalContrib, 0, 0, 0);
/* Ignore sources */
if (ray -> ro && islight(objptr(ray -> ro -> omod) -> otype))
return;
if (find1Photon(pmap, ray, &photon)) {
/* Get average wavelet coeff as total contributions */
getPhotonFlux(&photon, totalContrib);
if (pmap -> srcContrib) {
/* TODO: fetch decoded binned contribs here */
const OBJREC *srcMod = photonSrcMod(pmap, &photon);
MODCONT *srcContrib = (MODCONT*)lu_find(
pmap -> srcContrib, srcMod -> oname
) -> data;
COLOR binContrib;
if (!srcContrib) {
/* Contribs from this light source not sought; this indicates
* the photon map was precomputed with different rcontrib
* parameters */
sprintf(
errmsg,
"missing LUT entry for light source modifier %s; "
"mismatched contribution photon map parameters?",
srcMod -> oname
);
error(CONSISTENCY, errmsg);
}
#if 0
/* TODO */
decodeBins(&photon, &srcBins);
if (srcBins -> numBins != srcContrib -> nbins) {
/* Number of precomputed and allocated bins don't match */
sprintf(
errmsg,
"wrong number of bins for light source modifier %s; "
"mismatched contribution photon map parameters?",
srcMod -> oname
);
error(CONSISTENCY, errmsg);
}
for (b = 0; b <= srcBins -> numBins; b++) {
/* Accumulate contribs from decoded bin */
copycolor(binContrib, srcBins [b].contrib);
if (!contrib) {
/* Ray coefficient mode; normalise by light source radiance
* after applying pattern */
int i;
raytexture(ray, srcMod -> omod);
setcolor(
ray -> rcol, srcMod -> oargs.farg [0],
srcMod -> oargs.farg [1], srcMod -> oargs.farg [2]
);
multcolor(ray -> rcol, ray -> pcol);
for (i = 0; i < 3; i++)
binContrib [i] = ray -> rcol [i] ?
binContrib [i] / ray -> rcol [i] : 0;
}
multcolor(contrib, rayCoeff);
addcolor(srcContrib -> cbin [b], binContrib);
}
#endif
}
}
return;
}

Event Timeline