---
id: "wavelet-all-frequency-relighting"
title: "All-Frequency Shadows via Wavelet Lighting"
aliases: [wavelet relighting, all-frequency PRT]
domain: "gi"
stage: "lighting"
realtime: "interactive"
platforms: [cpu, desktop-gpu]
year_introduced: 2003
inputs: [mesh, hdr-image]
outputs: [radiance]
style: "photoreal"
dynamic: "both"
cost: "medium"
authority: "Ng et al., 2003"
url: "https://texelatlas.vercel.app/t/wavelet-all-frequency-relighting/"
sources_verified_at: "2026-11-29"
---
# All-Frequency Shadows via Wavelet Lighting (Ng et al., 2003)

> Stores precomputed visibility per vertex as Haar wavelets of a cubemap and keeps only the largest coefficients of both the light and the visibility, so sharp shadows from high-frequency environment maps are relit in real time.

## Reach for it when

- sunny hdr sky shadows look too soft
- relight rigid objects with detailed environment maps
- all-frequency lighting and shadows in real time
- precomputed shadows that stay sharp under studio lights
- need sharp and soft lighting from the same environment

## How it works

[precomputed-radiance-transfer](precomputed-radiance-transfer) with spherical harmonics blurs shadows because low bands cannot represent hard edges. This method swaps SH for **Haar wavelets** on each cubemap face, which are localized in space and so can represent a sharp shadow edge with a few coefficients.

Offline, for each vertex, the visibility times cosine function over the cube map is transformed into the wavelet basis. Only the largest coefficients (a few tens to hundreds out of tens of thousands) are kept; the rest are zeroed. At runtime, the lighting environment is transformed to the same wavelet basis, and a **non-linear approximation** keeps its largest coefficients too. Because wavelets are orthonormal, the lit value of a vertex is the dot product of the two coefficient sets, which only needs the entries that are non-zero in *both*.

Non-linear selection adapts to the data per vertex and per environment, which is why a handful of coefficients captures both a bright small light and its shadows. Diffuse transfer is a vector; glossy transfer uses a matrix expressed in the same basis.

## When to use it

Choose it for rigid objects relit by high-frequency environment maps (HDR skies with a sun, studio lights) when hard shadows matter and low-order SH looks too soft.

Prefer [precomputed-radiance-transfer](precomputed-radiance-transfer) with SH for compact, cheap, smooth results. Prefer [spherical-harmonics-lighting](spherical-harmonics-lighting) for ambient-only lighting. Prefer [lightmap-baking](lightmap-baking) when the lighting never changes. Prefer [restir-di](restir-di) or ray traced shadows for modern dynamic scenes.

## Cost

medium — Per-vertex cost depends on the number of retained coefficients; precomputation is heavy and storage is large for dense meshes.
Measured GPU Weight: 27.88× baseline (heavy) — 0.9171 ms median / 0.945 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 22.16× baseline (heavy) — 0.3524 ms median (2.6× faster on L4).
Ampere A100 scaling: 15.95× baseline (moderate) — 0.4593 ms median (2× faster on A100).

## Failure modes

- Large precomputed data per vertex, and sparse coefficient lists are awkward to evaluate on GPUs
- Rigid-only: moving or deforming geometry invalidates the transfer
- Truncation artifacts: dropping coefficients leaves visible blockiness in the shadow edges for high compression ratios
- Per-vertex sampling limits shadow quality to the mesh density unless stored in textures

## Dataflow

- Inputs: mesh, hdr-image
- Outputs: radiance
- Platforms: cpu, desktop-gpu

## Presets

### Wavelet All-Frequency Relighting — low-order SH blurry shadows (left) vs sparse Haar wavelet sharp shadows (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_ENV_ROT": 0.55,
  "P_WAVELET_K": 0.92,
  "P_SPEC_GLOSS": 0.75,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_ENV_ROT = 0.55; // P Env Rotation [0.0, 2.2, 0.05]
const float P_WAVELET_K = 0.92; // P Wavelet Terms [0.1, 1.0, 0.02]
const float P_SPEC_GLOSS = 0.75; // P Specular Gloss [0.1, 1.0, 0.02]
const float P_SPLIT = 0.48; // P Low-SH / Wavelet [0.0, 1.0, 0.02]

mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }

// Sculpted relief bust / multi-lobe architectural knot with deep self-occluding crevices!
float mapSculpt(vec3 p) {
  // Pedestal floor at y = -0.58
  float dFloor = p.y + 0.58;
  // Twin interlocking sculptural rings + central sphere (casts crisp all-frequency self-shadows!)
  vec3 q1 = p - vec3(0.0, 0.05, 0.0);
  float dRing1 = length(vec2(length(q1.xz) - 0.54, q1.y)) - 0.13;
  vec3 q2 = q1;
  q2.xy = rot2(1.05) * q2.xy;
  float dRing2 = length(vec2(length(q2.xz) - 0.54, q2.y)) - 0.12;
  float dCore = length(q1) - 0.28;
  return min(dFloor, min(dCore, min(dRing1, dRing2)));
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.0025, 0.0);
  return normalize(vec3(
    mapSculpt(p + e.xyy) - mapSculpt(p - e.xyy),
    mapSculpt(p + e.yxy) - mapSculpt(p - e.yxy),
    mapSculpt(p + e.yyx) - mapSculpt(p - e.yyx)
  ));
}

// Soft raymarched directional visibility V(p, w) with selectable angular blur k
float marchVis(vec3 p, vec3 lDir, float kSoft) {
  float vis = 1.0;
  float t = 0.04;
  for (int i = 0; i < 24; i++) {
    float d = mapSculpt(p + lDir * t);
    if (d < 0.002) return 0.0;
    vis = min(vis, kSoft * d / max(t, 0.04));
    t += clamp(d, 0.025, 0.25);
    if (t > 2.6) break;
  }
  return clamp(vis, 0.0, 1.0);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  bool isWavelet = screenX >= split;
  float rotT = iTime * max(P_ENV_ROT, 0.0);
  float wavK = clamp(P_WAVELET_K, 0.08, 1.0);
  float gloss = clamp(P_SPEC_GLOSS, 0.05, 1.0);

  vec3 ro = vec3(0.0, 0.52, 2.28);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.18, -1.48));

  // Rotating high-contrast HDR environment with 2 sharp studio key lights + cool dome
  vec3 lKey1 = normalize(vec3(cos(rotT * 0.65) * 0.78, 0.62, sin(rotT * 0.65) * 0.78));
  vec3 lKey2 = normalize(vec3(-cos(rotT * 0.65 + 0.7) * 0.72, 0.58, -sin(rotT * 0.65 + 0.7) * 0.72));

  vec3 bg = mix(vec3(0.025, 0.032, 0.055), vec3(0.085, 0.125, 0.210), smoothstep(-0.3, 0.6, rd.y));
  // Show rotating bright HDR environment light lobes in background
  bg += vec3(1.8, 1.25, 0.65) * pow(max(dot(rd, lKey1), 0.0), 48.0);
  bg += vec3(0.55, 1.15, 1.85) * pow(max(dot(rd, lKey2), 0.0), 48.0);
  vec3 col = bg;

  float t = 0.05;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    float d = mapSculpt(ro + rd * t);
    if (d < 0.0025) { hit = true; break; }
    t += d;
    if (t > 8.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p);
    bool isFloor = (p.y < -0.56);
    vec3 alb = isFloor ? vec3(0.58, 0.60, 0.64) : vec3(0.84, 0.80, 0.74);

    if (!isWavelet) {
      // Left: Order-2 Spherical Harmonics (9 coeffs) heavily band-limits visibility & glossy BRDF -> washed-out blurry shadows!
      float vis1 = mix(0.45, 0.92, marchVis(p, lKey1, 2.2));
      float vis2 = mix(0.45, 0.92, marchVis(p, lKey2, 2.2));
      float shDiff1 = max(dot(n, lKey1) * 0.62 + 0.38, 0.0);
      float shDiff2 = max(dot(n, lKey2) * 0.62 + 0.38, 0.0);
      // Low-order SH cannot represent sharp specular highlights
      float shSpec1 = pow(max(dot(n, normalize(lKey1 - rd)), 0.0), 5.0) * 0.24 * gloss;
      vec3 shEnv = vec3(0.16, 0.22, 0.32) * (0.5 + 0.5 * n.y);
      col = alb * (vec3(1.15, 0.84, 0.56) * shDiff1 * vis1 * 0.72
                 + vec3(0.42, 0.74, 1.15) * shDiff2 * vis2 * 0.58
                 + shEnv)
          + vec3(1.0, 0.92, 0.82) * shSpec1;
    } else {
      // Right: Non-linear Haar Wavelet PRT preserves top-K sparse wavelets -> razor-sharp all-frequency shadows & glossy highlights!
      float sharpK = mix(4.0, 26.0, wavK);
      float vis1 = marchVis(p, lKey1, sharpK);
      float vis2 = marchVis(p, lKey2, sharpK);
      float diff1 = max(dot(n, lKey1), 0.0) * vis1;
      float diff2 = max(dot(n, lKey2), 0.0) * vis2;
      float specExp = mix(14.0, 88.0, gloss * wavK);
      float spec1 = pow(max(dot(n, normalize(lKey1 - rd)), 0.0), specExp) * vis1 * (0.45 + 0.85 * gloss);
      float spec2 = pow(max(dot(n, normalize(lKey2 - rd)), 0.0), specExp) * vis2 * (0.35 + 0.65 * gloss);
      float ao = clamp(0.35 + 0.65 * mapSculpt(p + n * 0.14) / 0.14, 0.2, 1.0);
      vec3 amb = vec3(0.10, 0.15, 0.24) * (0.4 + 0.6 * n.y) * ao;
      col = alb * (vec3(1.45, 0.98, 0.56) * diff1 + vec3(0.45, 0.85, 1.40) * diff2 + amb)
          + vec3(1.0, 0.92, 0.78) * spec1 * (isFloor ? 0.32 : 0.92)
          + vec3(0.68, 0.88, 1.0) * spec2 * (isFloor ? 0.24 : 0.72);
    }

    if (isFloor) col = mix(col, bg, 1.0 - exp(-t * 0.10));
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Lineage

- extends [Precomputed Radiance Transfer](https://texelatlas.vercel.app/t/precomputed-radiance-transfer.md)

## Sources

1. [primary] Ren Ng, Ravi Ramamoorthi, Pat Hanrahan (2003) All-frequency shadows using non-linear wavelet lighting approximation. ACM Transactions on Graphics. https://doi.org/10.1145/882262.882280 (verified via crossref on 2026-11-29)

## Cite this entry

Texel. "All-Frequency Shadows via Wavelet Lighting." https://texelatlas.vercel.app/t/wavelet-all-frequency-relighting/ (accessed 2026-12-01).
