---
id: "spherical-harmonics-lighting"
title: "Spherical-Harmonic Lighting (Irradiance Environment Maps)"
aliases: [SH lighting, SH irradiance, L2 SH]
domain: "gi"
stage: "lighting"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot]
year_introduced: 2001
inputs: [hdr-image]
outputs: [irradiance-probes]
style: "photoreal"
dynamic: "both"
cost: "cheap"
authority: "Ramamoorthi & Hanrahan, 2001"
url: "https://texelatlas.vercel.app/t/spherical-harmonics-lighting/"
sources_verified_at: "2026-11-29"
---
# Spherical-Harmonic Lighting (Irradiance Environment Maps) (Ramamoorthi & Hanrahan, 2001)

> 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.

## 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

## 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 use it

Choose it for diffuse ambient light from a sky or probe, for dynamic objects inside [irradiance-volumes](irradiance-volumes), and as the basis for many baked-lighting formats.

Prefer [split-sum-ibl](split-sum-ibl) alongside it for the specular half of image-based lighting; SH cannot represent a sharp reflection. Prefer [precomputed-radiance-transfer](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.

## Cost

cheap — A few dozen ALU ops per pixel and 27 floats of storage per probe.
Measured GPU Weight: 69.22× baseline (extreme) — 2.2773 ms median / 2.4565 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 52.75× baseline (heavy) — 0.8387 ms median (2.72× faster on L4).
Ampere A100 scaling: 48.78× baseline (heavy) — 1.4049 ms median (1.62× faster on A100).

## Failure modes

- 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

## Engine support

- babylonjs: builtin — `pbrMaterial.brdf.useSphericalHarmonics = true (SH irradiance from the environment texture)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Materials/PBR/pbrBRDFConfiguration.ts, checked 2026-12-01)
- blender: builtin — `EEVEE Volume Light Probes encode baked indirect irradiance as spherical harmonic coefficients (sh_coef) in eevee_lightprobe_volume.cc` (evidence: https://github.com/blender/blender/blob/main/source/blender/draw/engines/eevee/eevee_lightprobe_volume.cc, checked 2026-12-01)
- godot: builtin — `LightmapGI.directional = true bakes directional lightmaps as spherical harmonics (LightmapGIData.uses_spherical_harmonics)` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/LightmapGI.xml, checked 2026-12-01)
- threejs: builtin — `new THREE.LightProbe(); LightProbeGenerator.fromCubeTexture()` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/lights/LightProbe.js, checked 2026-12-01)
- unity: builtin — `Lighting > Environment > Environment Lighting Source (Gradient / Skybox); Light Probes` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/SphericalHarmonics.cs, checked 2026-12-01) — Ambient and light probes are stored as L1/L2 spherical harmonics.
- unreal: builtin — `Sky Light and Volumetric Lightmaps store diffuse lighting as spherical harmonics` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/sky-lights-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: hdr-image
- Outputs: irradiance-probes
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot

## Presets

### L2 SH irradiance vs brute-force convolution (glsl-fragment; rendered 2026-11-29)

```json
{
  "samples": 192,
  "albedo": 0.8
}
```

```glsl
// 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

## Combines with

- [Split-Sum Image-Based Lighting](https://texelatlas.vercel.app/t/split-sum-ibl.md): SH supplies the diffuse term and the split-sum prefiltered map supplies the specular term of environment lighting.

## Sources

1. [primary] Ravi Ramamoorthi, Pat Hanrahan (2001) An efficient representation for irradiance environment maps. Proceedings of the 28th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/383259.383317 (verified via crossref on 2026-11-29)
2. [tutorial] Peter-Pike Sloan Stupid Spherical Harmonics (SH) Tricks. GDC 2008. https://www.ppsloan.org/publications/StupidSH36.pdf (verified via http on 2026-11-29)

## Cite this entry

Texel. "Spherical-Harmonic Lighting (Irradiance Environment Maps)." https://texelatlas.vercel.app/t/spherical-harmonics-lighting/ (accessed 2026-12-01).
