Feature Library

Lit height fog

8.50 GPU · 0.20 CPU ms
A still of the Lit height fog demo
Still
The live demo starts when it’s in view.Drag to orbit · wheel or + − to zoom · Fly low into the valley

Fog that fills the low ground and glows round the lights in it, in one full-screen pass over any scene with a depth buffer (WebGPU, or WebGL2 where it is missing).

What it costs a frame

8.50 ms
0.20 ms
GPU
8.50 ms
CPU, median
0.20 ms
CPU, 95th pct
0.28 ms
Draw calls
0
Weight
Heavy

Measured 11 November 2026 on 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept. What ran: Measured at night on the slow orbit: 40 lights moving along the valleys and six beacons splatted into a 256² light field, a 256 × 256 ground and the sky, the fog pass (six beacons glowing in the air, the wisp layer at 8 steps), the beams and lights after it and a tone pass, all timed together with timestamp queries. A living scene, so it draws every frame; with Moving lights and Slow orbit off (and under reduced motion) it draws only when something changes. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
unknown GPU · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool8.500.200.28
apple · Apple A19 Proin a browser tab · 16 November 2026not timed0.580.70
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 20264.980.350.48

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
WebGPU or WebGLWebGPU where there is one, WebGL2 where there is not.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages

What it’s for

  1. Valleys, harbours and cities at night
  2. Beacons, street lamps and headlights glowing in mist
  3. Maps and 3D overviews that fade with distance
  4. Game worlds and flight views
  5. Dusk and dawn moods over any scene
  6. Depth cues for terrain

Pitfalls, in brief

  1. The pass reads the scene’s colour and writes another texture: a render pass cannot sample the texture it draws into.
  2. Depth is WebGPU’s 0..1 with 1 far by default.
  3. Pixels at the far plane count as sky at skyDistance and get only skyFog of the fog: leave the far plane empty (your sky drawn there), or the fog will think your far geometry is sky.
  4. Draw glowing things (beams, sprites, emissive lamps) after the fog and multiply them by fogTransmittance to their point: drawn before, the fog washes them out as if they were lit surfaces.
  5. The airlight is a closed form for even air and no shadows: a light’s glow is weighted by the fog’s density at the light (never less than haze), so a lamp just above a dense layer glows less than you might expect.
5 more in brief
  1. At most 16 point lights glow in the air (they live in the uniform, and each costs every pixel two arctangents).
  2. The uniform is written with queue.writeBuffer, so draw() once per submit: two draws in one submit both see the second one’s settings.
  3. The low layer is a short march with per-pixel jitter that changes every frame: its steps crowd near the eye, its wisps fade out where a step is longer than a wisp, and it reads the light field from a blurrier mip there, but a thick layer still shows fine grain without temporal smoothing.
  4. On WebGL2 (createHeightFogGL) depth is GL’s: a DEPTH_COMPONENT texture read as 0..1 and turned into NDC z = 2d − 1 before the inverse view-projection, so give it the inverse of a GL projection (NDC z from −1 to 1) and NEAREST filtering.
  5. Splat small lights with a radius of at least two or three of the field’s texels (the rect’s width over its size): smaller pools alias as the lights move.
10 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Inigo Quilez, “Better fog”: The published closed form for exponential height fog along a ray; the code here is the owner’s derivation, re-written.

Miles Macklin, “Faster Fog” (2010): The closed-form in-scattering from a point light in even air (the arctangent form, without extinction), which pointAirlight is.

Sun, Ramamoorthi, Narasimhan and Nayar, “A Practical Analytic Single Scattering Model for Real Time Rendering” (2005): The full model with extinction that the airlight simplifies: not used, but where to go for more.

Henyey and Greenstein, phase function (1941): The sun’s forward glow in the fog: the published formula.

Jarzynski and Olano, “Hash Functions for GPU Rendering” (JCGT 2020): The PCG hash behind the wisps’ noise, the march’s jitter and the demo’s stars and terrain.

fogheight fogatmospherelight scatteringairlightpost-processingraw webgpuwgslglslwebgl2 fallbackanalyticnight scenes

Near it in the frame