Spherical Harmonics in games
Here is pretty much everything you need to know about spherical harmonics to use them in games:
- Spherical Harmonics are not scary at all :)
- An Efficient Representation for Irradiance Environment Maps
- Spherical Harmonics in Actual Games
- Spherical Harmonic Lighting: The Gritty Details
- Stupid Spherical Harmonics Tricks
- DirectX SDK samples contain all the C++ and HLSL code that you might need to get started
C++ code to calculate shader constants for evaluation on GPU:
(DirectX SDK) IrradianceVolume\PRTMesh.cpp, CPRTMesh::ComputeSHIrradEnvMapConstants()
HLSL code to evaluate SH for a given normal:
(DirectX SDK) IrradianceVolume\SHIrradianceEnvMap.fx
Also, DirectX SDK comes with a bunch of functions to get you going quickly. For example there is D3DXSHProjectCubeMap(), which generates spherical harmonic coefficients from a given cubemap.
PS: There one thing to keep in mind, though: SH are not the only option for storing lighting information. One great alternative is Valveās Ambient Cube (page 28), which gives quality somewhere between 2-band and 3-band SH.
Updated January 9th, 2011