# Spherical Harmonics Cubemap

This topic is 1141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on generating a spherical harmonics irradiance environment map for diffuse lighting.  I've read various papers on the topic ([1], [2], [3], [4]), and I've set to work implementing the process as a set of compute shaders.  I'm struggling with getting the right result.

I've iterated over an input cubemap and generated 9 coefficients each for R, G, and B.  I have a function to evaluate the coefficients for a direction.  When generating the output cubemap, do I just store this evaluation at each texel, or do I store the evaluation multiplied by the corresponding texel read from the input cubemap?

##### Share on other sites

Then how do I apply the coefficients?  I thought section 3.2 of this paper was telling me how to get the irradiance using the coefficients in a matrix and the normal of the object being lit.  It made sense to me then to generate an irradiance environment cubemap that cached all the normal directions I might sample for.

##### Share on other sites

MJP, you are the man.  I had to change CosineA2 to be Pi * 0.25f, which corresponds with the 1, 2/3, 1/4 bands.  But it works!  I am digesting the paper you linked me to, and I still have to adjust for the high dynamic range of the cubemaps I'm testing with, as a lot of the stuff ends up over-exposed.  But it's definitely looking much better:

Edited by Funkymunky

##### Share on other sites

I had to change CosineA2 to be Pi * 0.25f, which corresponds with the 1, 2/3, 1/4 bands

Whoops, sorry about that! I corrected the code, in case anybody else looks at this thread later on.

Either way, I'm glad that you got it to work!

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009716
• ### Who's Online (See full list)

There are no registered users currently online

×