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