Graphics Reference
In-Depth Information
Listing 32.11: The large-scale structure of the photon-mapping code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
main(){
set up image and display, and load scene
buildPhotonMap();
call photonRender for each pixel
display the resulting image
}
void App::buildPhotonMap(){
G3D::Array<EPhoton> ephotons;
LightList lightList(&(m_world->lightArray), &(m_world->lightArray2), rnd);
for (int i = 0; i < m_nPhotons; i++) {
ephotons.append(lightList.emitPhoton(m_nPhotons));
}
Array<IPhoton> ips;
for (int i = 0; i < ephotons.size(); i++) {
EPhoton ep = ephotons[i];
photonTrace(ep, ips);
m_photonMap.insert(ips);
}
}
The LightList represents a collection of all point lights and area lights in the
scene, and can produce emitted photons from these, with the number of photons
emitted from each source being proportional to the power of that source. List-
ings 32.12 and 32.13 show a little bit of how this is done: We sum the power (in
the R, G, and B bands) for each light to get a total power emitted. The probability
that a photon is emitted by the i th light is then the ratio of its average power (over
all bands) to the average of the total power over all bands. These probabilities are
stored in an array, with one entry per luminaire.
Listing 32.12: Initialization of the LightList class.
1
2
3
4
5
6
7
8
9
10
void LightList::initialize(void)
{
// Compute total power in all spectral bands.
foreach point or area light
m_totalPower += light.power() //totalPower is RGB vector
// Compute probability of emission from each light
foreach point or area light
m_probability.append(light.power().average() / m_totalPower.average());
}
With these probabilities computed, the only subtlety remaining is selecting
a random point on the surface of an area light (see Listing 32.13). If the area
light has some known geometric shape (cube, sphere, ...),wecanuse theobvi-
ous methods to sample from it (see Exercise 32.12). On the other hand, if it's
represented by a triangle mesh, we can first pick a triangle at random, with the
probability of picking a triangle T proportional to the area of T , and then pick a
point in that triangle uniformly at random. Exercise 32.6 shows that generating
samples uniformly on a triangle may not be as simple as you think.
 
Search WWH ::




Custom Search