{
 "id": "exponential-height-fog",
 "title": "Exponential Height Fog",
 "aliases": [
  "analytic height fog",
  "altitude fog"
 ],
 "domain": "volumes",
 "subdomain": "fog",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unreal",
  "unity",
  "godot"
 ],
 "year_introduced": 2002,
 "inputs": [
  "depth",
  "material-params"
 ],
 "outputs": [
  "radiance",
  "ldr-image"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Fog whose density falls off exponentially with altitude, integrated in closed form along the view ray so a fragment shader gets exact extinction and in-scatter with no ray marching.",
 "how_it_works": "Density is a function rho(y) = a * exp(-b * y). For a straight segment from the camera to a surface point, the optical depth is the integral of rho along the segment. With exponential density along y this has a closed form: the integral becomes a * (exp(-b y0) - exp(-b y1)) / (b * dir.y) scaled by distance, with a limiting case when the ray is horizontal that must be handled to avoid dividing by zero. Transmittance is exp of minus optical depth; the fog colour, optionally tinted toward the sun with a directional lobe, is blended in by one minus transmittance. This is a single per-pixel expression that depends on camera height, fragment depth and view direction, and is applied in a post pass or in each material.",
 "when_to_use": "Choose it for ground fog, valley haze and general depth cueing in mobile, web and stylised games where cost must be negligible and there is no per-light interaction.\n\nPrefer `froxel-volumetric-fog` when fog must be lit and shadowed by dynamic lights, and prefer `hillaire-sky-atmosphere` for physically based aerial perspective. Use `volumetric-light-scattering-god-rays` for sun shafts on top of an analytic fog.",
 "cost": {
  "class": "cheap",
  "notes": "A handful of ALU operations and one exponential per pixel."
 },
 "failure_modes": [
  "Division by zero or NaN for rays near horizontal if the limit case is not handled",
  "Fog does not interact with light sources or shadows, so there are no light shafts",
  "Sky is shaded by the same fog and looks flat unless the fog is faded out with view angle",
  "Sudden colour jump at transparent surfaces when fog is applied in a post pass after they were drawn",
  "Fog colour banding in 8-bit targets at low density"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://iquilezles.org/articles/fog",
   "type": "web",
   "title": "Better fog",
   "authors": [
    "Inigo Quilez"
   ],
   "year": null,
   "venue": "iquilezles.org",
   "url": "https://iquilezles.org/articles/fog",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261109162525/https://iquilezles.org/articles/fog/",
     "timestamp": "20261109162525"
    },
    "page_title": "Inigo Quilez :: computer graphics, maths, shaders, fractals, demoscene",
    "host": "iquilezles.org",
    "title_confirmed_by_page": false,
    "title_unconfirmed": true
   },
   "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://iquilezles.org/articles/fog → 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://iquilezles.org/articles/fog → 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": 0,
   "__bib": "quilezbetter"
  },
  {
   "role": "tutorial",
   "key": "url:https://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine",
   "type": "tutorial",
   "title": "Exponential Height Fog in Unreal Engine",
   "authors": [
    "Epic Games"
   ],
   "year": null,
   "venue": "dev.epicgames.com",
   "url": "https://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261029194447/https://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine",
     "timestamp": "20261029194447"
    },
    "page_title": "Exponential Height Fog in Unreal Engine  | Unreal Engine 5.9 Documentation | Epic Developer Community",
    "host": "dev.epicgames.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine → 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://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine → 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": 0.95,
   "__bib": "gamesexponential"
  }
 ],
 "presets": [
  {
   "id": "exponential-height-fog-specimen",
   "title": "Analytic exponential height fog: no fog (left) vs fog (right)",
   "runtime": "glsl-fragment",
   "params": {
    "FOG_DENSITY": 0.06,
    "FOG_FALLOFF": 0.35
   },
   "code": "// Exponential height fog: density(y) = D0 * exp(-FALLOFF * y), integrated analytically along each ray.\n// Left half: no fog.  Right half: fog.\nconst float FOG_DENSITY = 0.06;\nconst float FOG_FALLOFF = 0.35;\n\nvec3 sky(vec3 rd, vec3 sd) {\n  vec3 c = mix(vec3(0.75, 0.82, 0.9), vec3(0.2, 0.4, 0.8), pow(clamp(rd.y, 0.0, 1.0), 0.5));\n  return c + vec3(1.0, 0.8, 0.5) * pow(max(dot(rd, sd), 0.0), 64.0) * 2.0;\n}\nbool sph(vec3 ro, vec3 rd, vec3 c, float r, out float t) {\n  vec3 oc = ro - c; float b = dot(oc, rd); float h = b * b - dot(oc, oc) + r * r;\n  if (h < 0.0) return false;\n  t = -b - sqrt(h); return t > 0.0;\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 sd = normalize(vec3(-0.5, 0.12, -0.8));\n  vec3 ro = vec3(0.0, 1.3, 2.0);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.08, -1.1));\n  float t = 1e4; vec3 col = sky(rd, sd);\n  if (rd.y < -1e-3) {\n    t = -ro.y / rd.y; vec3 p = ro + rd * t;\n    float chk = mod(floor(p.x * 0.5) + floor(p.z * 0.5), 2.0);\n    col = mix(vec3(0.22, 0.3, 0.18), vec3(0.5, 0.55, 0.4), chk);\n  }\n  for (int i = 0; i < 5; i++) {\n    float k = float(i);\n    vec3 c = vec3(sin(k * 2.3) * 3.5, 1.0, -6.0 - k * 7.0);\n    float ts;\n    if (sph(ro, rd, c, 1.0, ts) && ts < t) {\n      t = ts; vec3 n = normalize(ro + rd * ts - c);\n      col = vec3(0.8, 0.35, 0.25) * (0.25 + 0.8 * max(dot(n, sd + vec3(0.0, 0.5, 0.0)), 0.0));\n    }\n  }\n  if (fragCoord.x > 0.5 * iResolution.x) {\n    float tf = min(t, 300.0);\n    float k = FOG_FALLOFF * rd.y;\n    float integ = abs(k) < 1e-4 ? tf : (1.0 - exp(-k * tf)) / k;\n    float tau = FOG_DENSITY * exp(-FOG_FALLOFF * ro.y) * integ;\n    vec3 fc = mix(vec3(0.6, 0.7, 0.8), vec3(1.0, 0.8, 0.55), pow(max(dot(rd, sd), 0.0), 6.0));\n    col = mix(fc, col, exp(-tau));\n  }\n  if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "exponential-height-fog",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7312,
      "std": 0.1389,
      "unique_colors": 130
     },
     "image": "/specimens/exponential-height-fog-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "froxel-volumetric-fog",
  "hillaire-sky-atmosphere",
  "volumetric-light-scattering-god-rays"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "hosek-wilkie-sky",
   "why": "Horizon sky colour is sampled as the fog colour to hide the far plane."
  }
 ],
 "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/exponential-height-fog.json"
 },
 "solves": [
  "need cheap ground fog that thickens near the floor",
  "valley haze that fades with altitude",
  "depth cueing for mobile or web with minimal cost",
  "fog without raymarching in a fragment shader",
  "mist that pools low in a stylised game"
 ],
 "authority": "Quilez",
 "url": "https://texelatlas.vercel.app/t/exponential-height-fog/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 2.36,
  "tier": "light",
  "p50_ms": 0.0776,
  "p95_ms": 0.0803,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "exponential-height-fog-specimen",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 2.16,
   "tier": "light",
   "p50_ms": 0.0344,
   "p95_ms": 0.0345,
   "speedup_x": 2.26,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.51,
   "tier": "feather",
   "p50_ms": 0.0436,
   "p95_ms": 0.0438,
   "speedup_x": 1.78,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}