February 17, 2012 | By
Simon Yeung

Spherical Harmonics(SH) functions can represent low frequency data such as diffuse lighting, where those high frequency details are lost after projected to SH. Luckily we can extract a dominant directional light from SH coefficients to fake specular lighting.

We can also extract more than 1 directional light from SH coefficients, but this post will only focus on extracting 1 dominant light, those interested can read Stupid Spherical Harmonics (SH) Tricks for the details. A webGL demo is provided at the last section which will only extract 1 directional light.

We can get a single dominant light direction from the SH projected environment lighting,

Finding the dominant light direction is equivalent to choose an incoming direction,

So we can extract the dominant light direction for a single color channel. Finally the dominant light direction can be calculated by scaling each dominant direction for RGB channels using the ration that converts color to grayscale:

After extracting the light direction, the remaining problem is to calculate the light intensity. That means we want to calculate an intensity

To minimize the error, differentiate the equation and solve it to equal zero:

If both lighting functions are projected into SH, the intensity can be simplified to:

The next step is to project the directional light (with unit intensity) into SH basis (

Therefore the SH coefficients of projected directional light can be calculated by substituting the light direction into the corresponding SH basis function.

As the SH projected directional light is in unit intensity, we want to scale it with a factor so that the extracted light intensity

For artist convenience, clight does not correspond to a direct radiometric measure of the light's intensity; it is specified as the color a white Lambertian surface would have when illuminated by the light from a direction parallel to the surface normal (lc = n).

So we need to calculate a scaling factor,

We can project both L(

The ZH coefficients of (

Then rotate the ZH coefficients such that the normal direction equals the light direction,

Finally we can go back to compute the scaling factor,

Therefore the steps to extract the dominant light intensity are first to project the directional light into SH with a scaling factor

A webGL demo (you'll need a webGL enabled browser such as Chrome) is provided to illustrate how to extract a single directional light to fake the specular lighting from the SH coefficient.

The specular lighting is calculated using the basic Blinn-Phong specular team for simplicity reasons. Other specular lighting equation can be used such as those physically plausible (The source code can be downloaded from here.).

Screenshot of the demo

Extracting the dominant directional light from SH projected light is easy to compute with the following steps: First, calculate the dominant light direction. Second, project the dominant light into SH with a normalization factor. Third, calculate the light color. The extracted light can be used for specular lighting to give an impression of high frequency lighting.

[1] Stupid Spherical Harmonics (SH) Tricks: http://www.ppsloan.org/publications/StupidSH36.pdf

[2] Light Factorization for Mixed-Frequency Shadows in Augmented Reality: http://zurich.disneyresearch.com/~wjarosz/publications/nowrouzezahrai11light.pdf

[3] Physically Based Rendering, Second Edition: From Theory To Implementation Ch.17.2.2

[4] Physically-Based Shading Models in Film and Game Production: http://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_a_notes.pdf

[3] Physically Based Rendering, Second Edition: From Theory To Implementation Ch.17.2.2

[4] Physically-Based Shading Models in Film and Game Production: http://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_a_notes.pdf

[5] PI or not to PI in game lighting equation: http://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/

[6] March of the Froblins: Simulation and Rendering Massive Crowds of Intelligent and Detailed Creatures on GPU: http://developer.amd.com/documentation/presentations/legacy/Chapter03-SBOT-March_of_The_Froblins.pdf

[7] Pick dominant light from sh coeffs: http://sourceforge.net/mailarchive/message.php?msg_id=28778827

[6] March of the Froblins: Simulation and Rendering Massive Crowds of Intelligent and Detailed Creatures on GPU: http://developer.amd.com/documentation/presentations/legacy/Chapter03-SBOT-March_of_The_Froblins.pdf

[7] Pick dominant light from sh coeffs: http://sourceforge.net/mailarchive/message.php?msg_id=28778827