Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85140312
pmcontrib3.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 27, 01:30
Size
5 KB
Mime Type
text/x-c
Expires
Sun, Sep 29, 01:30 (2 d)
Engine
blob
Format
Raw Data
Handle
21112554
Attached To
R10977 RADIANCE Photon Map
pmcontrib3.c
View Options
#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$
*/
#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 *contribTab)
/* 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 -> contribTab = contribTab;
pmap -> lookup = getPreCompPhotonContrib;
/* 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 getPreCompPhotonContrib (PhotonMap *pmap, RAY *ray, COLOR totalContrib)
/* Fetch and decode precomputed 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 -> contribTab) {
/* TODO: fetch decoded binned contribs here */
const OBJREC *mod = photonSrcMod(pmap, &photon);
MODCONT *contrib = (MODCONT*)lu_find(
pmap -> contribTab, mod -> oname
) -> data;
COLOR binContrib;
if (!contrib) {
/* 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?",
mod -> oname
);
error(CONSISTENCY, errmsg);
}
#if 0
/* TODO */
decodeBins(&photon, &srcBins);
if (srcBins -> numBins != contrib -> 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
}
}
}
Event Timeline
Log In to Comment