Spherical-Harmonic Lighting (Irradiance Environment Maps)
Projects an environment's radiance onto nine spherical-harmonic coefficients per color channel, from which diffuse irradiance for any surface normal is evaluated with a tiny quadratic polynomial.
Also known as SH lighting, SH irradiance, L2 SH
In the family Light transport & global illumination, low-frequency lighting
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | new THREE.LightProbe(); LightProbeGenerator.fromCubeTexture() docs |
| Babylon.js 9.38.0 | Built in | pbrMaterial.brdf.useSphericalHarmonics = true (SH irradiance from the environment texture) docs |
| Godot 4.7 | Built in | LightmapGI.directional = true bakes directional lightmaps as spherical harmonics (LightmapGIData.uses_spherical_harmonics) docs |
| Unity | Built in | Lighting > Environment > Environment Lighting Source (Gradient / Skybox); Light Probes docs Ambient and light probes are stored as L1/L2 spherical harmonics. |
| Unreal 5.7 | Built in | Sky Light and Volumetric Lightmaps store diffuse lighting as spherical harmonics docs |
| Blender 5.2 | Built in | EEVEE Volume Light Probes encode baked indirect irradiance as spherical harmonic coefficients (sh_coef) in eevee_lightprobe_volume.cc docs |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Diffuse reflection is a cosine-weighted average of incoming light, and that cosine kernel is smooth. Its spectrum falls off quickly, with about 99 percent of the energy in the first three bands (order 0, 1, 2). So instead of storing a cubemap and convolving it per pixel, you project the radiance onto spherical harmonics: nine coefficients L_lm per color channel (27 floats).
Projection is a one-time integral over the sphere, done by Monte Carlo sampling or by summing a cubemap with solid-angle weights. Irradiance for a normal n is then a quadratic form in n: the zeroth band contributes a constant, the first band a linear term, the second a quadratic one, with fixed band attenuation constants taken from the cosine lobe's SH coefficients. In a shader this is a dozen multiply-adds.
Because the representation is linear, blending probes or dynamic lights is just adding coefficient vectors, and rotations are matrix operations on coefficients. Windowing (a gentle filter that reduces ringing) is a common cleanup when the source has high dynamic range.
When to choose it
Reach for it when
- need cheap diffuse ambient light from a sky
- environment lighting stored in a few numbers
- dynamic objects need soft lighting from probes
- diffuse irradiance without sampling a cubemap many times
- compact baked lighting representation
Choose it for diffuse ambient light from a sky or probe, for dynamic objects inside Irradiance Volumes and Light Probes, and as the basis for many baked-lighting formats.
Prefer Split-Sum Image-Based Lighting alongside it for the specular half of image-based lighting; SH cannot represent a sharp reflection. Prefer Precomputed Radiance Transfer when you also want self-shadowing and interreflection of the object itself. Prefer a prefiltered diffuse cubemap when you want exact cosine convolution without L2 ringing.
Field marks
- Ringing: strong, small lights produce negative irradiance or bright halos on the opposite side (visible with a sun in the environment)
- Cannot represent sharp directional lights or shadows; the result is a soft ambient wash
- L1-only variants lose contrast compared with a true cosine convolution
- Banding or color shifts when HDR values are clamped before projection, since peaks dominate the coefficients
Presets
L2 SH irradiance vs brute-force convolution
{
"samples": 192,
"albedo": 0.8
}Show GLSL (48 lines)
// GLSL ES 3.0, Shadertoy-style. Left: brute-force cosine-convolved env. Right: order-2 SH irradiance.
const int N = 192; // projection samples
const float ALBEDO = 0.8;
vec3 env(vec3 d){
vec3 sky = mix(vec3(0.55,0.7,1.0), vec3(0.15,0.3,0.7), clamp(d.y,0.0,1.0));
vec3 gnd = vec3(0.22,0.16,0.1);
vec3 c = d.y > 0.0 ? sky : gnd;
vec3 sun = normalize(vec3(0.6,0.5,0.3));
c += vec3(9.0,7.0,4.5) * pow(max(dot(d,sun),0.0), 48.0);
return c;
}
vec3 fib(int i){
float y = 1.0 - 2.0*(float(i)+0.5)/float(N);
float r = sqrt(1.0-y*y), a = 2.399963*float(i);
return vec3(r*cos(a), y, r*sin(a));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 uv = (fragCoord - 0.5*iResolution.xy) / iResolution.y;
vec3 bg = mix(vec3(0.12), vec3(0.2), uv.y+0.5);
float side = uv.x < 0.0 ? -1.0 : 1.0;
vec2 q = uv - vec2(0.25*side, 0.0);
float rad = 0.22;
if (dot(q,q) > rad*rad) { fragColor = vec4(bg,1.0); return; }
vec2 p = q/rad;
vec3 n = vec3(p.x, p.y, sqrt(1.0-dot(p,p)));
float ca = cos(iTime*0.5), sa = sin(iTime*0.5);
n = vec3(ca*n.x + sa*n.z, n.y, -sa*n.x + ca*n.z);
vec3 Lc[9]; for (int k=0;k<9;k++) Lc[k] = vec3(0.0);
vec3 ref = vec3(0.0);
for (int i=0;i<N;i++){
vec3 d = fib(i); vec3 L = env(d);
ref += L*max(dot(n,d),0.0);
Lc[0] += L*0.282095;
Lc[1] += L*0.488603*d.y; Lc[2] += L*0.488603*d.z; Lc[3] += L*0.488603*d.x;
Lc[4] += L*1.092548*d.x*d.y; Lc[5] += L*1.092548*d.y*d.z;
Lc[6] += L*0.315392*(3.0*d.z*d.z-1.0);
Lc[7] += L*1.092548*d.x*d.z; Lc[8] += L*0.546274*(d.x*d.x-d.y*d.y);
}
float w = 4.0*3.14159265/float(N);
for (int k=0;k<9;k++) Lc[k] *= w;
ref *= w/3.14159265;
vec3 E = 0.429043*Lc[8]*(n.x*n.x-n.y*n.y) + 0.743125*Lc[6]*n.z*n.z + 0.886227*Lc[0] - 0.247708*Lc[6]
+ 2.0*0.429043*(Lc[4]*n.x*n.y + Lc[7]*n.x*n.z + Lc[5]*n.y*n.z)
+ 2.0*0.511664*(Lc[3]*n.x + Lc[1]*n.y + Lc[2]*n.z);
vec3 sh = max(E, 0.0)/3.14159265;
vec3 col = ALBEDO * (side < 0.0 ? ref : sh);
fragColor = vec4(pow(col/(1.0+col), vec3(1.0/2.2)), 1.0);
}Attribution: written for this index; SH constants from the Ramamoorthi-Hanrahan irradiance formula · basis: 0
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| sh-l2-irradiance-comparison | Tesla T4 1920x1080 | 69.2× baseline (extreme) · 2.28 ms / 2.46 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| sh-l2-irradiance-comparison | NVIDIA L4 1920x1080 | 52.8× baseline (heavy) · 0.839 ms / 0.869 ms · 2.7× faster on L4 | opengl-timer-query · Cross-architecture validation |
| sh-l2-irradiance-comparison | NVIDIA A100-SXM4-40GB 1920x1080 | 48.8× baseline (heavy) · 1.40 ms / 1.43 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Light Stage Reflectance Capture, Environment mapping, cubemaps and skyboxes, Irradiance Volumes and Light Probes; cited by LEADR mapping, Precomputed Radiance Transfer, 4× MSAA Sort-Free Stochastic Gaussian Splatting, All-Frequency Shadows via Wavelet Lighting.
Crosses
- Split-Sum Image-Based Lighting: SH supplies the diffuse term and the split-sum prefiltered map supplies the specular term of environment lighting.
Sources
- primaryRavi Ramamoorthi, Pat Hanrahan (2001). An efficient representation for irradiance environment maps. Proceedings of the 28th annual conference on Computer graphics and interactive techniques.Verified via crossref · 2026-11-29doi:10.1145/383259.383317
- tutorialPeter-Pike Sloan. Stupid Spherical Harmonics (SH) Tricks. GDC 2008.Verified via live page · 2026-11-29