DirectXMath (aka XNAMath version 3) provides almost all the functionality of the original D3DXMath library with two exceptions. The first is the 'matrix stack' helper and the second is the 'spherical harmonics' math functions. The matrix stack is fairly easy to implement, but the SH math functions are another story. The original code for SH math in the D3DX utility library was written by John Snyder (MSR) and Peter-Pike Sloan (former Microsoft now at NVIDIA), and was the basis for a number of DirectX SDK samples and graphics publications as well as several ATI/AMD demos. With the removal of the SH math functionality from D3DX11 and the retirement of the D3DX library generally (see Where is the DirectX SDK?), this post provides a replacement for this functionality.
Note this post does not include the Precomputed Radiance Transfer (PRT) simulator that was shipped in D3DX9. You can continue to make use of that library for offline computations, and then use this post's SH math routines for runtime usage in a modern Direct3D 11 application without any legacy D3DX dependencies.
The DirectXSH.h/.cpp file pair provides the SH math functions. It is based on DirectXMath and requires Visual Studio 2012 or VS 2010 with the Windows 8.0 SDK.
DirectXSH.h/.cpp
Note it is fairly easy to modify these files if you must use XNAMath for compatibility with Xbox 360 or VS 2008 by removing namespaces and changing from SAL2 to VS-style SAL, but that is left as an exercise to the reader.
XMSHEvalDirection
XMSHRotate
XMSHRotateZ
XMSHAdd
XMSHScale
XMSHDot
XMSHMultiply
XMSHMultiply2 XMSHMultiply3 XMSHMultiply4 XMSHMultiply5 XMSHMultiply6
XMSHEvalDirectionalLight
XMSHEvalSphericalLight
XMSHEvalConeLight
XMSHEvalHemisphereLight
The DirectXSHD3D11.cpp module provides the function for computing the SH projection of a cubemap.
DirectXSHD3D11.cpp
SHProjectCubeMap
These files are provided subject to the Microsoft Public License (MS-PL).
Green, Robin. Spherical Harmonic Lighting: The Gritty Details. Game Developers' Conference, San Jose, CA, March 2003. PDF
Kautz, Jan. Peter-Pike Sloan, Jaakko Lehtinen. Precomputed Radiance Transfer: Theory and Practice. SIGGRAPH 2005 Course. Website.
Oat, Chris Oat and Natalya Tatarchuk. Irradiance Volumes for Games. Game Developers' Conference 2005, ATI Technologies, GDC 2005. PDF
Sloan, Peter-Pike. Stupid Spherical Harmonics (SH) Tricks. Game Developer Conference 2008 PDF PPTX
Sloan, Peter-Pike, Jan Kautz, and John Snyder. Precomputed Radiance Transfer for Real-Time Rendering in Dynamic, Low-Frequency Lighting Environments. ACM Transactions on Graphics (TOG), Proceedings of the 29th Annual Conference on Computer Graphics and Interactive Techniques (SIGGRAPH), pp. 527-536. New York, NY: ACM Press, 2002. PDF
Sloan, Peter-Pike, Jesse Hall, John Hart, and John Snyder. Clustered Principal Components for Precomputed Radiance Transfer. ACM Transactions on Graphics (TOG), Vol. 22, Issue 3 (SIGGRAPH), pp. 382-391. New York, NY: ACM Press, July 2003. PDF
Sloan, Peter-Pike, Ben Luna and John Snyder. Local, Deformable Precomputed Radiance Transfer. ACM Transaction on Graphics 24(3) [Proceedings of SIGGRAPH], 2005. PDF PPT
Sloan, Peter-Pike. Normal Mapping for Precomputed Radiance Transfer. ACM Symposium on Interactive 3D Graphics and Games 2006. March, 2006. PDF PPT
Xinguo Liu, Peter-Pike Sloan, Heung-Yeung Shum and John Snyder. All-Frequency Precomputed Radiance Transfer for Glossy Objects. Eurographics Symposium on Rendering 2004, June, 2004. PDF