🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Verifying correctness of (ambient) diffuse lighting

Started by
11 comments, last by Aressera 1 month ago

Hello, again!

I decided to run a bunch of experiments on SH computations, which is why my response took a few days. One of these experiments to try to brute-force the normalization factors for each order. I did this by brute-forcing an irradiance cube map, then fitting the SH normalization factors using stochastic gradient descent to find the optimal values.

I took the bases (?) up to order 4 from Wikipedia: https://en.wikipedia.org/wiki/Table_of_spherical_harmonics#Real_spherical_harmonics

After a few seconds, it converges to something like the following values:

A0: 3.1424568
A1: 2.095541
A2: 0.78717023
A3: 0.0
A4: -0.1300998

These values are within ~0.02 of the values listed in https://cseweb.ucsd.edu/~ravir/papers/envmap/envmap.pdf​ at the top right on page 2:​

A0 = 3.141593
A1 = 2.094395
A2 = 0.785398
A3 = 0.0
A4 = −0.130900

More exactly, the correct normalization values are:

A0 = PI
A1 = 2/3*PI
A2 = 1/4*PI
A3 = 0
A4 = 1/24*PI

Note that all these values are off by a factor of 4, so the correct values are actually:

A0 = 4*PI
A1 = 8/3*PI
A2 = PI
A3 = 0
A4 = 1/6*PI

I can confirm that these normalization values look very good. Using 4*PI as the normalization factor for all orders of spherical harmonics looks very wrong.

Using order 2 spherical harmonics (9 coefficients) indeed seems to be by far the most value for your money. Going up to order 4 with 25 coefficients (of which only 18 have a non-zero normalization factor) gives an almost identical result while more than doubling the computation cost.

Advertisement

theagentd said:
Using 4*PI as the normalization factor for all orders of spherical harmonics looks very wrong.

What you describe as “normalization values" are just the coefficients of the SH functions of a particular band. When I say that the normalization of SH is 1/sqrt(4pi), I am referring to the whole set of SH functions from order 0 up to arbitrary order. I'm not suggesting you put 1/sqrt(4pi) in front of every SH function, that's obviously wrong. The choice of 1/sqrt(4pi) as the overall scaling is so that when you compute the inner product of SH functions for a particular direction and SH coefficients of your data, that you get 1/sqrt(4pI) * 1/sqrt(4pi) = 1/(4pi), which exactly cancels out the surface area of a unit sphere (4pi).

For reference, I've been working with SH for nearly a decade now, and have published 2 academic papers in IEEE VR conference (1 and 2) which specifically focus on using SH for audio. SH are heavily used in audio to represent and decode spatial sound fields, such as with ambisonics.

With ambisonics, there are different normalization conventions in use, such as SN3D, N3D. These exist so that SH data can be described by fixed-point audio samples with limited range. They apply different scale factors to the individual bands to maximize the use of the available bits per sample. To get the correct result when decoding ambisonics to loudspeakers or binaural audio (calculated by the inner product of the ambisonics with the decoder), it's important to compensate for these normalization conventions when constructing the decoder coefficients. You'll notice that the definition of SH for ambisonics omits most of the constants of standard SH functions, again to make best use of the fixed-point range. To convert between N3D ambisonics and standard SH, you divide by 1/sqrt(4pi). This choice means that if the original sound field has values in [0,1] before encoding, that the encoded ambisonics of order 0 will be in range [0,1] as well. The SN3D normalization convention applies additional per-band modifications to the basis functions so that all bands beyond 0 also fit in the [0,1] range, which is not guaranteed by N3D. N3D is the same as standard SH except for the 1/sqrt(4pi) factor.

So, I can assure you that SH are scaled overall by 1/sqrt(4pi).

This topic is closed to new replies.

Advertisement