- +1 for introducing them as real-valued functions over cartesian coordinates!
Typically, spherical harmonics are introduced as a complex function over spherical coordinates, which makes them much easier to derive, but imo hides their beauty.
The real-valued, cartesian form of regular spherical harmonics is also called "solid harmonics" or "harmonic polynomials", in case you want to dig deeper.
- If one needs to describe (and maybe compress) functions or data on a sphere, spherical harmonics are really a thing.
An alternative would be to construct a new function (or matrix) that is not only periodic in azimuth, but also in elevation (i.e., extend elevation to a full circle -pi to +pi). Then, one can simply compute two independent Fourie r transforms: along azimuth and along elevation. [1] The same idea works on matrices using the Discrete Fourier transform (DFT/FFT). However, you then have to accept things like that your data points are all equal at the poles.
[1] https://en.wikipedia.org/wiki/Double_Fourier_sphere_method
- > spherical harmonics can have uses beyond lighting
This math is also used in Ambisonic surround sound though newer techniques use planewave expansion.
For games, the full-sphere encoding of Ambisonic B-format can be decoded for arbitrary speaker locations and the soundfield rotated around any axis. I'm not sure if its ever been used for a game though.
- ... also quantum mechanics. The textbook solution for the wavefunction of the hydrogen atom involves spherical harmonics.
- That fact is betrayed by the the similarity of the shapes of atomic orbitals and the sensitivity patterns of Abisonic B-format channels.
https://en.wikipedia.org/wiki/Ambisonics#Higher-order_ambiso...
https://en.wikipedia.org/wiki/Atomic_orbital#Orbitals_table
...and the same patterns appear on the unit disk with the Zernike polynomials, used to describe optical aberrations and more.
- Ambisonics can give one end game audio
- end-game audio?
Or it can give game audio to one end?
- This is really great. I always saw those harmonic shapes as electron orbitals, I had no idea they could be used in lighting too - so cool.
It made me wonder - why do the electron orbitals take those shapes in say a hydrogen atom? Is there a constraint on the electron and proton together that make it fit only to spherical harmonic functions?
- The reason is that electrons (like all quantum mechanical objects) are wavelike. In an isolated hydrogen atom, the electron is in a spherically symmetric environment, so the solutions to the wave equation have to be spherical standing waves, which are the spherical harmonics. The wave frequencies have to be integer divisions of 2pi or else they would destructively interfere. (Technically each solution is a product of a spherical harmonic function and a radial function that describes how fast the electron wave decays vs distance from the nucleus)
What’s interesting is if the environment is not spherically symmetric (consider an electron in a molecule) the solutions to the wave equation (the electronic wave functions) are no longer spherical harmonics, even though we like to approximate them with combinations of spherical harmonic basis functions centered on each nucleus. It’s kind of like standing waves on a circular drum head (hydrogen atom) vs standing waves on an irregular shaped drum head
Of course the nucleus also has a wave nature and in reality this interacts with the electrons, but in chemistry and materials we mostly ignore this and approximate the nucleus like a static point charge from the elctrons perspective because the electrons are so much lighter and faster
- Ah amazing - thank you for the response! I have a couple of related questions - is it that the non 2 pi frequencies exist, but they destructively interfere so we can't see them? My understanding is that the radial function for the electron is zero at the nucleus - there is no possibility of it being found there - but why is that the case?
- Awesome write up. Is the appeal of spherical harmonics in graphics compression?
Like, if you know the third order harmonics that's only 16 values you have to pass around
- For sure that's a big reason but it's also a useful basis for doing lighting calculations because of their sphere like nature. They are quite efficient in dynamic scenes and historically used in a lot of precalc to do something akin to real time Global Illumination
- Author here. Please let me know if the sample code doesn't work for you. It's all single threaded dumb JavaScript which makes it very easy to read, but definitely not performant. I decided to stick with it for didactic reasons, but still worried that it may hang someone's browser.
- Would it be practical to use high resolution spherical harmonics as a replacement for cube maps?
- Not really. Besides the problems with ringing outlined in the post, the number of coefficients required to capture higher frequency detail grows quadratically, requiring not only more storage but also operations to evaluate. Which makes straightforward cubemap replacement impractical.