This sample demonstrates how to use ID3DXPRTEngine, a precomputed radiance transfer (PRT) simulator that uses low-order spherical harmonics. The sample then demonstrates how to compress the results with Clustered principal component analysis (CPCA) and view the compressed results with arbitrary lighting in real time using a vs_1_1 shader.
Source: | (SDK root)\Samples\C++\Direct3D\PRTDemo |
Executable: | (SDK root)\Samples\C++\Direct3D\Bin\x86 or x64\PRTDemo.exe |
PRT using low-order spherical harmonic basis functions has a number of advantages over typical diffuse (N • L) lighting. Area light sources and global effects such as interreflections, soft shadows, self shadowing, and subsurface scattering can be rendered in real time after a precomputed light transport simulation. CPCA allows the results of the simulator to be compressed so the shader does not need as many constants or per-vertex data.
The basic idea is first to run a PRT simulator offline as part of the art content creation process and save the compressed results for later real-time use. The light transport simulator models global effects that would typically be very difficult to do in real time. The real-time engine evaluates the lights in terms of spherical harmonic basis functions and sums them up into a single set of spherical harmonic basis coefficients describing the entire lighting environment. It then uses a vertex shader to arrive at the vertex's diffuse color by combining the compressed simulator results and the lighting environment. Because the offline simulator did the work of computing the interreflections and soft shadows, this technique is visually impressive, efficient, and can be used for real-time lighting.
For more detail about the math behind PRT, clustered principal component analysis (CPCA), and spherical harmonics, see PRT Equations and the following references.