Submitted by , posted on 13 November 2003

Image Description, by

This is my implementation of the SH (Spherical Harmonics) Lighting. What my little demo does is substitute a real light for its spherical harmonics projection. The algorithm is a little complicated but it boils down to

1) Get a light's position and color
2) Project that light into a environment map (spherical)
3) Get Spherical Harmonics coefficients from the environment map
4) Pass those coefficients to a vertex program that will do vertex level diffuse lighting

In the picture, the 2 upper images are obtained using normal lighting (OpenGL lights plus a vertex program to do the actual lighting), while the 2 bottom images are obtained using the spherical harmonics coefficients of the lights projected into the environment map. There are 3 lights in the scene.

I know that D3DX offers utility functions for calculating coefficients out of a given light, but here I coded my own utility functions. The demo is coded entirely in OpenGL. The papers I used are:

Spherical Harmonics Lighting: The Gritty Details - Robin Green (great because it explains very good the mathematics behind the technique)
An Efficient Representation for Irradiance Environment Maps - Ravi Ramamoorthi & Pat Hanrahan (good for the actual algorithm implementation explanation)

The GDC 2003 talk that Tom Forsyth and Peter Pike-Sloan gave.

The model I am using is taken from a tutorial from Keep up the good work guys.

The demo can be downloaded from:

Any feedback is greatly appreciated

Vlad Stamate.

Image of the Day Gallery



Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.