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