| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: pmapamb.c,v 2.6 2015/08/18 18:45:55 greg Exp $";
|
| 3 |
#endif
|
| 4 |
|
| 5 |
/*
|
| 6 |
==================================================================
|
| 7 |
Photon map interface to RADIANCE ambient calculation
|
| 8 |
|
| 9 |
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
|
| 10 |
(c) Fraunhofer Institute for Solar Energy Systems,
|
| 11 |
(c) Lucerne University of Applied Sciences and Arts,
|
| 12 |
supported by the Swiss National Science Foundation (SNSF, #147053)
|
| 13 |
==================================================================
|
| 14 |
|
| 15 |
$Id: pmapamb.c,v 1.8 2015/08/10 14:10:16 taschreg Exp taschreg $
|
| 16 |
*/
|
| 17 |
|
| 18 |
|
| 19 |
#include "pmapamb.h"
|
| 20 |
#include "pmap.h"
|
| 21 |
|
| 22 |
|
| 23 |
int ambPmap (COLOR aval, RAY *r, int rdepth)
|
| 24 |
/* Factor irradiance from photon map into ambient coefficient aval;
|
| 25 |
* return 1 on success, else 0 (with aval unmodified) */
|
| 26 |
{
|
| 27 |
COLOR rcoef, photonIrrad;
|
| 28 |
/* Handle precedence in case of multiple photon maps:
|
| 29 |
* contrib > precomp > global */
|
| 30 |
PhotonMap *pmap = contribPhotonMapping ? contribPmap
|
| 31 |
: preCompPmap ? preCompPmap
|
| 32 |
: globalPmap;
|
| 33 |
|
| 34 |
/* Get photon irradiance either via 1 ambient bounce (final
|
| 35 |
* gather) if ambounce > 0, or directly if ambounce < 0. */
|
| 36 |
if (pmap && (rdepth || ambounce < 0)) {
|
| 37 |
/* Temporarily factor ambient value into ray coefficient
|
| 38 |
* (required for contribution photon map) */
|
| 39 |
copycolor(rcoef, r -> rcoef);
|
| 40 |
multcolor(r -> rcoef, aval);
|
| 41 |
|
| 42 |
/* Get photon irradiance via callback */
|
| 43 |
pmap -> lookupFlags = 0;
|
| 44 |
(pmap -> lookup)(pmap, r, photonIrrad);
|
| 45 |
|
| 46 |
/* Factor irradiance into ambient value and restore ray coeficient */
|
| 47 |
multcolor(aval, photonIrrad);
|
| 48 |
copycolor(r -> rcoef, rcoef);
|
| 49 |
|
| 50 |
return 1;
|
| 51 |
}
|
| 52 |
|
| 53 |
return 0;
|
| 54 |
}
|
| 55 |
|
| 56 |
|
| 57 |
int ambPmapCaustic (COLOR aval, RAY *r, int rdepth)
|
| 58 |
/* Factor specular-diffuse (caustic) irradiance from photon map into ambient
|
| 59 |
* coeff aval; return 1 if successful, else 0 (with aval set to zero) */
|
| 60 |
{
|
| 61 |
COLOR rcoef, photonIrrad;
|
| 62 |
/* Handle precedence in case of multiple photon maps: contrib > caustic */
|
| 63 |
PhotonMap *pmap = contribPhotonMapping ? contribPmap : causticPmap;
|
| 64 |
|
| 65 |
/* Get caustic photon density estimate at primary rays or when
|
| 66 |
* filling in ambient rays that have no global photon map to use */
|
| 67 |
if (pmap && (!rdepth || !globalPmap & !contribPmap & !preCompPmap)) {
|
| 68 |
/* Temporarily factor ambient value into ray coefficient
|
| 69 |
* (required for contribution photon map) */
|
| 70 |
copycolor(rcoef, r -> rcoef);
|
| 71 |
multcolor(r -> rcoef, aval);
|
| 72 |
|
| 73 |
/* Set caustic flag and get photon irradiance via callback */
|
| 74 |
pmap -> lookupCaustic = 1;
|
| 75 |
(pmap -> lookup)(pmap, r, photonIrrad);
|
| 76 |
|
| 77 |
/* Factor irradiance into ambient value and restore ray coeficient */
|
| 78 |
multcolor(aval, photonIrrad);
|
| 79 |
copycolor(r -> rcoef, rcoef);
|
| 80 |
|
| 81 |
return 1;
|
| 82 |
}
|
| 83 |
|
| 84 |
setcolor(aval, 0, 0, 0);
|
| 85 |
|
| 86 |
return 0;
|
| 87 |
}
|