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