{
 "id": "continuous-wavelength-spectral-dispersion",
 "title": "Continuous-Wavelength Hero and Single-Wavelength Spectral Dispersion",
 "aliases": [
  "hero wavelength spectral sampling",
  "HWSS",
  "continuous-wavelength dispersion",
  "spectral dispersion path tracing"
 ],
 "domain": "materials",
 "subdomain": "spectral & dispersive materials",
 "stage": "material",
 "realtime": "interactive",
 "platforms": [
  "webgpu",
  "webgl2",
  "desktop-gpu",
  "cuda",
  "cpu"
 ],
 "year_introduced": 2014,
 "inputs": [
  "material-params",
  "radiance"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Samples continuous visible wavelengths along refractive paths—either as a multi-wavelength hero bundle or a single wavelength when dispersion splits rays—so glass, prisms, and gemstones render smooth rainbow caustics without discrete RGB banding.",
 "how_it_works": "Dispersive dielectrics such as crystal glass and diamonds refract short blue wavelengths more strongly than long red wavelengths, governed by a wavelength-dependent index of refraction `n(λ)` (commonly parameterized via Cauchy or Sellmeier equations and an Abbe number). Splitting rays into only three fixed R, G, and B channels produces stark three-color stair-stepping instead of a smooth spectrum.\n\n**Hero Wavelength Spectral Sampling** (Wilkie et al. 2014) transports a stratified tuple of `N` continuous wavelengths (often 4) together along every non-dispersive path segment, using one randomly selected **hero wavelength** `λ_h` to drive directional BSDF sampling and weighting all `N` companion wavelengths via balance-heuristic multiple importance sampling. Whenever a path encounters a dispersive specular interface where Snell's law depends on `λ`, companion wavelengths cannot share the refracted direction, so their throughput collapses to zero and the path continues purely at the hero wavelength `λ_h`.\n\nLightweight RGB path tracers adopt a **single-wavelength dispersion** variant on demand: camera paths carry RGB until they hit a dispersive material, at which point a continuous wavelength `λ ∈ [400, 700]` nm is importance-sampled from a CIE color-matching inverse CDF table, refracted using `n(λ)`, and weighted back into linear sRGB so white light integrates neutrally on average.",
 "when_to_use": "Choose it in physically based path tracers whenever glass, prisms, crystal chandeliers, camera lenses, or gemstones must exhibit smooth rainbow dispersion and spectral caustics without discrete R/G/B fringes.\n\nPrefer [chromatic-aberration](chromatic-aberration) post-processing when you only want cheap screen-space lens fringing in a real-time rasterizer. Prefer [thin-film-iridescence](thin-film-iridescence) for wave-interference soap bubbles and oil slicks where phase shift rather than bulk refraction drives color separation. Pair with [spectral-upsampling-sigmoid](spectral-upsampling-sigmoid) when running a full spectral renderer on RGB textures.",
 "cost": {
  "class": "medium",
  "notes": "Hero-wavelength bundles add SIMD-friendly per-bounce spectral arithmetic; on-demand single-wavelength dispersion incurs near-zero overhead on non-dispersive paths but introduces chromatic Monte Carlo noise that needs extra samples or denoising."
 },
 "failure_modes": [
  "Single-wavelength collapse after dispersive refraction introduces high-frequency rainbow color noise that converges more slowly than luminance noise",
  "RGB-embedded continuous-wavelength dispersion clamps out-of-gamut spectral XYZ values into sRGB, sacrificing strict colorimetric accuracy for saturated rainbows",
  "Smooth spectral caustics still suffer high variance under unidirectional path tracing unless combined with caustic photon mapping, light tracing, or manifold sampling",
  "Incorrect Abbe number parameterization or negative Cauchy terms can produce unphysical refractive indices outside the visible band"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1111/cgf.12419",
   "type": "paper",
   "title": "Hero Wavelength Spectral Sampling",
   "authors": [
    "A. Wilkie",
    "S. Nawaz",
    "M. Droske",
    "A. Weidlich",
    "J. Hanika"
   ],
   "year": 2014,
   "venue": "Computer Graphics Forum",
   "url": "https://doi.org/10.1111/cgf.12419",
   "ids": {
    "doi": "10.1111/cgf.12419"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.12419",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.12419",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.12419",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.12419",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.12419",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": 1,
   "__bib": "wilkie2014hero"
  },
  {
   "role": "implementation",
   "key": "gh:pissang/mutracer",
   "type": "code",
   "title": "pissang/mutracer",
   "description": "WebGPU physically based path tracer",
   "authors": [
    "pissang"
   ],
   "year": 2026,
   "venue": "GitHub",
   "url": "https://github.com/pissang/mutracer",
   "ids": {
    "repo": "pissang/mutracer"
   },
   "license": "MIT",
   "extra": {
    "stars": 204,
    "stars_checked": "2026-11-30",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-30T01:28:58Z",
    "language": "TypeScript",
    "homepage": "https://mutracer.meimu-studio.com/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pissang/mutracer",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pissang/mutracer",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pissang/mutracer",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pissang/mutracer",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pissang/mutracer",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/pissang/mutracer",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": null,
   "__bib": "pissang2026pissang"
  }
 ],
 "presets": [
  {
   "id": "continuous-wavelength-spectral-dispersion-live",
   "title": "Continuous-Wavelength Spectral Dispersion — 3-band RGB dispersion (left) vs continuous hero-wavelength Cauchy spectrum (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_DISPERSION": 0.14,
    "P_IOR_BASE": 1.62,
    "P_ROT_SPEED": 0.55,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_DISPERSION = 0.14; // P Cauchy Dispersion [0.02, 0.28, 0.01]\nconst float P_IOR_BASE = 1.62; // P Base Glass IOR [1.35, 2.15, 0.02]\nconst float P_ROT_SPEED = 0.55; // P Prism Spin [0.0, 2.2, 0.05]\nconst float P_SPLIT = 0.48; // P RGB / Spectral Split [0.0, 1.0, 0.02]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\n// Smooth CIE-inspired spectral wavelength-to-linear-RGB response for lambda in [0, 1] (400nm -> 700nm)\nvec3 spectralRGB(float t) {\n  vec3 c = clamp(vec3(\n    1.5 - abs(t - 0.78) * 3.6 + 0.35 * exp(-pow((t - 0.12) * 5.0, 2.0)),\n    1.45 - abs(t - 0.48) * 3.4,\n    1.5 - abs(t - 0.18) * 3.6\n  ), 0.0, 1.0);\n  return c * c;\n}\n\n// Faceted octagonal crystal gem / optical prism SDF\nfloat mapCrystal(vec3 p, float spin) {\n  vec3 q = p;\n  q.xz = rot2(spin * 0.52) * q.xz;\n  q.yz = rot2(0.32) * q.yz;\n  vec3 aq = abs(q);\n  float d1 = max(aq.x + aq.z * 0.414, aq.z + aq.x * 0.414) - 0.58;\n  float d2 = (aq.x + aq.y * 0.85 + aq.z) * 0.68 - 0.66;\n  float d3 = aq.y - 0.72;\n  return max(max(d1, d2), d3) * 0.88;\n}\n\nvec3 calcNormal(vec3 p, float spin) {\n  vec2 e = vec2(0.002, 0.0);\n  return normalize(vec3(\n    mapCrystal(p + e.xyy, spin) - mapCrystal(p - e.xyy, spin),\n    mapCrystal(p + e.yxy, spin) - mapCrystal(p - e.yxy, spin),\n    mapCrystal(p + e.yyx, spin) - mapCrystal(p - e.yyx, spin)\n  ));\n}\n\n// High-contrast studio lightbox environment so chromatic dispersion fringes read crisply\nvec3 studioEnv(vec3 d) {\n  vec3 bg = mix(vec3(0.02, 0.03, 0.05), vec3(0.10, 0.14, 0.22), smoothstep(-0.4, 0.6, d.y));\n  float strip1 = smoothstep(0.08, 0.02, abs(d.x - 0.38)) * smoothstep(-0.3, 0.5, d.y);\n  float strip2 = smoothstep(0.10, 0.02, abs(d.x + 0.45)) * smoothstep(-0.2, 0.6, d.y);\n  float keyOrb = pow(max(dot(d, normalize(vec3(0.55, 0.72, -0.45))), 0.0), 42.0);\n  float horizonBand = exp(-abs(d.y + 0.08) * 16.0) * (0.4 + 0.6 * step(0.0, sin(atan(d.z, d.x) * 6.0)));\n  return bg + vec3(2.8, 2.75, 2.65) * (strip1 + strip2 * 0.8 + keyOrb * 1.8) + vec3(0.9, 0.95, 1.0) * horizonBand * 0.85;\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  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isContinuous = screenX >= split;\n  float disp = clamp(P_DISPERSION, 0.01, 0.32);\n  float iorBase = clamp(P_IOR_BASE, 1.2, 2.3);\n  float spin = iTime * max(P_ROT_SPEED, 0.0);\n\n  vec3 ro = vec3(0.0, 0.10, 2.35);\n  vec3 rd = normalize(vec3(uv, -1.55));\n\n  vec3 col = mix(vec3(0.018, 0.022, 0.036), vec3(0.052, 0.062, 0.095), smoothstep(-0.55, 0.55, uv.y));\n  // Soft caustic spectral fan cast behind the prism onto backdrop\n  float causticAngle = atan(uv.y + 0.12, uv.x + 0.02);\n  float causticBeam = exp(-abs(uv.y + 0.24 - uv.x * 0.18) * 14.0) * smoothstep(0.18, 0.65, abs(uv.x));\n  if (isContinuous) {\n    float wl = clamp(0.5 + (uv.y + 0.24 - uv.x * 0.18) * 3.8, 0.0, 1.0);\n    col += spectralRGB(wl) * causticBeam * 0.38;\n  } else {\n    float dY = uv.y + 0.24 - uv.x * 0.18;\n    vec3 rgbBand = vec3(exp(-pow((dY - 0.04) * 34.0, 2.0)), exp(-pow(dY * 34.0, 2.0)), exp(-pow((dY + 0.04) * 34.0, 2.0)));\n    col += rgbBand * causticBeam * 0.42;\n  }\n\n  float t = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 56; i++) {\n    float d = mapCrystal(ro + rd * t, spin);\n    if (d < 0.002) { hit = true; break; }\n    t += d;\n    if (t > 5.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p, spin);\n    vec3 reflD = reflect(rd, n);\n    float ndv = max(dot(n, -rd), 0.0);\n    float f0 = pow((iorBase - 1.0) / (iorBase + 1.0), 2.0);\n    float fres = f0 + (1.0 - f0) * pow(1.0 - ndv, 5.0);\n\n    vec3 transCol = vec3(0.0);\n    if (!isContinuous) {\n      // Left: Discrete 3-channel RGB refraction (produces distinct red/green/blue chromatic split!)\n      for (int c = 0; c < 3; c++) {\n        float fc = float(c);\n        float ior = iorBase + (fc - 1.0) * disp * 1.15;\n        vec3 rIn = refract(rd, n, 1.0 / ior);\n        // Approximate second exit refraction through opposite crystal wall\n        vec3 pExit = p + rIn * 0.72;\n        vec3 nExit = -calcNormal(pExit, spin);\n        vec3 rOut = refract(rIn, nExit, ior);\n        if (length(rOut) < 0.01) rOut = reflect(rIn, nExit);\n        vec3 s = studioEnv(normalize(rOut));\n        if (c == 0) transCol.r = s.r;\n        else if (c == 1) transCol.g = s.g;\n        else transCol.b = s.b;\n      }\n    } else {\n      // Right: Continuous 12-wavelength hero spectral quadrature using Cauchy n(lambda) = A + B/lambda^2\n      vec3 normW = vec3(0.0);\n      for (int k = 0; k < 12; k++) {\n        float wl = (float(k) + 0.5) / 12.0; // 0 = 400nm violet, 1 = 700nm red\n        float lam = mix(0.40, 0.70, wl);\n        float cauchy = (1.0 / (lam * lam) - 1.0 / (0.55 * 0.55)) * 0.24;\n        float ior = iorBase + cauchy * disp * 1.45;\n        vec3 rIn = refract(rd, n, 1.0 / max(ior, 1.05));\n        vec3 pExit = p + rIn * 0.72;\n        vec3 nExit = -calcNormal(pExit, spin);\n        vec3 rOut = refract(rIn, nExit, max(ior, 1.05));\n        if (length(rOut) < 0.01) rOut = reflect(rIn, nExit);\n        vec3 wRGB = spectralRGB(wl);\n        float envLum = dot(studioEnv(normalize(rOut)), vec3(0.28, 0.54, 0.18));\n        transCol += wRGB * envLum;\n        normW += wRGB;\n      }\n      transCol /= max(normW, vec3(1e-4));\n    }\n\n    vec3 reflCol = studioEnv(reflD);\n    col = mix(transCol * 1.25, reflCol, clamp(fres * 1.1, 0.08, 0.92));\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "continuous-wavelength-spectral-dispersion",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:47.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4244,
      "std": 0.211,
      "min": 0.1371,
      "max": 0.9521
     },
     "image": "/specimens/continuous-wavelength-spectral-dispersion-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "spectral-upsampling-sigmoid",
  "thin-film-iridescence",
  "openpbr-surface",
  "path-tracing",
  "multiple-importance-sampling",
  "chromatic-aberration"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "spectral-upsampling-sigmoid",
   "why": "Converts RGB albedo textures into smooth continuous reflectance spectra evaluated at each hero and companion wavelength."
  },
  {
   "id": "openpbr-surface",
   "why": "Drives wavelength-dependent dielectric refraction directly from OpenPBR's transmission dispersion scale and Abbe number parameters."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-30T17:59:51.239Z",
  "draft": "data/drafts/materials/continuous-wavelength-spectral-dispersion.json"
 },
 "solves": [
  "rgb rendering misses rainbow prism dispersion through glass and diamonds",
  "three-channel caustics show ugly red green blue banding instead of spectra",
  "need physically accurate glass chromatic dispersion in a path tracer",
  "sample continuous visible wavelengths with hero wavelength weighting",
  "convert spectral radiance cleanly to linear rgb without color bias"
 ],
 "authority": "Wilkie et al., 2014",
 "url": "https://texelatlas.vercel.app/t/continuous-wavelength-spectral-dispersion/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 24.91,
  "tier": "heavy",
  "p50_ms": 0.8197,
  "p95_ms": 0.8307,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "continuous-wavelength-spectral-dispersion-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 17.69,
   "tier": "moderate",
   "p50_ms": 0.2813,
   "p95_ms": 0.3013,
   "speedup_x": 2.91,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 15.76,
   "tier": "moderate",
   "p50_ms": 0.454,
   "p95_ms": 0.4655,
   "speedup_x": 1.81,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}