ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapamb.c
Revision: 2.2
Committed: Fri May 8 13:20:23 2015 UTC (9 years ago) by rschregle
Content type: text/plain
Branch: MAIN
Changes since 2.1: +3 -2 lines
Log Message:
Double-counting bugfix for glow sources (thanks DGM!), revised copyright

File Contents

# Content
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 2.1 2015/02/24 19:39:26 greg Exp $
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 only at primary rays */
62 if (pmap && !rdepth) {
63 /* Temporarily factor ambient value into ray coefficient
64 * (required for contribution photon map) */
65 copycolor(rcoef, r -> rcoef);
66 multcolor(r -> rcoef, aval);
67
68 /* Set caustic flag and get photon irradiance via callback */
69 pmap -> lookupFlags = PMAP_CAUST_BIT;
70 (pmap -> lookup)(pmap, r, photonIrrad);
71
72 /* Factor irradiance into ambient value and restore ray coeficient */
73 multcolor(aval, photonIrrad);
74 copycolor(r -> rcoef, rcoef);
75
76 return 1;
77 }
78
79 setcolor(aval, 0, 0, 0);
80
81 return 0;
82 }