Our Properties: Gamasutra GameCareerGuide IndieGames Indie Royale GDC IGF Game Developer Magazine GAO
My Message close
Latest News
spacer View All spacer
 
May 22, 2012
 
Dealing with Android's fragmented market
 
How Epic Games' week-long game jam gave birth to Infinity Blade: Dungeons [2]
 
38 Studios' ongoing financial issues lead to staff layoffs
spacer
Latest Features
spacer View All spacer
 
May 22, 2012
 
arrow Kratos' Boss: The Studio Head of Sony Santa Monica Speaks [2]
 
arrow A Personal Journey: Jenova Chen's Goals for Games [21]
 
arrow Predicting Churn: Data-Mining Your Game [12]
spacer
Latest Blogs
spacer View All     Post     RSS spacer
 
May 22, 2012
 
'Unlocks' and the Gamification of Gaming [2]
 
Epic/Silicon Knights - tidbits from the (messy) lawsuit [2]
 
Pleasure without learning leads to addiction [16]
 
Gen4: The Hard Sell All Around [22]
 
A Grim Reminder: An analysis of Legend of Grimrock [10]
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
May 22, 2012
 
Edventure More
Video Game Instructor- Summer Camp
 
Harmonix Music Systems
Executive Producer
 
NetherRealm Studios
Senior Artist/Animator - NetherRealm Studios
 
NetherRealm Studios
Senior Software Engineer, Network - WB Games...
 
NetherRealm Studios
Senior Software Engineer
 
NetherRealm Studios
Senior Designer - WB Games/NetherRealm Studios -...
spacer
Latest Press Releases
spacer View All     RSS spacer
 
May 22, 2012
 
Barbily Games Implements
Improved Customer
Service...
 
Press release for Flip
Tag Madrid
 
GameShampoo.com to Appear
in Baycon 2012,
Present...
 
Mind of Man: Sentiment
Analysis is the Future
of...
 
Void Rim - Indie game off
to a great start
spacer
About
spacer Editor-In-Chief:
Kris Graft
Features Director:
Christian Nutt
News Director:
Frank Cifaldi
Senior Contributing Editor:
Brandon Sheffield
News Editors:
Frank Cifaldi, Tom Curtis, Mike Rose, Eric Caoili, Kris Graft
Editors-At-Large:
Leigh Alexander, Chris Morris
Advertising:
Jennifer Sulik
Recruitment:
Gina Gross
 
Feature Submissions
 
Comment Guidelines
Sponsor
News

  In-depth: Extracting dominant light from Spherical Harmonics
by Simon Yeung [Console/PC, Programming, Art]
Post A Comment
Share on Twitter
Share on Facebook RSS
 
 
February 17, 2012
 
In-depth: Extracting dominant light from Spherical Harmonics

[In this reprinted #altdevblogaday in-depth piece, game programmer Simon Yeung looks at extracting the dominant directional light from spherical harmonics-projected light, to fake specular lighting.]

Introduction

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.


Extracting dominant light direction

We can get a single dominant light direction from the SH projected environment lighting, Le. Consider we approximate the environment light up to band 1 (i.e. l=1):


Finding the dominant light direction is equivalent to choose an incoming direction, ω, so that Le(ω)is maximized. In other words, cosθ should equal 1:

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:


Extracting dominant light intensity

After extracting the light direction, the remaining problem is to calculate the light intensity. That means we want to calculate an intensity s, so that the error between the extracted light and the light environment is at a minimum (Le is the original environment light while Ld is the directional light):


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 (ci is the SH coefficient of the projected directional light):


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 s is the light color that can be ready for use in a direct lighting equation, which is defined as (detail explanation can be found in [4]):
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, c, that scales the SH projected directional light as such:


We can project both L(ω) and (n . ω) into SH to calculate the integral. To project the transfer function (n . ω) into SH, we can first align the n to +Z-axis, which is zonal harmonics, then we can rotate the ZH coefficient into any direction using the equation:


The ZH coefficients of (n . ω) are: (note that the result is different from Stupid Spherical Harmonics (SH) Tricks in the Normalization section as we have taken the π term outside the integral):


Then rotate the ZH coefficients such that the normal direction equals the light direction, ld (because we need ld = n as stated above):


Finally we can go back to compute the scaling factor, c, for the SH projected directional light (we calculate up to band=2):


Therefore the steps to extract the dominant light intensity are first to project the directional light into SH with a scaling factor c, and then light color, s, which can be calculated by:


WebGL Demo

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

Conclusion

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.

References
[1] Stupid Spherical Harmonics (SH) Tricks: http://www.ppsloan.org/publications/StupidSH36.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

[This piece was reprinted from #AltDevBlogADay, a shared blog initiative started by @mike_acton devoted to giving game developers of all disciplines a place to motivate each other to write regularly about their personal game development passions.]
 
   
 
Comments


none
 
Comment:
 




 
UBM Techweb
Game Network
Game Developers Conference | GDC Europe | GDC Online | GDC China | Gamasutra | Game Developer Magazine | Game Advertising Online
Game Career Guide | Independent Games Festival | Indie Royale | IndieGames

Other UBM TechWeb Networks
Business Technology | Business Technology Events | Telecommunications & Communications Providers

Privacy Policy | Terms of Service | Contact Us | Copyright © UBM TechWeb, All Rights Reserved.