   [SOLVED] SH, Extracting directional light and color
Background:I'm looking to implement a Screen-Space Spherical Harmonic Lighting renderer, similar to what is outlined here & here. Sadly, my understanding of SH is weak, and the only information sources I have found deal with static IBL. So I have a few questions to learn what I need to know about SH and dynamic lighting.Questions:For the following questions, assume 1st order SH, with just four coefficients.How to correctly generate SH coefficients?How to add directional/point/spot lights to SH coefficients?How to correctly apply SH coefficients in a shader?Is it true that a directional & an ambient light can be extracted from SH coefficients? If so, how?I've heard you can accelerate SH coefficient computation via a cubemap LUT. How would I generate said LUT?Thanks for any help you can provide.EDIT:I am reusing this post, since I merely narrowed the focus of my questions. This topic now focuses on question #4, which I have reworded below to avoid ambiguity.According to "Stupid SH tricks (pg. 12)", it is possible to extract directional lights from SH coefficients. Sadly, the math seems to be way over my head. Can anyone explain what is the correct way to extract the dominant direction and color-intensity from 1st order SH coefficients? (Pseudo-code/short-answer)[Edited by - n00body on May 17, 2010 10:01:59 PM]
  1. How to correctly generate SH coefficients?Wikipedia tells you the constants to use for i think up to 5th order? The foruma can be found in a presentation called Spherical Harmonics: The Gritty Details (or something like that)2. Follow that presentation. Technically you can't add a point or spot light to a SH. SH can be thought of as a low resolution cubemap. The way to support point & spot lights is to have multiple sets of SH coefficients in the world and picking/blending between them per object.3. Its pretty much exactly the same as the process in #1, but supplying a normal instead of a light direction. Its explained in that presentation too.4. You can't separate directional and ambient light once they are in the one SH. You can take the 1st coefficient and just use that as the ambient term, but you may end up with negative diffuse lights in that case.5. GPU Gems 2 or 3 has that in it. Its available online at the Nvidia website.   ;  I've changed the focus of my topic. Please read the EDITs I made to the original post.   ;  Just check out the march of the froblins demo paper by AMD, has HLSL for question #4.   ;  Thanks, that was the crucial piece of information that I lacked. The sad part is that I had the pdf already, albeit buried in a misc pile. Fortunately, I found the information you mentioned.Thanks for the help. ;)   