---
id: "exponential-height-fog"
title: "Exponential Height Fog"
aliases: [analytic height fog, altitude fog]
domain: "volumes"
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"
cost: "cheap"
authority: "Quilez"
url: "https://texelatlas.vercel.app/t/exponential-height-fog/"
sources_verified_at: "2026-11-29"
---
# Exponential Height Fog (Quilez)

> 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.

## Reach for it when

- 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

## 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 it

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.

Prefer [Froxel Volumetric Fog](https://texelatlas.vercel.app/t/froxel-volumetric-fog.md) when fog must be lit and shadowed by dynamic lights, and prefer [Scalable Production Sky and Atmosphere (Hillaire)](https://texelatlas.vercel.app/t/hillaire-sky-atmosphere.md) for physically based aerial perspective. Use [Screen-space Volumetric Light Scattering (God Rays)](https://texelatlas.vercel.app/t/volumetric-light-scattering-god-rays.md) for sun shafts on top of an analytic fog.

## Cost

cheap — A handful of ALU operations and one exponential per pixel.
Measured GPU Weight: 2.36× baseline (light) — 0.0776 ms median / 0.0803 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 2.16× baseline (light) — 0.0344 ms median (2.26× faster on L4).
Ampere A100 scaling: 1.51× baseline (feather) — 0.0436 ms median (1.78× faster on A100).

## 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

## Engine support

- godot: builtin — `Environment.fog_enabled = true; Environment.fog_height / fog_height_density` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Environment.xml, checked 2026-12-01)
- threejs: builtin — `import { exponentialHeightFogFactor } from 'three/tsl'; scene.fogNode = ...` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/nodes/fog/Fog.js, checked 2026-12-01) — TSL / WebGPURenderer node.
- unity: builtin — `Volume > Add Override > Fog > Enable; Fog Attenuation Distance / Base Height / Maximum Height` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Documentation~/fog-volume-override-reference.md, checked 2026-12-01) — HDRP only; height-based exponential fog.
- unreal: builtin — `Place Actors > Visual Effects > Exponential Height Fog` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: depth, material-params
- Outputs: radiance, ldr-image
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unreal, unity, godot

## Presets

### Analytic exponential height fog: no fog (left) vs fog (right) (glsl-fragment; rendered 2026-11-29)

```json
{
  "FOG_DENSITY": 0.06,
  "FOG_FALLOFF": 0.35
}
```

```glsl
// Exponential height fog: density(y) = D0 * exp(-FALLOFF * y), integrated analytically along each ray.
// Left half: no fog.  Right half: fog.
const float FOG_DENSITY = 0.06;
const float FOG_FALLOFF = 0.35;

vec3 sky(vec3 rd, vec3 sd) {
  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));
  return c + vec3(1.0, 0.8, 0.5) * pow(max(dot(rd, sd), 0.0), 64.0) * 2.0;
}
bool sph(vec3 ro, vec3 rd, vec3 c, float r, out float t) {
  vec3 oc = ro - c; float b = dot(oc, rd); float h = b * b - dot(oc, oc) + r * r;
  if (h < 0.0) return false;
  t = -b - sqrt(h); return t > 0.0;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  vec3 sd = normalize(vec3(-0.5, 0.12, -0.8));
  vec3 ro = vec3(0.0, 1.3, 2.0);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.08, -1.1));
  float t = 1e4; vec3 col = sky(rd, sd);
  if (rd.y < -1e-3) {
    t = -ro.y / rd.y; vec3 p = ro + rd * t;
    float chk = mod(floor(p.x * 0.5) + floor(p.z * 0.5), 2.0);
    col = mix(vec3(0.22, 0.3, 0.18), vec3(0.5, 0.55, 0.4), chk);
  }
  for (int i = 0; i < 5; i++) {
    float k = float(i);
    vec3 c = vec3(sin(k * 2.3) * 3.5, 1.0, -6.0 - k * 7.0);
    float ts;
    if (sph(ro, rd, c, 1.0, ts) && ts < t) {
      t = ts; vec3 n = normalize(ro + rd * ts - c);
      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));
    }
  }
  if (fragCoord.x > 0.5 * iResolution.x) {
    float tf = min(t, 300.0);
    float k = FOG_FALLOFF * rd.y;
    float integ = abs(k) < 1e-4 ? tf : (1.0 - exp(-k * tf)) / k;
    float tau = FOG_DENSITY * exp(-FOG_FALLOFF * ro.y) * integ;
    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));
    col = mix(fc, col, exp(-tau));
  }
  if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);
  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}

```

Attribution: written for this index

## Combines with

- [Hosek-Wilkie Sky Model](https://texelatlas.vercel.app/t/hosek-wilkie-sky.md): Horizon sky colour is sampled as the fog colour to hide the far plane.

## Sources

1. [primary] Inigo Quilez Better fog. iquilezles.org. https://iquilezles.org/articles/fog (verified via http on 2026-11-29)
2. [tutorial] Epic Games Exponential Height Fog in Unreal Engine. dev.epicgames.com. https://dev.epicgames.com/documentation/en-us/unreal-engine/exponential-height-fog-in-unreal-engine (verified via http on 2026-11-29)

## Cite this entry

Texel. "Exponential Height Fog." https://texelatlas.vercel.app/t/exponential-height-fog/ (accessed 2026-12-01).
