{
 "id": "precomputed-radiance-transfer",
 "title": "Precomputed Radiance Transfer",
 "aliases": [
  "PRT",
  "SH PRT"
 ],
 "domain": "gi",
 "subdomain": "low-frequency lighting",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "desktop-gpu",
  "webgl2",
  "mobile-gpu"
 ],
 "year_introduced": 2002,
 "inputs": [
  "mesh",
  "hdr-image"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "Precomputes, per vertex or texel, how incoming low-frequency light maps to outgoing radiance including self-shadowing and interreflection, so relighting a rigid object under a changing environment is a dot product.",
 "how_it_works": "For a rigid object, how light at a point depends on the environment is linear. If the lighting is expressed in a basis (spherical harmonics), then outgoing radiance is a **transfer vector** dotted with the **lighting coefficient vector**. The transfer vector captures everything that depends only on geometry and material: visibility (self-shadowing), cosine falloff, and with extra bounces, interreflection.\n\nIn the offline stage, for each vertex or texel, you cast many rays and project the visibility times cosine onto SH, producing `n^2` coefficients (25 for order 4). For glossy materials the transfer is a **matrix** that maps lighting coefficients to coefficients of the exiting radiance, which is then evaluated for the view direction.\n\nAt runtime you project the current environment to SH (cheaply, even per frame, using [spherical-harmonics-lighting](spherical-harmonics-lighting)) and then compute a dot product per vertex (or per pixel with the coefficients in textures). Rotation of the light is a coefficient rotation, so it supports dynamic environments, but not moving geometry, which would invalidate the precomputed transfer.",
 "when_to_use": "Choose it for hero rigid objects or static scenes lit by changing low-frequency lighting (sky, time of day), where self-shadowed soft diffuse lighting is wanted.\n\nPrefer [irradiance-volumes](irradiance-volumes) when the object deforms or moves around a baked scene, since PRT is per-object. Prefer [wavelet-all-frequency-relighting](wavelet-all-frequency-relighting) when sharp shadows from high-frequency environments are needed. Prefer [lightmap-baking](lightmap-baking) when the lighting is fixed and you want per-texel detail.",
 "cost": {
  "class": "cheap",
  "notes": "Runtime is a dot product of 9 to 25 coefficients per vertex; offline precomputation is heavy."
 },
 "failure_modes": [
  "Low-order SH cannot represent sharp shadows or glossy highlights, so shadows look soft and generic",
  "Rigid geometry only: skinned meshes or moving occluders require recomputation",
  "Large storage for glossy transfer matrices (n^2 by n^2 per sample point)",
  "Ringing and negative values in the reconstructed radiance for strongly directional environments"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/566654.566612",
   "type": "paper",
   "title": "Precomputed radiance transfer for real-time rendering in dynamic, low-frequency lighting environments",
   "authors": [
    "Peter-Pike Sloan",
    "Jan Kautz",
    "John Snyder"
   ],
   "year": 2002,
   "venue": "ACM Transactions on Graphics",
   "url": "https://doi.org/10.1145/566654.566612",
   "ids": {
    "doi": "10.1145/566654.566612"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566654.566612",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566654.566612",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566654.566612",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566654.566612",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566654.566612",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "sloan2002precomputed"
  }
 ],
 "presets": [
  {
   "id": "precomputed-radiance-transfer-live",
   "title": "Precomputed Radiance Transfer — 9-band SH environment lighting with self-shadowed bounce",
   "runtime": "glsl-fragment",
   "params": {
    "P_ENV_ROTATION": 1,
    "P_SH_ORDER": 2,
    "P_SELF_SHADOW": 0.88,
    "P_BOUNCE_GAIN": 0.68
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_ENV_ROTATION = 1.0; // P Env Spin [0.0, 2.5, 0.05]\nconst float P_SH_ORDER = 2.0; // P SH Band Order [0.0, 2.0, 1.0]\nconst float P_SELF_SHADOW = 0.88; // P Self-Shadow [0.0, 1.4, 0.04]\nconst float P_BOUNCE_GAIN = 0.68; // P Interreflection [0.0, 1.5, 0.04]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\n// Sculpted concave/grooved architectural orb to showcase PRT self-shadowing & interreflection\nfloat mapSculpt(vec3 p) {\n  float dSphere = length(p) - 0.82;\n  // Carve three orthogonal concave bowl cavities and equatorial flute grooves\n  float c1 = length(p - vec3(0.68, 0.22, 0.52)) - 0.42;\n  float c2 = length(p - vec3(-0.62, 0.32, 0.48)) - 0.38;\n  float c3 = length(p - vec3(0.05, -0.58, 0.58)) - 0.38;\n  float d = max(dSphere, -c1);\n  d = max(d, -c2);\n  d = max(d, -c3);\n  // Subtle sculpted relief rings\n  float ring = 0.028 * sin(p.y * 18.0 + atan(p.z, p.x) * 4.0);\n  d += ring * smoothstep(0.2, 0.75, length(p.xz));\n  return d * 0.78;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapSculpt(p + e.xyy) - mapSculpt(p - e.xyy),\n    mapSculpt(p + e.yxy) - mapSculpt(p - e.yxy),\n    mapSculpt(p + e.yyx) - mapSculpt(p - e.yyx)\n  ));\n}\n\n// Analytical rotating 3-band (L=0,1,2) Spherical Harmonics environment radiance\nvec3 evalSHEnv(vec3 d, float rotAng, float order) {\n  vec3 dir = d;\n  dir.xz = rot2(rotAng) * dir.xz;\n\n  // Band 0 (DC ambient)\n  vec3 L00 = vec3(0.42, 0.45, 0.54);\n  vec3 irr = L00 * 0.8862;\n\n  if (order >= 0.5) {\n    // Band 1 (directional warm sun-sky dipole + cool cyan fill)\n    vec3 L1m1 = vec3(0.24, 0.30, 0.46); // y\n    vec3 L10  = vec3(0.45, 0.36, 0.24); // z\n    vec3 L1p1 = vec3(0.88, 0.48, 0.18); // x\n    irr += 1.0233 * (L1m1 * dir.y + L10 * dir.z + L1p1 * dir.x);\n  }\n\n  if (order >= 1.5) {\n    // Band 2 (quadrupole crisp golden key lobe + indigo-magenta rim)\n    vec3 L2m2 = vec3(0.32, 0.16, 0.28);\n    vec3 L2m1 = vec3(0.28, 0.34, 0.48);\n    vec3 L20  = vec3(0.38, 0.24, 0.14);\n    vec3 L2p1 = vec3(0.68, 0.42, 0.16);\n    vec3 L2p2 = vec3(0.46, 0.26, 0.34);\n    irr += 0.4954 * (\n      L2m2 * (dir.x * dir.y) +\n      L2m1 * (dir.y * dir.z) +\n      L20  * (3.0 * dir.z * dir.z - 1.0) * 0.33 +\n      L2p1 * (dir.x * dir.z) +\n      L2p2 * (dir.x * dir.x - dir.y * dir.y) * 0.5\n    );\n  }\n  return max(irr, vec3(0.02));\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n\n  float rotAng = iTime * 0.75 * max(P_ENV_ROTATION, 0.0);\n  float shOrder = clamp(P_SH_ORDER, 0.0, 2.0);\n  float ssWeight = clamp(P_SELF_SHADOW, 0.0, 1.5);\n  float bounceW = clamp(P_BOUNCE_GAIN, 0.0, 1.6);\n\n  vec3 ro = vec3(0.0, 0.08, 2.55);\n  vec3 rd = normalize(vec3(uv, -1.55));\n\n  // Background shows the rotated low-frequency SH environment directly\n  vec3 col = evalSHEnv(rd, rotAng, shOrder) * 0.55;\n\n  float t = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    float d = mapSculpt(ro + rd * t);\n    if (d < 0.002) { hit = true; break; }\n    t += d;\n    if (t > 8.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n\n    // Estimate precomputed hemispherical visibility + bent normal (PRT transfer vector T_i)\n    vec3 bentDir = n * 0.35;\n    float visSum = 0.0;\n    vec3 tangent = normalize(abs(n.y) < 0.9 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));\n    vec3 bitan = cross(n, tangent);\n\n    for (int k = 0; k < 6; k++) {\n      float fk = float(k);\n      float phi = fk * 1.0472 + 0.4;\n      vec3 sDir = normalize(n * 0.62 + (cos(phi) * tangent + sin(phi) * bitan) * 0.78);\n      float d1 = mapSculpt(p + sDir * 0.14);\n      float d2 = mapSculpt(p + sDir * 0.34);\n      float vSample = clamp(min(d1 / 0.14, d2 / 0.34), 0.0, 1.0);\n      visSum += vSample;\n      bentDir += sDir * vSample;\n    }\n    float visibility = mix(1.0, clamp(visSum / 6.0, 0.05, 1.0), ssWeight);\n    vec3 bentN = normalize(mix(n, normalize(bentDir + 1e-4), 0.65 * ssWeight));\n\n    // Diffuse PRT transfer dot product: irradiance along visibility-weighted bent normal\n    vec3 directSH = evalSHEnv(bentN, rotAng, shOrder) * visibility;\n\n    // Second-bounce interreflection inside cavities (warm terracotta-ochre bounce)\n    vec3 albedo = mix(vec3(0.84, 0.78, 0.72), vec3(0.86, 0.52, 0.34), smoothstep(0.75, 0.42, length(p)));\n    vec3 bounceSH = evalSHEnv(-n, rotAng, shOrder) * (1.0 - visibility) * albedo * albedo * bounceW * 1.35;\n\n    // Subtle specular SH sheen\n    vec3 rDir = reflect(rd, n);\n    float fres = 0.04 + 0.96 * pow(1.0 - max(dot(n, -rd), 0.0), 5.0);\n    vec3 specSH = evalSHEnv(rDir, rotAng, shOrder) * fres * visibility * 0.55;\n\n    col = albedo * directSH + bounceSH + specSH;\n  }\n\n  // Bottom-right SH light-probe inset sphere showing the active SH basis radiance\n  vec2 probeC = vec2(0.35, -0.34);\n  vec2 pd = uv - probeC;\n  float pr = 0.11;\n  float r2 = dot(pd, pd);\n  if (r2 < pr * pr) {\n    vec3 pn = normalize(vec3(pd, sqrt(max(pr * pr - r2, 0.0))));\n    col = evalSHEnv(pn, rotAng, shOrder);\n  } else if (abs(length(pd) - pr) < 0.004) {\n    col = vec3(0.92, 0.94, 0.98);\n  }\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "precomputed-radiance-transfer",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:50:13.852Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6371,
      "std": 0.2494,
      "unique_colors": 473
     },
     "image": "/specimens/precomputed-radiance-transfer-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "spherical-harmonics-lighting",
  "wavelet-all-frequency-relighting",
  "irradiance-volumes",
  "lightmap-baking"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "spherical-harmonics-lighting",
   "why": "The environment is projected to SH each frame and dotted with per-vertex transfer coefficients."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/gi/precomputed-radiance-transfer.json"
 },
 "solves": [
  "rigid object must relight under changing sky",
  "want soft self-shadowed diffuse lighting cheaply",
  "time-of-day lighting on a static model",
  "need baked self-shadowing that responds to environment"
 ],
 "authority": "Sloan et al., 2002",
 "url": "https://texelatlas.vercel.app/t/precomputed-radiance-transfer/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 38.47,
  "tier": "heavy",
  "p50_ms": 1.2655,
  "p95_ms": 1.3318,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "precomputed-radiance-transfer-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 33.05,
   "tier": "heavy",
   "p50_ms": 0.5255,
   "p95_ms": 0.5313,
   "speedup_x": 2.41,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 24.31,
   "tier": "heavy",
   "p50_ms": 0.7001,
   "p95_ms": 0.7029,
   "speedup_x": 1.81,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}