Sponsored By

In-depth: Photon mapping and baking light maps

In this reprinted <a href="http://altdevblogaday.com/">#altdevblogaday</a> in-depth piece, game programer Simon Yeung shares an overview on how to bake light maps of indirect lighting data by sampling from the photon map.

July 3, 2012

5 Min Read
Game Developer logo in a gray background | Game Developer

[In this reprinted #altdevblogaday in-depth piece, game programer Simon Yeung shares an overview on how to bake light maps of indirect lighting data by sampling from the photon map.] Continuing from my previous post, this article will describe how light maps are calculated from the photon map. My light map stores incoming radiance of indirect lighting on a surface which are projected into Spherical Harmonics (SH) basis. Four SH coefficients is used for each color channels. So three textures are used for RGB channels (total 12 coefficients).

Baking the light map

To bake the light map, the scene must have a set of unique, non-overlapping texture coordinates (UV) that correspond to a unique world space position so that the incoming radiance at a world position can be represented. This set of UV can be generated inside a modeling package or using UVAtlas. In my simple case, this UV is mapped manually. To generate the light map, given a mesh with unique UV and the light map resolution, we need to rasterize the mesh (using scan-line or half-space rasterization) into the texture space with interpolated world space position across the triangles. So we can associate a world space position to a light map texel. Then for each texel, we can sample the photon map at the corresponding world space position by performing a final gather step just like in the previous post for offline rendering. So the incoming radiance at that world space position, hence the texel in the light map, can be calculated. Then the data is projected into SH coefficients, stored in three 16-bits floating point textures. Below is a light map that extracts the dominant light color from SH coefficients: The baked light map showing the dominant light color from SH coefficients

Using the light map

After baking the light map, during run-time, the direct lighting is rendering the usual way, a point light is used to approximate the area light in the ray traced version, and the difference is more noticeable at the shadow edges.

Then we sample the SH coefficients from the light map to calculate the indirect lighting:

Combining the direct and indirect lighting, the final result becomes:

As we store the light map in SH, we can apply a normal map to the mesh to change the reflected radiance.

We can also apply some tessellation, adding some ambient occlusion (AO) to make the result more interesting:

Conclusion

This post gives an overview on how to bake light maps of indirect lighting data by sampling from the photon map. I use SH to store the incoming radiance, but other data can be stored such as storing the reflected diffuse radiance of the surface, which can reduce texture storage and doesn't require floating point texture. Besides, the SH coefficients can be store per vertex in the static mesh instead of light map. Lastly, by sampling the photon map with final gather rays, light probe for dynamic objects can also be baked using similar methods.

References

[This piece was reprinted from #AltDevBlogADay, a shared blog initiative started by @mike_acton devoted to giving game developers of all disciplines a place to motivate each other to write regularly about their personal game development passions.]

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like