Spherical harmonics are a Resonite system that blend values (individual harmonics) using an integer Order using the Coder<T> library into a single value. In mathematics, the spherical harmonics are a special set of functions that can be added together in a weighted sum to create any function defined on a sphere's surface. Resonite is able to combine the harmonics up to 4th order (count starts at 0th order) with each increasing order providing higher resolution/definition/information.
How this works mathematically is outside the scope of this wiki, and is better explained on it's wikipedia page [1].
Usage
Spherical harmonics can be used in many different areas, including:
- Audio mapping/direction
- Mesh creation (to visualize the spherical harmonic)
- Light data (used for color, skyboxes, ambient/world lighting)
- Gaussian Splat rendering
In general, they can be used to approximate functions whose domain can be represented as the surface of a sphere: every point on the surface has some value like color, temperature, brightness, transparency, volume, etc.
Similar Concepts
The spherical harmonics form a basis for the functions on a sphere (technically SO(3)). This allows you to mix and match them to create many arbitrary values out of a small set of simple terms. You can also decompose complex structures into their unique constituent parts (often with a bit more effort). You may already be familiar with other bases and their properties:
- The X, Y, and Z unit vectors form a basis in 3D space that you can use to locate any point in the world and all points have a unique (X ,Y, Z) value.
- are a basis that you can use to make any polynomial
- Sine waves with different frequencies are a basis and can be used to create any function (e.g. sound wave). Sine waves are also an example of harmonic functions like the spherical harmonics. Because of this, the spherical harmonics can be thought of as the 'frequencies' or 'modes' of the sphere's surface.
While the fundamental principles may be simple, knowing which individual values to tweak to produce some desired outcome is often incredibly difficult. Therefore, most uses of harmonics use specialized algorithms for decomposing functions into a more digestible form: such as using a (Fast) Fourier Transform for decomposing waves into their individual sinusoidal frequency components.
Technical Notes
Spherical harmonics are blended using the code below
public static T Evaluate<T>(this ISphericalHarmonics<T> harmonics, float3 dir) where T : unmanaged
{
T val = default(T);
dir = new float3(0f - dir.x, 0f - dir.y, dir.z);
for (int i = 0; i <= harmonics.Order; i++)
{
for (int j = -i; j <= i; j++)
{
T t = harmonics[CoefficientIndex(i, j)];
float s = EvaluateScale(i, j, in dir);
val = Coder<T>.Add(val, Coder<T>.Scale(t, s));
}
}
return val;
}
The EvaluateScale(i, j, in dir) uses precalculated values that would take much longer to evaluate if done on the fly. How to calculate these values are also explained on the spherical harmonics wikipedia page [2].