Exponential Height Fog
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.
Also known as analytic height fog, altitude fog
In the family Atmosphere, water & volumes, fog
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | import { exponentialHeightFogFactor } from 'three/tsl'; scene.fogNode = ... docs TSL / WebGPURenderer node. |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | Built in | Environment.fog_enabled = true; Environment.fog_height / fog_height_density docs |
| Unity | Built in | Volume > Add Override > Fog > Enable; Fog Attenuation Distance / Base Height / Maximum Height docs HDRP only; height-based exponential fog. |
| Unreal 5.7 | Built in | Place Actors > Visual Effects > Exponential Height Fog docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
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 when fog must be lit and shadowed by dynamic lights, and prefer Scalable Production Sky and Atmosphere (Hillaire) for physically based aerial perspective. Use Screen-space Volumetric Light Scattering (God Rays) for sun shafts on top of an analytic fog.
Field marks
- 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
Presets
Analytic exponential height fog: no fog (left) vs fog (right)
{
"FOG_DENSITY": 0.06,
"FOG_FALLOFF": 0.35
}Show GLSL (46 lines)
// 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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| exponential-height-fog-specimen | Tesla T4 1920x1080 | 2.36× baseline (light) · 0.078 ms / 0.080 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| exponential-height-fog-specimen | NVIDIA L4 1920x1080 | 2.16× baseline (light) · 0.034 ms / 0.035 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| exponential-height-fog-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 1.51× baseline (feather) · 0.044 ms / 0.044 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Hosek-Wilkie Sky Model: Horizon sky colour is sampled as the fog colour to hide the far plane.
Sources
- tutorialEpic Games. Exponential Height Fog in Unreal Engine. dev.epicgames.com.Verified via live page · 2026-11-29