{
 "id": "precomputed-atmospheric-scattering",
 "title": "Precomputed Atmospheric Scattering",
 "aliases": [
  "Bruneton sky"
 ],
 "domain": "volumes",
 "subdomain": "atmosphere",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu"
 ],
 "year_introduced": 2008,
 "inputs": [
  "material-params"
 ],
 "outputs": [
  "radiance",
  "hdr-image"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Tabulates single and multiple Rayleigh/Mie scattering of a planetary atmosphere into 3D textures, so sky color and aerial perspective cost a few texture fetches per pixel from any altitude.",
 "how_it_works": "The atmosphere is a spherically symmetric medium with density profiles for air molecules, aerosols and ozone. Because the geometry is symmetric, in-scattered light depends only on four things: altitude, view zenith angle, sun zenith angle and the view-sun azimuth. A precompute pass fills transmittance (2D), single-scattering (a 4D function packed into a 3D texture) and then iterates over scattering orders, feeding each order's result into the next as a source term. A separate irradiance table gives ground ambient light. At run time the sky is one 4D lookup with manual interpolation across the packed axes, and aerial perspective is the difference of two lookups at the camera and at the surface point. Mie scattering is stored separately and recombined with its phase function to save memory.",
 "when_to_use": "Choose it when you need a physically plausible planet-scale atmosphere with real multiple scattering, a sun that can sit anywhere from noon to below the horizon, and a camera that can fly from the ground to orbit, and you can afford a precompute step on parameter changes.\n\nPrefer `hillaire-sky-atmosphere` when parameters (density, albedo, sun) must change every frame without a recompute, or when you want one unified path with volumetric fog. Prefer `preetham-sky` or `hosek-wilkie-sky` for a ground-only sky with a handful of turbidity sliders and no precompute. Prefer `rayleigh-mie-single-scattering` for a cheap ray-marched gradient.",
 "cost": {
  "class": "cheap",
  "notes": "Per-pixel cost is a handful of 3D texture fetches; the precompute is a one-off cost that is noticeable (tens to hundreds of ms on a desktop GPU) if parameters change."
 },
 "failure_modes": [
  "Seams or banding in the sky near the horizon where the packed 4D table is interpolated across slice boundaries",
  "Visible discontinuity at the terminator or when the sun is slightly below the horizon if the table parametrization is too coarse",
  "Changing atmosphere parameters at run time forces a full table rebuild, causing hitches",
  "Planet shadow on aerial perspective and clouds is not captured unless added separately",
  "Assumes a smooth sphere, so terrain shadows (crepuscular rays through mountains) are missing"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1111/j.1467-8659.2008.01245.x",
   "type": "paper",
   "title": "Precomputed Atmospheric Scattering",
   "authors": [
    "Eric Bruneton",
    "Fabrice Neyret"
   ],
   "year": 2008,
   "venue": "Computer Graphics Forum",
   "url": "https://doi.org/10.1111/j.1467-8659.2008.01245.x",
   "ids": {
    "doi": "10.1111/j.1467-8659.2008.01245.x"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2008.01245.x (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2008.01245.x (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2008.01245.x (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2008.01245.x (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.1111/j.1467-8659.2008.01245.x (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "bruneton2008precomputed"
  },
  {
   "role": "implementation",
   "key": "gh:ebruneton/precomputed_atmospheric_scattering",
   "type": "code",
   "title": "ebruneton/precomputed_atmospheric_scattering",
   "description": "This project provides a new implementation of our EGSR 2008 paper \"Precomputed Atmospheric Scattering\".",
   "authors": [
    "ebruneton"
   ],
   "year": 2017,
   "venue": "GitHub",
   "url": "https://github.com/ebruneton/precomputed_atmospheric_scattering",
   "ids": {
    "repo": "ebruneton/precomputed_atmospheric_scattering"
   },
   "license": "BSD-3-Clause",
   "extra": {
    "stars": 1088,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2025-10-05T18:39:46Z",
    "language": "C++",
    "homepage": "https://ebruneton.github.io/precomputed_atmospheric_scattering/",
    "license_name": "BSD 3-Clause \"New\" or \"Revised\" License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ebruneton/precomputed_atmospheric_scattering",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ebruneton/precomputed_atmospheric_scattering",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ebruneton/precomputed_atmospheric_scattering",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ebruneton/precomputed_atmospheric_scattering",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ebruneton/precomputed_atmospheric_scattering",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ebruneton/precomputed_atmospheric_scattering",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "ebruneton2017ebruneton"
  },
  {
   "role": "tutorial",
   "key": "url:https://ebruneton.github.io/precomputed_atmospheric_scattering",
   "type": "tutorial",
   "title": "Precomputed Atmospheric Scattering: a New Implementation",
   "authors": [
    "Eric Bruneton"
   ],
   "year": null,
   "venue": "ebruneton.github.io",
   "url": "https://ebruneton.github.io/precomputed_atmospheric_scattering",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260805003022/https://ebruneton.github.io/precomputed_atmospheric_scattering/",
     "timestamp": "20260805003022"
    },
    "page_title": null,
    "host": "ebruneton.github.io",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://ebruneton.github.io/precomputed_atmospheric_scattering → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://ebruneton.github.io/precomputed_atmospheric_scattering → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "brunetonprecomputed"
  },
  {
   "role": "implementation",
   "key": "gh:takram-design-engineering/three-geospatial",
   "type": "code",
   "title": "takram-design-engineering/three-geospatial",
   "description": "Geospatial Rendering in Three.js",
   "authors": [
    "takram-design-engineering"
   ],
   "year": 2024,
   "venue": "GitHub",
   "url": "https://github.com/takram-design-engineering/three-geospatial",
   "ids": {
    "repo": "takram-design-engineering/three-geospatial"
   },
   "license": "MIT",
   "extra": {
    "stars": 1798,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-05-27T06:40:25Z",
    "language": "TypeScript",
    "homepage": "https://takram-design-engineering.github.io/three-geospatial",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/takram-design-engineering/three-geospatial",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/takram-design-engineering/three-geospatial",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/takram-design-engineering/three-geospatial",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/takram-design-engineering/three-geospatial",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/takram-design-engineering/three-geospatial",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/takram-design-engineering/three-geospatial",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "takramdesignengineering2024takram"
  }
 ],
 "presets": [
  {
   "id": "precomputed-atmospheric-scattering-live",
   "title": "Precomputed Atmospheric Scattering — single-scatter limb (left) vs multi-scatter Rayleigh/Mie orbital twilight (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_SUN_ELEV": 0.1,
    "P_ALTITUDE": 0.42,
    "P_MIE_HAZE": 0.85,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_SUN_ELEV = 0.10; // P Sun Limb Angle [-0.15, 0.45, 0.02]\nconst float P_ALTITUDE = 0.42; // P Orbital Altitude [0.15, 0.95, 0.05]\nconst float P_MIE_HAZE = 0.85; // P Mie Aerosol [0.2, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P Single / Multi Split [0.0, 1.0, 0.02]\n\nvec2 raySphere(vec3 ro, vec3 rd, float R) {\n  float b = dot(ro, rd);\n  float c = dot(ro, ro) - R * R;\n  float h = b * b - c;\n  if (h < 0.0) return vec2(-1.0);\n  h = sqrt(h);\n  return vec2(-b - h, -b + h);\n}\n\n// Physical Rayleigh + Mie atmospheric optical depth integration (Bruneton 2008 planetary geometry)\nvec3 integrateAtmosphere(vec3 ro, vec3 rd, vec3 sunDir, float mieScale, bool includeMulti) {\n  float Rg = 6.36;\n  float Rt = 6.48;\n  float HR = 0.018;\n  float HM = 0.0045;\n  vec3 betaR = vec3(5.8, 13.5, 33.1) * 0.92;\n  vec3 betaM = vec3(21.0) * 0.42 * mieScale;\n\n  vec2 hitAtm = raySphere(ro, rd, Rt);\n  if (hitAtm.y < 0.0) return vec3(0.0);\n  vec2 hitGnd = raySphere(ro, rd, Rg);\n  bool hitsPlanet = (hitGnd.x > 0.0);\n\n  float t0 = max(hitAtm.x, 0.0);\n  float t1 = hitsPlanet ? hitGnd.x : hitAtm.y;\n\n  const int STEPS = 18;\n  float dt = (t1 - t0) / float(STEPS);\n  float optR = 0.0;\n  float optM = 0.0;\n  vec3 sumR = vec3(0.0);\n  vec3 sumM = vec3(0.0);\n  vec3 sumMulti = vec3(0.0);\n\n  float mu = dot(rd, sunDir);\n  float phaseR = 0.059683 * (1.0 + mu * mu);\n  float g = 0.78;\n  float phaseM = 0.079577 * ((1.0 - g * g) / pow(max(1.0 + g * g - 2.0 * g * mu, 0.02), 1.5));\n\n  for (int i = 0; i < STEPS; i++) {\n    vec3 p = ro + rd * (t0 + (float(i) + 0.5) * dt);\n    float h = max(length(p) - Rg, 0.0);\n    float dR = exp(-h / HR) * dt;\n    float dM = exp(-h / HM) * dt;\n    optR += dR;\n    optM += dM;\n\n    // Light transmittance from sample point p to space along sunDir (4-step Chapman/optical depth)\n    vec2 sunAtm = raySphere(p, sunDir, Rt);\n    vec2 sunGnd = raySphere(p, sunDir, Rg);\n    float sunVis = (sunGnd.x > 0.0 && sunGnd.x < sunAtm.y) ? 0.0 : 1.0;\n\n    float sOptR = 0.0;\n    float sOptM = 0.0;\n    if (sunVis > 0.5) {\n      float sDt = sunAtm.y * 0.25;\n      for (int j = 0; j < 4; j++) {\n        vec3 sp = p + sunDir * ((float(j) + 0.5) * sDt);\n        float sh = max(length(sp) - Rg, 0.0);\n        sOptR += exp(-sh / HR) * sDt;\n        sOptM += exp(-sh / HM) * sDt;\n      }\n      vec3 tau = betaR * (optR + sOptR) + betaM * 1.15 * (optM + sOptM);\n      vec3 atten = exp(-tau);\n      sumR += atten * dR;\n      sumM += atten * dM;\n    }\n\n    if (includeMulti) {\n      // Precomputed multi-scattering isotropic approximation (2nd+ orders fill deep twilight & luminous horizon limb!)\n      vec3 up = normalize(p);\n      float sunCosZ = dot(up, sunDir);\n      float twilight = smoothstep(-0.34, 0.35, sunCosZ);\n      vec3 viewAtten = exp(-(betaR * optR + betaM * optM) * 0.62);\n      vec3 warmMulti = mix(vec3(0.45, 0.16, 0.38), vec3(0.98, 0.52, 0.24), smoothstep(-0.22, 0.12, sunCosZ));\n      vec3 dayMulti = vec3(0.32, 0.56, 0.96);\n      vec3 msCol = mix(warmMulti, dayMulti, smoothstep(0.05, 0.42, sunCosZ));\n      sumMulti += viewAtten * msCol * (dR * 12.0 + dM * 4.0) * twilight * 0.42;\n    }\n  }\n\n  vec3 sky = (sumR * betaR * phaseR + sumM * betaM * phaseM) * 18.0 + sumMulti;\n\n  // Planet surface & ocean specular + aerial perspective transmittance\n  if (hitsPlanet) {\n    vec3 gp = ro + rd * hitGnd.x;\n    vec3 gn = normalize(gp);\n    vec3 viewTrans = exp(-(betaR * optR + betaM * optM));\n    float ndl = max(dot(gn, sunDir), 0.0);\n    // Subtle continental silhouettes & clouds on planetary limb\n    float landMask = smoothstep(0.05, 0.32, sin(gn.x * 14.0 + gn.z * 9.0) * cos(gn.y * 12.0 - gn.x * 6.0));\n    vec3 surfAlb = mix(vec3(0.04, 0.11, 0.24), vec3(0.18, 0.24, 0.14), landMask);\n    float oceanSpec = (1.0 - landMask) * pow(max(dot(reflect(-sunDir, gn), -rd), 0.0), 42.0) * 1.4;\n    vec3 surfLit = (surfAlb * (ndl * 1.2 + (includeMulti ? 0.06 : 0.0)) + vec3(1.0, 0.84, 0.62) * oceanSpec * ndl);\n    sky += surfLit * viewTrans;\n  } else {\n    // Crisp solar disc + subtle starfield in deep space\n    float sunDisc = smoothstep(0.9985, 0.9996, mu);\n    vec3 viewTrans = exp(-(betaR * optR + betaM * optM));\n    sky += vec3(12.0, 10.5, 8.2) * sunDisc * viewTrans;\n  }\n\n  return sky;\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 sx = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool useMulti = sx >= split;\n\n  float sunElev = clamp(P_SUN_ELEV, -0.22, 0.55) + 0.05 * sin(iTime * 0.4);\n  float alt = clamp(P_ALTITUDE, 0.1, 1.0);\n  float mie = clamp(P_MIE_HAZE, 0.1, 2.5);\n\n  // Orbital view skimming the curved planetary horizon\n  float camR = 6.36 + mix(0.14, 0.72, alt);\n  vec3 ro = vec3(0.0, camR, 0.0);\n  vec3 ta = vec3(0.0, 6.26, -2.25);\n  vec3 fw = normalize(ta - ro);\n  vec3 ri = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));\n  vec3 up = cross(ri, fw);\n  vec3 rd = normalize(fw * 1.55 + ri * uv.x + up * uv.y);\n\n  vec3 sunDir = normalize(vec3(0.28 * cos(iTime * 0.25), sunElev, -0.94));\n  vec3 col = integrateAtmosphere(ro, rd, sunDir, mie, useMulti);\n\n  float sep = smoothstep(0.0035, 0.0008, abs(sx - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\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": "precomputed-atmospheric-scattering",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:22.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.3229,
      "std": 0.419,
      "min": 0,
      "max": 0.9546
     },
     "image": "/specimens/precomputed-atmospheric-scattering-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "hillaire-sky-atmosphere",
  "rayleigh-mie-single-scattering",
  "henyey-greenstein-phase-function",
  "preetham-sky"
 ],
 "extends": [
  "rayleigh-mie-single-scattering"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "nubis-volumetric-clouds",
   "why": "Provides sky radiance and sun transmittance that tint and light the cloud layer."
  },
  {
   "id": "froxel-volumetric-fog",
   "why": "Aerial perspective table supplies the far-field haze that the froxel grid hands over to."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/volumes/precomputed-atmospheric-scattering.json"
 },
 "solves": [
  "realistic sky and distant haze from space to ground",
  "multiple scattering makes the sunset look right",
  "atmosphere ray marching per pixel is too slow",
  "need accurate planet atmosphere rendering via lookup"
 ],
 "authority": "Bruneton & Neyret, 2008",
 "url": "https://texelatlas.vercel.app/t/precomputed-atmospheric-scattering/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 19.08,
  "tier": "moderate",
  "p50_ms": 0.6278,
  "p95_ms": 0.65,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "precomputed-atmospheric-scattering-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 18.56,
   "tier": "moderate",
   "p50_ms": 0.2951,
   "p95_ms": 0.2982,
   "speedup_x": 2.13,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 13.55,
   "tier": "moderate",
   "p50_ms": 0.3901,
   "p95_ms": 0.3913,
   "speedup_x": 1.61,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}