Taos Explorer Technology Launch Taos ExplorerLaunch ↗

Technology / Rendering / 05

Rendering deep dive · 05

Clouds as a volume wrapped around the planet

Towering cumulus with flat gray bases and sunlit tops over a valley, seen from a runway, with a darker cloud mass overhead.
Showers over Medford. The “Showers” weather seen from the runway at KMFR: a cumulus layer with a 5 km minimum top, sunlit lobes, gray flat bases and the haze of distance between the cells. Every cloud here is a ray-marched density field; there are no cloud meshes or sprites.
1 in 16pixels ray-marched per frame by default (4×4 interleave; 2×2 on Ultra)
128³ + 64³baked shape noise (r8unorm) and erosion noise (rg8unorm), mipmapped
256×256×40rgba16float cloud volume (distance + density) baked around the camera
2 × 512²rgba16float Beer Shadow Map cascades, rebuilt every 4th frame
8 octavesof energy-conserving multiple scattering on the sun term
4 layersof typed clouds at most, each in its own height band

Clouds in Taos Explorer have to work from a runway, from inside the deck, from the top of it at cruise, and from far enough up that the deck is a texture on a globe. They have to sit at a true altitude over terrain that is streamed from real elevation data, take their cover from the weather (sometimes a live airport report), cast shadows on the ground and on themselves, redden at sunset, glow when lightning fires inside them, and cost a few milliseconds of a browser's GPU budget. The answer is one engine pass, HQCloudPass, that ray-marches a density field in a spherical shell at the real planet radius; a baked distance-field volume so the march can jump through clear air; a sun-aligned Beer Shadow Map for long-range shadow; and an interleaved, temporally reprojected march that touches one pixel in sixteen per frame.

Overview

The pass in a frame

explorer/main.ts · src/renderer/features/hq_cloud_feature.ts · src/renderer/render_graph/passes/hq_cloud_pass.ts · src/shaders/clouds_hq.wgsl · src/shaders/cloud_reproject.wgsl · src/shaders/cloud_composite.wgsl

HQCloudFeature is registered after the deferred lighting, the water, the stars, the night lights and the engine's god-ray feature, and before screen-space reflections, bloom, precipitation, antialiasing and the tone map (see Anatomy of a frame for the whole order). It reads the lit HDR target and the scene depth and writes a new HDR target with the clouds composited in. Five render passes and two compute bakes make up the work:

#StageReads → writesNotes
Outside the graph (submitted from updateSettings)
aHQCloudVolumeBakelayer uniforms, noise → 256×256×40 rgba16float (back buffer)compute, 4 slices a frame while a new volume is due; typed layers only
bHQCloudLightBakecloud volume → 128×128×40 rgba16floatcompute, 8 slices a frame; sun optical depth + sky visibility
In the render graph
0HQCloudPass.bsmdensity → 1024×512 rgba16float (persistent)skipped on the frames the map is reused; added early when the ground LUT needs it
0′HQCloudPass.groundLutBSM → 1024² r8unormbefore deferred lighting; the ground's cloud shadow
1HQCloudPass.raymarchdepth, BSM, LUTs → ⌈W/4⌉×⌈H/4⌉ rgba16float scatter + r32float cloud distanceone pixel of each 4×4 block
2HQCloudPass.reprojectfresh samples, history, depth → W×H rgba16floatwrites the other of two history slots
3HQCloudPass.godraydepth, BSM → W/2×H/2 r16floatmean sun transmittance along the view ray
4HQCloudPass.compositescene HDR, resolved clouds, god-ray factor → new HDRmanual premultiplied “over” with perceptual transmittance
volume bake 256²×40 · compute light bake 128²×40 · compute bsm 2 cascades · 1/4 fr groundLut → deferred sun raymarch 1 px of 16 godray half res · ×factor reproject full res history ×2 ping-pong composite over scene HDR
The stages of one frame. The two compute bakes run only while a new volume or a new light volume is being made; the Beer Shadow Map is rendered on one frame in four (and whenever the sun, the camera or the cloud settings jump) and otherwise reused, pinned to the world.

How Explorer creates it

The pass has four compile-time options, each a WGSL override constant so the unused branch folds out of the pipeline. Explorer turns all four on, and on phones and tablets halves the shadow map's resolution and rebuilds it half as often:

explorer/main.tsTypeScript
const cloudFeature = new HQCloudFeature({
  noises: hqNoises,              // createBakedCloudNoiseTextures(device)
  settings: hqSettings,
  useAtmosphere: true,           // sky ambient + aerial perspective from the atmosphere model
  useTransmittanceLut: true,     // sun color through the air column (AtmosphereLutsFeature)
  accuratePhase: true,           // approximate-Mie phase instead of dual-lobe HG
  beerShadowMap: true,           // sun-view optical-depth map + god rays + ground LUT
  ...(defaultTileMemoryMB().mobile ? { bsmSize: 256, bsmInterval: 8 } : {}),
});

The two cloud styles share this pass. Layered (the default on desktop) describes the sky as up to four typed layers and marches a baked cloud volume; classic (the default on phones and tablets, where the layered style's baked volumes would cost about 50 MB of GPU memory) is a single deck whose density is evaluated procedurally at every sample (as are the thin “sheet” layers, when present). Because a combined shader reserves registers for the larger of the two marches, the host compiles one pipeline per march through the MARCH_MODE override: the procedural one at start-up, the volume one asynchronously the first time typed layers are drawn.

Geometry

A shell at planet scale

src/shaders/clouds_hq.wgsl (altitude_of, altitude_crossings, band_range) · src/renderer/render_graph/passes/hq_cloud_pass.ts (updateCamera, updateSettings) · explorer/main.ts (cloud frame setup)

The cloud layer is a spherical shell around a planet center that is a uniform. The engine default puts that center at (0, −R, 0) so that world Y reads as altitude; Explorer instead hands it the real center of the globe in its floating-origin world frame and the real ground radius under the camera (WGS84 at start-up), so the deck is the same curved layer the atmosphere and terrain sit on. The shader's geometry is exact at planet scale rather than shrinking the planet to protect f32 precision: a stylized radius of about 638 km would over-curve the shell, so that a 1.2 km deck reaches a horizon of only √(2·R·h) ≈ 39 km instead of about 124 km, and the clouds would shrink to a patch that gets worse with altitude.

Altitude without cancellation

The naive altitude, length(p − center) − R, subtracts two numbers near 6.4 × 10⁶ m and quantizes the result to about half a meter in f32, enough for the deck to wobble as the camera moves. The shader instead writes altitude as the height above the tangent plane plus the second-order drop of the sphere below it, and solves ray crossings of that same paraboloid with a quadratic whose coefficients are all O(1):

src/shaders/clouds_hq.wgslWGSL
fn altitude_of(p_world: vec3<f32>) -> f32 {
  let dx = p_world.x - cloud.planetCenter.x;
  let dz = p_world.z - cloud.planetCenter.z;
  return (p_world.y - surface_y()) + (dx * dx + dz * dz) / (2.0 * cloud.earthRadius);
}

// Where the PARABOLIC altitude crosses target_alt along the ray: every coefficient is
// O(1), so t stays millimeter-precise at ANY world position (the sphere form put
// ±1 m of per-pixel t noise on cloud edges once the camera sat at world XZ ~1e5).
fn altitude_crossings(ro: vec3<f32>, rd: vec3<f32>, target_alt: f32) -> vec2<f32> {
  let hx = ro.x - cloud.planetCenter.x;
  let hz = ro.z - cloud.planetCenter.z;
  let a = (rd.x * rd.x + rd.z * rd.z) / (2.0 * cloud.earthRadius);
  let b = rd.y + (hx * rd.x + hz * rd.z) / cloud.earthRadius;
  let c = altitude_of(ro) - target_alt;
  …
  var q = -0.5 * (b + sq);              // stable (citardauq) quadratic
  if (b < 0.0) { q = -0.5 * (b - sq); }
  return vec2<f32>(min(q / a, c / q), max(q / a, c / q));
}

The same paraboloid is used for the density evaluation, so the march range and the cloud it samples agree exactly. Where a true sphere is still wanted (the sun ray to the top of the shell, the Beer Shadow Map's chords), intersect_sphere uses the ratio form r·(−cos χ ± √((Rs/r)² − sin²χ)), which never builds R².

band_range classifies the camera as below, inside or above a band of altitudes and returns the entry and exit distances. Below the deck the ray starts where it rises through the base; inside it starts at the camera; above it, the usual case at cruise, it enters through the top and leaves through the base, or through the top again on a grazing ray that misses the base sphere. Global (“skybox”) clouds are drawn only on sky pixels; Explorer uses localClouds: true, which clamps every ray to the scene depth so terrain and buildings cut the clouds and the camera can fly into them.

ground (real radius under the camera) base top below inside above grazing: top → top
March ranges for a camera below, inside and above the shell (thick segments). With typed layers the march goes further: each layer's own band is intersected separately, the spans are sorted and merged, and the clear air between layers is never stepped through.

Camera-relative everything

Explorer's world coordinates are hundreds of kilometers from the origin between re-anchors of its floating origin (see Anatomy of a frame). The pass therefore folds the camera translation into its matrices in f64 on the CPU: the inverse view-projection it uploads maps NDC to camera-relative positions, the camera position uniform is identically zero, and the planet center arrives relative to the camera. With absolute matrices, f32 rounding of the translation terms would put a per-pixel lattice on the rays, visible as static stair-terracing on cloud edges, and mis-register the reprojection by a sub-pixel amount each frame.

The noise is handled the same way. Texture coordinates are built from camera-relative horizontal positions, and the world anchoring plus the wind scroll are restored by per-layer phases computed in f64 and wrapped with fract() (the textures tile with period 1, so the field is bit-identical). The procedural weather noise does not tile, so its phase stays unwrapped; it grows by one per weather patch flown over, small enough for f32 on any flight. Explorer also keeps its own running noiseAnchor, advanced each frame by the camera's horizontal travel. Without it, every re-derivation of the floating origin's axes (about every hundred kilometers, and on every airport jump) would swap the whole sky for a different part of the field.

The two pieces of state the pass carries from frame to frame also survive a jump of the origin. The reprojection projects into last frame's image with the camera's previous view-projection, into which the camera folds the pending shift (see Motion vectors and reprojection), so the history lines up across the jump. The Beer Shadow Map's key holds the planet center's world position to the meter, and a jump moves it, so the map is rebuilt that frame rather than read at an offset.

Anchoring the deck to the ground

Cloud base and top are heights above the ground, but which ground? Using the terrain under the camera would make the deck bob up and down as the camera crosses ridges, around Machu Picchu for instance. The layer level is instead a regional mean elevation from the ground map, eased with a ten-second time constant, taken at once on the first reading or after a jump of more than 5 km. The shell radius is then the ground radius plus that level.

From above the deck to orbit

The march length is bounded (a few hundred steps), so from far above the deck it can no longer reach the horizon; the deck would cull into a shrinking disk, and grazing columns would read as an opaque blanket. Explorer fades the density with the camera's height over the highest layer:

Altitude fade
falt = 1 − clamp((hcam − (htop + 3 km)) / 37 km, 0, 1)
  • htopthe highest layer top (or a main layer's minimum top) of the weather's sky
  • faltmultiplies every layer's density; the feature is disabled below 0.01

So the full sea of clouds is there to about 3 km above the tops and gone by about 40 km. From there to orbit, Earth's clouds come from its imagery instead: the day imagery has today's cloud cover painted into it from a global infrared satellite composite (EUMETSAT data via Live Cloud Maps), covered in Space, stars and other worlds. The volumetric deck only exists on Earth; the Moon and Mars get none.

Shape

Noise, weather and coverage

src/assets/cloud_noise_baked.ts · src/assets/cloud_noise_gen.ts · src/assets/cloud_noise_worker.ts · src/shaders/clouds_hq.wgsl (eval_cloud, weather_fbm) · src/renderer/features/hq_cloud_presets.ts

The baked noise volumes

All cloud shape comes from two tileable 3D textures, created by createBakedCloudNoiseTextures:

TextureSize · formatChannelsSource
Shape (base_noise)128³ · r8unorm · 8 mipsR: low-frequency Perlin–Worleyflipbook PNG (128×16384), red channel
Erosion (detail_noise)64³ · rg8unorm · 7 mipsR: Perlin (wispy) · G: inverted-F1 Worley fBm (billowy)32³ baked Perlin flipbook, refined; Worley generated

The PNG names say “RGBA” and “RGB”, but the data is grayscale, so only one channel is uploaded. Mips are box-filtered on the CPU because the march reads far clouds from coarser levels. The erosion volume is 64³ with two channels: at the baked Perlin's own 32³, one texel would be 30–100 m of cloud, and a cloud flown beside would look blocky. The red channel is the 32³ Perlin resampled with a second octave of itself at twice the frequency folded in (weight 0.35). The green channel is an inverted-F1 Worley fBm with four octaves at 4/8/16/32 cells per tile, weighted 0.56/0.25/0.12/0.07: eroding where it is low (between cells) leaves rounded cauliflower lobes, where eroding the Perlin leaves torn wisps. Generating the Worley volume takes most of a second, so a module worker builds it; until it returns, the texture holds a quick resample of the 32³ data, and the full volume is written over it in place.

Pitfall

The engine also has a runtime noise generator, createCloudNoiseTextures, tuned for the cheaper flat-slab cloud pass. Fed to this pass it produces a density field far too weak for the remap below: the sky shows a few thin wisps near the horizon and looks almost clear. The HQ pass must get the baked volumes.

The classic deck

The single-deck model follows the published “cloudscape” recipe closely. The shape noise is read at a world-scale frequency (position / 100,000 × shapeScale, about a 20 km period at the default scale 5), with an anti-repetition shear that leaks horizontal position into the vertical texture axis (alt + x/3 + z/7) and an altitude-distortion lean downwind with height. A per-preset vertical density curve gives flat bases and rounded tops, and the noise is remapped against the local coverage so that lowering coverage shrinks clouds from their edges inward rather than thinning them:

Coverage remap (eval_cloud)
n′ = mix(1, n, s) ,   b = 1 − D(h)·c·(1 − s) ,   ρ0 = sat((n′ − b)/(1 − b)) · c²
  • nshape noise sample (R of the 128³ volume)
  • sshape factor, mix(0.1, 1, shapeFactor) × the erosion curve
  • D(h)the preset's density curve at normalized height h in the deck
  • ccoverage after the weather modulation and coverage spots

Erosion then remaps ρ0 once more against the erosion noise (blended from the wispy Perlin at the base to the billowy Worley above 15% of the deck by billow), an optional second “micro” erosion fetch does the same at a finer scale, and an edge-sharpening power ρ1/(1+2·sharp) lifts the fringe toward the interior so a cloud reads solid. The sharpening fades out with the shape mip: a hard edge sampled sparsely at distance shimmers.

Weather noise and coverage spots

One global coverage makes every cloud the same. Three octaves of value noise at a much larger scale than the shape noise (lacunarity 2.17, chosen to avoid axis-aligned repetition) give a per-column weather value w, from which coverage and density are modulated. The modulation is mean-preserving, so the coverage slider stays the average over the sky:

Weather modulation
c = sat(c0 · (1 + vc(2wc − 1))) ,   kρ = max(0, 1 + vρ(2wρ − 1))
  • wc, wρtwo decorrelated weather-noise samples (or the R and G of an authored 2D weather texture when one is bound)
  • vc, vρcoverage and density variation; Explorer uses 0.7 and 0.5 with a weather scale of 2.2

The alternatives show why it is mean-preserving: a symmetric modulation that puts the slider at the midpoint never reaches overcast, and a “carve-down” one that makes the slider the ceiling drags the average down until there are hardly any clouds.

Coverage spots (CloudCoverageSpot, at most MAX_CLOUD_COVERAGE_SPOTS = 16) are Gaussian bells of raised coverage, c = max(c, cspot·exp(−d²/r²)), so a cloud is sure to form over a point even in a clear sky. Explorer uses them twice. In a thunderstorm the 16 nearest storm cells from the weather radar (level ≥ 2.5) become spots of full cover at 0.75 of the cell radius, taken from the aircraft's radar picture when flying. When soaring, thermals become spots, and with clouds otherwise off they form a cumulus deck of their own at the top of the convection, 1,500 m thick. On the typed layers the first layer's spots also shape storm towers: storm_cells widens a spot to 2.4× its radius in the anvil's height band, pushes it downwind, and raises a dome over the core where the updraft overshoots the anvil.

Presets and wind

The classic deck's vertical curves and scalars come from five presets in src/renderer/features/hq_cloud_presets.ts: Sparse, Cloudy, Overcast, Stormy and Cumulus. Each sets density, shape and erosion factors and scales, base and thickness, coverage and its variation, and the Cumulus one also billow, edgeSharpness and inScatter. The settings' default preset is Cloudy, whose deck runs from 1,200 to 3,200 m (base 1,200 m, 2,000 m thick), which is also where Explorer's manual cloud sliders start. With the weather system on, each weather type picks the preset whose curves it uses (cumulus for fair weather and showers, overcast decks for drizzle and fog, stormy towers for heavy rain and storms), and the weather sets the amounts and heights.

Wind is a running offset added to the noise phases: Explorer advances it at the cloud wind speed (6 m/s by default, from the settings slider) at a fixed 45° heading. The typed layers additionally lay their noise along a wind axis (stretched types such as stratus and cirrus streak along it), latched when first seen and re-latched only after a turn of 45°; following the wind exactly would rotate the whole sky about the noise origin with every few degrees of change, and every cloud would become a different one.

Weather

Cloud types and the weather's sky

src/renderer/render_graph/passes/hq_cloud_types.ts · src/shaders/clouds_hq.wgsl (layer_field, cover_threshold, profile_*) · explorer/lib/weather/cloud_sky.ts · explorer/lib/weather/weather.ts · explorer/lib/weather/metar.ts · explorer/lib/weather/open_meteo.ts

The layered style replaces the single deck with a stack of CloudTypeLayers, each one cloud type in its own height band with its own cover, density, patch size and weather seed. A type's look is written in meters, not texture units, and the pass turns those into noise frequencies:

TypeProfileCellErosionBillowEdgeStretchDensity ×Shadows
cumuluscumuliform10 km900 m11.513yes
stratocumulussheet14 km1,300 m0.8511.42yes
stratussheet30 km1,600 m0.10.221.2yes
altocumulussmall cells12 km1,600 m111.31.5no
altostratussheet30 km1,400 m0.20.22.50.6yes
nimbostratusthick25 km1,300 m0.60.61.21.5yes
cumulonimbustower26 km2,200 m11.212yes
cirrusfeathered11 km900 m004.50.05no

Each type also carries a shape factor, an erosion factor, optional fine detail (“micro”, 260–420 m for the cumuliform types), a top relief (lumps and rolls reaching down from the band's ceiling, up to 380 m for nimbostratus) and a base raggedness. Small high cloud (altocumulus, cirrus) casts no shadow on the ground, the air or other clouds: its shafts through the air read as noise in the sky. It still shades itself through its own short sun march.

Cover as a share of the sky

The classic remap does not suit the layers: under it a type with strong shape noise has almost no cloud at any coverage. The layers instead threshold the shape noise at a quantile. The baked shape volume's distribution is skewed high (the median is 0.753), and cover_threshold(f) is a piecewise-linear fit of the value above which a share f of it lies, applied through f1.6 so the weather system's coverage numbers, tuned by eye against the classic remap, keep their meaning (0.5 covers about a third of the sky). The signed distance above the threshold, divided by 0.2, is the layer's implicit field: positive inside cloud. Density inside is the layer's density times clamp(c², 0.45, 1); without the floor, a cloud in a sparse part of the sky would become a ghostly smooth dome with no lobes to see. Below a cover of 0.02 the threshold rises by up to 0.08 more, past the noise's highest values, so a layer with no cover of its own there has no cloud: at the floor of 0.97 alone the noise's highest peaks still made a stray cloud or two, dark lumps in the storm cells' tower layer (whose cover is its cells' alone) far from any storm, and in a band under the weather map's clear sky.

Six vertical profiles shape where in its band a type has cloud: cumuliform (sharp base, body narrowing into domes), sheet, thick, tower (a waist narrowing with height, full again where the anvil spreads, cut flat at 0.9 of the band except over a storm core), small cells, and feathered. Each also has an ambient-occlusion curve, dark at the base for the deep types.

The weather's sky

Explorer's weather system has thirteen types (clear, few, scattered, broken, showers, high clouds, overcast, light rain, rain, snow, storm, light fog, dense fog). Each is a target state (coverage, density, base, top, fog, rain, snow, rain shafts, temperature offset, lightning) that the controller eases toward, and in dynamic mode it drifts between neighboring types with weighted odds. WEATHER_SKY in cloud_sky.ts maps each type to a stack of layers; the main layer takes the weather's live eased values, the others are fixed bands:

WeatherMain layerOther layers
clear, fewcumuluscirrus 8–9 km, cover 0.2 / 0.3
scatteredcumulusaltocumulus 4.3–4.9 km (0.3) · cirrus 8–9.2 km (0.45)
brokenstratocumulusaltocumulus 4.3–4.9 km (0.25)
showerscumulus, top ≥ 5 kmcirrus 8.5–9.5 km (0.25)
high cloudsaltostratus (5.2–6.2 km)cirrus 8.5–9.6 km (0.55)
overcaststratocumuluscirrus 8.5–9.5 km (0.3)
light rain, snownimbostratus—
rainnimbostratuscumulonimbus 0.9–10 km (0.35)
stormcumulonimbus, top ≥ 11 km, cover × 0.4nimbostratus 0.7–2.6 km (0.6)
light fog / dense fogstratocumulus / stratus—

The overcast stack has no second sheet of altostratus at 4.2–5.4 km: one would keep an aircraft under cloud to nearly 18,000 ft, and without it there is a top to climb out on. CloudSky eases one stack into the next: a layer type both stacks have keeps its slot (and so its weather field and seed), new ones fade in, departing ones fade out, over fadeSeconds = 7. Covers ease with a minimum rate (an exponential ease alone never arrives, and the volume is rebaked for every hundredth of cover), the first sky appears at once rather than fading in, and at most the four most-wanted layers are passed on.

While the sky is changing, Explorer sets continuousVolume: the cloud volume is rebaked whole each frame from the unrounded values, so clouds grow and dissolve smoothly instead of stepping a few times a second. Otherwise the volume is rebaked only when a layer has moved by a step (a hundredth of cover, 25 m of height), a few slices per frame. Phones never use the continuous mode.

Live weather

With live weather, a METAR or an Open-Meteo forecast becomes a weather target directly. METAR cover codes map to coverage (FEW 0.25, SCT 0.5, BKN 0.78, OVC 1.05, vertical visibility 1.1), raised to 1.0 in precipitation, 1.2 in heavy precipitation and 1.35 with thunder; the base is the ceiling (the lowest broken or overcast layer) or the lowest layer; the deck depth is chosen from the coverage. Open-Meteo's low, mid and high cloud fractions combine as max(0.03, low, 0.9·mid, 0.45·high). Both set density to min(1, 0.3 + 0.45·coverage) and pick the nearest named type for the label (and, for the forecast, the cloud stack).

A station's report builds the stack itself. reportedLayers (metar.ts) gives each cloud group a typed layer with no main layer: the base is the report's, in meters above the ground like every band. The type comes from the height band, the cover, the CB/TCU marks read from the raw text, the present weather, and a dew-point check on cumulus bases. The top is a typical depth by type, kept under the next layer's base. blendedLayers pulls each layer toward the same type at stations within 100 km. deepenWithModel (open_meteo.ts) deepens cumulus by the model's CAPE and adds a middle and a high layer the report lacks. The layers carry fadeSeconds of 90, so CloudSky eases a new report in over a minute and a half instead of its usual 7 s. A first report, or one from a station over 100 km from the last, calls CloudSky.snap() and is there at once. Two layers of one type keep their slots by nearest base. Fractus scraps are cumulus with a style override (4 km cells, 450 m erosion, edge sharpness 0.6).

Each type turns coverage into cloud differently: a stratus deck is all or nothing, cumulus heap, and altostratus is a veil. So one coverage for each cover read as anything from nearly clear to more than reported. reportedCoverage maps the cover through a per-type row (REPORTED_COVERAGE), fitted to the fraction of the sky the field shows from the ground: blue-free pixels looking straight up, nine places 2.5 km apart. The targets are the middle of each cover's oktas: 0.19 FEW, 0.44 SCT, 0.75 BKN and all of the sky at OVC. A BKN stratocumulus deck takes 0.82, and a BKN altocumulus one 0.95.

A layer's weather noise varies its cover by up to ±coverageVariation, so a BKN deck (variation 0.6) could leave the station itself under scattered cloud. The uniform coverAnchor (camera-relative XZ, a radius and a bitmask of layers) holds the station's reported layers to their own cover near it. layer_cover_variation scales the variation by smoothstep(0.3, 1, d / radius), so it is none within 7.5 km (a 25 km radius) and full from 25 km. Explorer sets it from the nearest report and CloudSky.anchoredMask (the output slots holding reported layers). With no anchor the field is as before.

The weather map

One stack of layers is drawn everywhere, so on its own the sky 50 km off is the sky here. The weather map (HQCloudSettings.weatherMap, explorer/lib/weather/weather_map.ts) lays a texture on the ground: R, G and B the low, middle and high cloud's cover in the layers' own coverage units, A the precipitation, in rgba16float, 256 texels over 300 km, placed by its corner relative to the camera (the host keeps its middle as an ECEF point, so the floating origin moving does not slide it). A second r8 texture holds the low cloud's kind, 0 stratiform to 1 convective. Both are binding 10 and 11 of the noise group, visible to the compute stages too, because the volume bake (layer_field) reads them; the light volume is baked from that volume, and the shadows from both, so the line between overcast and clear holds in the cloud, its light and its shadow alike.

Each typed layer carries mapChannel, mapStrength, mapRef and mapOther. layer_base_cover gives the base cover before the patches vary it: with mapRef 0 the map's value replaces the layer's own; above 0, the layer's own is scaled by the map's value over mapRef (the map's at the camera), at most twice, for a second layer in a band. The share is mapStrength, faded out over the map's outer tenth and held off over the cover anchor, so a reporting station keeps its reported sky. layer_type_mix turns a low layer's density and AO profile toward mapOther's by how far the map's kind there is from its own. The march caches both per layer with the rest of a sample's weather, so the light march does not fetch them again. Where the map's A places the rain, rain_amount replaces the weather's one rain level under the clouds, the radar cells' shafts are kept only where the map has rain, and spotLayer sends the storm cells' spots to the tower layer. The single classic deck takes the low channel as its cover. With no map every layer is as before.

For pictures and films a painted map can take the baked one's place (?weathermap=<image>, or __planet.weatherMap.paint): an image scaled to 256 × 256, its R, G, B and A taken as the baked map's channels, its top row north, laid over 300 km (or another size) about a place. The image is read back through the GPU (copyExternalImageToTexture with premultipliedAlpha: false), since a 2D canvas premultiplies: a dry texel, A 0, would lose its cover. Its rain's peaks become the radar's cells (see the weather deep dive), so a painted storm stands where it is painted. It is drawn with any weather but a hand-set sky, and only on the player's own screen.

Acceleration

The baked cloud volume

src/shaders/clouds_hq.wgsl (cs_bake_volume, vol_sample_local, cs_bake_light, light_od, sun_transmittance_vol) · src/renderer/render_graph/passes/hq_cloud_pass.ts (_updateVolume, _updateLightVolume) · hq_cloud_types.ts (volumeBands)

Evaluating the typed layers procedurally at every sample means two 3-octave weather noises, a shape fetch and a threshold per layer per sample, and nothing tells the march how far it is to the next cloud. The layered style therefore bakes the layers' implicit field into a 3D texture around the camera once, and marches that. Each texel stores a pseudo signed distance to the cloud surface and the cloud's density there; the noise that makes the lobes is applied at march time, as a displacement of that surface, only close to it.

Layout

Horizontally the volume is a stereographic map centered near the camera: a point at distance q from the center maps to u = d·2/(1 + |d|²), d = q/Rvol, so a texel at the center is half the size of one at the rim. At the 80 km radius used among or under the clouds, a central texel is 625 m. Climbing above the tops widens the radius by 20 m per meter of height above the highest layer, up to 200 km, and the volume is rebaked only when the wanted radius is off by a quarter, so a climb rebakes it a few times rather than every frame. Vertically, the 40 slices are spent only on the layers' bands (padded by 4% or 40 m, merged where they overlap, at least 4 slices each, shared in proportion to thickness): volumeBands. The flat bases and tops are not in the texture; the march cuts them exactly.

camera top view · 256² texels 625 m texels at the center (80 km) ×2 at the rim density fades 0.72→0.98 r² cirrus band · 6 slices altocumulus · 5 cumulus · 29 (no slices between bands) (no slices between bands) side view · 40 slices (example split)
The volume's two mappings. The slice counts on the right are an illustration of volumeBands for a scattered-cumulus sky; the real split follows each band's thickness.

Distance from a field

The baked field is not a true distance; it is the noise value against its threshold. The bake turns it into one to first order by dividing by its gradient, estimated with three extra field evaluations a texel away horizontally and 80 m vertically:

src/shaders/clouds_hq.wgsl · cs_bake_volumeWGSL
let f0 = vol_field(…, lr.x, lr.y, alt);                    // (inside field, density)
let fx = vol_field(…, lr.x + eh, lr.y, alt).x;
let fz = vol_field(…, lr.x, lr.y + eh, alt).x;
let fy = vol_field(…, lr.x, lr.y, alt + ev).x;             // ev = 80 m, eh = one texel
let slope = length(vec3<f32>((fx - f0.x) / eh, (fz - f0.x) / eh, (fy - f0.x) / ev));
let dist = clamp(f0.x / max(slope, 1e-5), -range, range);   // range = VOL_RANGE = 2000 m
textureStore(volume_out, cell, vec4<f32>(dist / range, f0.y, 0.0, 1.0));

Placed clouds

src/shaders/clouds_hq.wgsl (stamp_field) · hq_cloud_pass.ts (CloudStamp, stampLayers) · explorer/lib/fire/pyrocumulus.ts

The host may place up to 8 clouds of its own (stamps; Explorer places a wildfire's pyrocumulus and the lenticulars over mountains). Each is a tower (a column narrower at its base, leaning downwind as it rises, with a dome over its top third) or a lens (a flat ellipsoid along a heading). stamp_field gives its distance analytically, a tower's cut back by the shape noise in its own frame for billows of about half its radius. A tower is not a solid either: its density is 0.12 of its core's at the surface, rises to full over the outer 45% of its radius, and is patchy with the same noise (0.3 to 1), so its rims and the clefts between billows let the light through while the outline stays. Explorer gives a pyrocumulus 0.12 of a layer's density and a lens 0.35. The noise only cuts in, so the distance never overstates how far the surface is. A stamp a few hundred meters across is smaller than a volume texel (625 m at the center), so the volume does not hold its shape: vol_sample_local evaluates it at each sample, and the erosion and the rest of the detail work on it as on any cloud. A lens is left smooth, as real lenticulars are: no erosion, relief or ragged base (its density comes back negative to say so). The bake writes only a bound on the stamps' distance into the volume's z channel: the distance at the texel's center plus two texels (the cubic read's reach) and the 150 m a stamp may drift before the next bake, never past 0. Where the bound says one may be within a step and 40 m, the sample evaluates the stamps; further, the march jumps by the bound. The stamps are packed camera-relative with the spots, and the volume is baked again each time one has drifted 100 m with the wind or changed size by 25 m. A stamp outside every layer's band gets a layer of its own (coverage −1: no cloud but the stamps) while there are fewer than four, so the volume holds its height.

Two textures alternate: the march reads the front one while slices of the back one are baked (4 per frame, or all 40 for the first volume so there are clouds at once). When the back one is complete the two swap. A new volume is started when the camera has wandered 4 km (scaled by the radius ratio) from its center, when the layers' rounded description changes, or when the radius needs to change. The textures and pipelines are created lazily; the classic style allocates none of them. Two volumes and two light volumes come to about 52 MB of rgba16float, which is why phones stay on classic.

Detail at march time

vol_sample_local reads the volume (through a cubic B-spline built from four bilinear fetches within about 40 m of footprint; plain trilinear filtering leaves a crease along every texel edge, and under a low sun the creases draw straight lines across a near cloud), then adds what the texture cannot hold:

Firm types (edge sharpness ≥ 1) become a solid body a little thinner just under the surface; soft types (sheets, cirrus) thicken over hundreds of meters (sat(sdf / 500)) so they are veils the sky shows through.

The light volume

A second baked texture, 128×128×40 on the same map and slices, holds what is expensive to march per sample: x the cloud's optical depth toward the sun (20 steps through the cloud volume, from 60 m growing by 1.25× per step to about 20 km), y the share of sky visible (three rays 60° up, a third of a turn apart, to above the highest layer), and z the mean optical depth along those rays. It is rebaked 8 slices per frame when the sun has moved a quarter of a degree, and whole, in the same frame, whenever a new cloud volume is swapped in; marching one frame with no light volume would flash bright over every cloud on each swap. The light bake samples the erosion texture, so that binding needs compute visibility; without the light volume every cloud would be lit by the 830 m local march alone.

Lighting

Lighting a cloud

src/shaders/clouds_hq.wgsl (fs_main, ms_transfer, cloud_phase, mie_phase, hq_powder, in_scatter_probability, flash_glow) · explorer/main.ts (ambientDimmer, nightAmbient, sunScale, lightOverride, cloudFlash)

Beer–Lambert, integrated per step

Along the view ray the march accumulates a transmittance and two kinds of in-scattered light, sun and ambient. Each step uses the energy-conserving analytic form (albedo 1), which weights a step's source term by the light it actually removes from the ray instead of by the step length:

Transmittance and per-step in-scatter
Tstep = e−σt Δs ,   L += T(1 − Tstep) · (Ssun + Samb) ,   T ← T · Tstep
  • σtextinction = density × extinction (0.05 per unit density by default)
  • Ssunsun transfer × powder × in-scatter probability (below)
  • Tthe march stops below 0.003 (procedural) or 0.01 (volume)

Phase: dual-lobe HG or approximate Mie

The default phase is a sum of two Henyey–Greenstein lobes, forward and backward, each with eccentricity g = anisotropy (0.7). With accuratePhase, which Explorer turns on, the phase is the Jendersie & d'Eon (2023) fit to Mie scattering by water droplets: a blend of an HG lobe and a Draine lobe whose four parameters are functions of the droplet diameter, here MIE_DROPLET_DIAMETER = 12 µm. It reproduces the sharp forward peak (the silver lining) and the faint backscatter glory that the two HG lobes only approximate.

Phase functions
pHG(θ, g) = (1 − g²) / (4π (1 + g² − 2g cos θ)3/2)
pMie(θ) = (1 − wD) pHG(θ, gHG) + wD pDraine(θ, gD, α)
  • gHGexp(−0.0990567 / (d − 1.67154)) ≈ 0.990 at 12 µm
  • gDexp(−2.20679 / (d + 3.91029) − 0.428934) ≈ 0.567
  • αexp(3.62489 − 8.29288 / (d + 5.52825)) ≈ 23.4
  • wDexp(−0.599085 / (d − 0.641583) − 0.665888) ≈ 0.487

The Mie phase is multiplied by 2 so that switching between it and the two-lobe sum (whose isotropic limit is 2/(4π)) does not change the overall exposure. Since the phase depends only on the view–sun angle and the octave, it is evaluated once per pixel (phase_setup) rather than per sample.

Multiple scattering as octaves

Single scattering with Beer–Lambert sun attenuation makes cloud interiors nearly black; real clouds are bright inside because light scatters many times. The pass uses the octave approximation: octave o scales the extinction, the scattering and the phase eccentricity by ao, where a = multiScatter (0.5), and the octaves are summed. Eight octaves rather than two make the largest single difference against reference renders, where fewer leave interiors dark and flat.

Sun transfer (ms_transfer)
Ssun(τ, θ) = Σo=07 ao e−ao τ po(θ)
po = pHG(θ, g ao) + pHG(θ, −g ao)   or   2 mix(1/4π, pMie, ao)
  • τoptical depth toward the sun (local march + light volume or Beer Shadow Map)
  • amultiScatter = 0.5; higher octaves are dimmer, travel farther and are more isotropic

With the Mie phase the sum folds exactly: 2·mix(iso, p, ao) = 2·iso + 2ao(p − iso), so the code accumulates two scalar series and needs pMie once per pixel:

src/shaders/clouds_hq.wgsl · ms_transferWGSL
fn ms_transfer(od: f32) -> f32 {
  var a = 1.0;
  if (ACCURATE_PHASE) {
    let iso = 1.0 / (4.0 * PI);
    var s1 = 0.0;
    var s2 = 0.0;
    for (var o = 0; o < MS_OCTAVES; o++) {
      let e = exp(-od * a) * a;
      s1 += e;
      s2 += e * a;
      a *= cloud.multiScatter;
    }
    return 2.0 * (iso * s1 + (g_phase_mie - iso) * s2);
  }
  …                                   // dual-lobe HG: Σ exp(-od a) g_phase_hg[o] a
}
Interactive · how octaves keep light alive in thick cloud
at τ = 5: –at τ = 20: –Beer alone at τ = 20: –
The isotropic part of the transfer, Σ ao e−aoτ, against τ (phase left out). The faint curve is a single octave, plain Beer–Lambert. Deep in a cloud (τ of tens) single scattering is effectively zero, while the higher octaves, which see a fraction of the extinction, still deliver light; that is the bright, soft interior.

Where τ comes from

For the volume march, sun_transmittance_vol takes six jittered steps toward the sun through the cloud volume (25 m growing by 1.7× to about 830 m in all, the first few with the lobes' detail so each lobe shades itself and its neighbors), then adds the light volume's optical depth for everything farther up-sun. For the procedural march, sun_transmittance takes five steps over the first 400 m (ending at 12.5, 37.5, 87.5, 187.5 and 400 m) and reads the Beer Shadow Map beyond (next section); without the map it marches five steps of up to 1 km to the shell top. Both return 0 when the sun is below the local horizon at that sample's radius, and both multiply by terrain_sun, a map of the height below which terrain shades the air, so a mountain's shadow falls across the deck at a low sun.

Edges: powder and in-scatter probability

Two empirical terms shape the look of edges. A “beer-powder” factor, mix(1, 1 − e−4ρ, …) at strength 0.25, darkens thin, sun-facing edges when the sun is behind the viewer. The in-scatter probability term, from the dark-edges observation in the cloudscape talks, darkens thin freshly eroded density near the surface (it has little cloud behind it to scatter from) more strongly toward the tops; that is what outlines the crevices between bright cauliflower bulges. Its weight rises when the sun is behind the viewer. On top of what the march finds, a narrow silver-lining lobe 0.6·τ e−τ·cos48θ uses the ray's own total transmittance: rims that are neither clear nor opaque are brightest toward the sun, a feature the march's steps are too coarse to resolve.

Sun color

The sun term is the scene light's color × intensity × π (restoring the normalization the phase divides out; without it the direct sun would be about three times too weak and clouds would read flat). With the transmittance LUT (Atmosphere), the color is attenuated by the air column from the deck's mid-point along the ray to the top of the atmosphere. For typed layers it is the reddening relative to a sun 30° up, mostly its hue and a little of its dimming, because the scene's sun is already tinted and dimmed for the ground; applying the full attenuation on top would make tops in a midday winter sun tan, and sunset clouds a dark maroon:

Relative reddening (typed layers)
r = T(h, μ) / T(h, max(μ, 0.5)) ,   Lsun = L · mix(1, r/ℓ(r), 0.7) · ℓ(r)0.3
  • T(h, μ)atmosphere transmittance LUT at altitude h and sun cosine μ
  • ℓRec. 709 luminance

The sun fades across the horizon in a soft band centered on the cloud's own horizon: a deck at 2 km sees the sun set about 1.4° later than the ground (dip = √(2h/R)). Explorer adds two host-side corrections. It dims its scene sun from 14° up for the ground's sake, so it passes sunScale to undo that for the clouds; and between 3.4° above and about 3° below the horizon it lights the clouds with the real sun through lightOverride, because the scene's key light has already switched to the moon while the clouds kilometers up are still in sunlight.

Ambient: the real sky

Shaded cloud is lit mostly by the sky, so the ambient term decides how real the clouds look. With useAtmosphere, two texel loads from the atmosphere pass's 2×1 distant-skylight LUT give a cosine-weighted upper-hemisphere average (for the tops) and a horizon-ring average (for the undersides, halved for the ground's occlusion), scaled by ATM_AMBIENT_SCALE = 1.5 and by the sun's intensity. Without the LUT the pass falls back to evaluating the atmosphere model in two directions per pixel. For the volume march the top light is desaturated by half (a tower in shade is gray, a little blue, not the color of the sky behind it) and the horizon light by 70% (at low sun it is warm, and taken at full hue it makes shaded sides brown through a winter afternoon).

Per sample the ambient is interpolated from bottom to top by height in the layer, multiplied by the profile's AO and by the light volume's sky visibility (0.35 + 0.65·vis), and dimmed by one fetch of the cloud a lobe's height overhead (180 m or two footprints): reaching up 1,500 m would make the whole shaded wall of a tower one flat gray. Light diffused through the cloud above is added back as a two-stream estimate, Tdiff = 1/(1 + K·τup) with CLOUD_DIFFUSE_K = 0.03, weighted by how much sky is hidden; this is what makes an overcast base a bright gray rather than a dark navy at noon. It applies only to a deck covering the sky (cover above 0.8): single cumulus lose their light out of their sides, and with it on they would go flat white. Ground bounce (ground albedo × sun × cos) lights the undersides, but only as far as the sky is open above them; unrestricted, under a storm it would make the cloud brown, the color of the ground.

Night, towns and lightning

Explorer sets ambientDimmer = 0.08 + 0.92·max(min(1, day/0.15), twilight), with twilight running until the sun is 6° down, and adds the light that is not the sky's on top, undimmed: nightAmbient (0.028, 0.036, 0.06 at full night), applied ×4 on the bases for the night ground's glow; and cityGlow, the warm (1.0, 0.68, 0.4) light of towns on cloud bases, its level read from the night-lights imagery within about 15 km and refined by a 5×5 grid of samples 16 km apart so the glow sits over the towns, not under the camera.

A lightning strike lights the cloud from within. The weather system's flash is placed 900 m above the strike point and passed as flash = (position, CLOUD_FLASH_GAIN × flash), with CLOUD_FLASH_GAIN = 40. Every sample adds

Flash glow (flash_glow)
Eflash = (0.82, 0.88, 1.0) · F · 1/(1 + (d/450 m)²) · (1 − smoothstep(2.5 km, 5 km, d)) / kdim

so the channel's surroundings are blinding and the glow carries a few kilometers through the cloud. The flash also raises ambientDimmer by 1.6 × flash so the whole deck brightens, and a point light lights the ground (see Rain, snow and wet weather).

Night on a runway in a storm: rain streaks, runway lights, and an almost black sky between flashes.
Between flashes. The Storm weather at night on runway 14 at KMFR. With no moon the deck is only the dim nightAmbient and town glow; each strike lights it from inside for the flash's 0.7 s.

Aerial perspective

Distant clouds must dissolve into the sky that the atmosphere pass already drew behind them, not just be tinted. The pass evaluates the atmosphere model's aerial perspective from the camera to the cloud's transmittance-weighted mean distance, takes the mean view transmittance v, and fades the cloud's opacity by (1 − v)·ATM_AERIAL_STRENGTH (0.5), attenuates its color by v, and adds the airlight weighted by the remaining opacity so it cannot over-brighten a vanishing cloud. The airlight is gated by the sun's elevation and by the light's intensity, because the model uses its own fixed sun and cannot see the night.

Cape Town from Table Mountain, with soft gray cloud banks over the bay fading toward the horizon.
Cape Town from Table Mountain. The deck thins toward the horizon as aerial perspective fades its opacity into the sky drawn behind it.

The craft's shadow, the glory and fog near the camera

src/shaders/clouds_hq.wgsl (caster_sun, glory_setup, glory_rgb, cloud_fog) · hq_cloud_pass.ts (setCasterShadows, setGlory, setInCloudFog, setHazeField) · cloud_caster_shape.ts · explorer/lib/weather/cloud_optics.ts · tools/explorer/bake_glory.py

Three options of the pass show the viewer's own flight. All are off by default, and Explorer turns them on. They share the TerrainShade uniform: past the terrain shadow and rain cells come the caster, the fog parameters, the glory's gain, the per-layer liquid flags, and a glory table row of 64 angles per layer. Each setter writes only its own range of the buffer.

Shadow

The Beer Shadow Map

src/shaders/clouds_hq.wgsl (fs_bsm, bsm_lookup_raw, beer_shadow_od, beer_shadow_col) · src/renderer/render_graph/passes/hq_cloud_pass.ts (updateSettings, _addBsm)

A short march toward the sun sees a cloud's own surface, not the tall cloud a few kilometers up-sun that should put it in shadow. The Beer Shadow Map renders the cloud once from the sun's direction, in an orthographic frame perpendicular to it, centered at mid-deck over the camera, and stores per texel a summary of the whole sun ray through the shell:

Depths are measured from the shell top so they stay small enough for half floats. The fragment shader marches 32 steps along the chord inside the shell (from the base crossing, so the steps are tens of meters, not hundreds) with the cheap, erosion-free density, and places cloud edges at the interpolated threshold crossing between samples so the stored depths vary smoothly instead of terracing the lit tops. The map is an atlas of two cascades side by side, BSM_SIZE = 512 texels each in an rgba16float 1024×512 texture; cascade 0 spans clamp(6 × deck thickness, 4 km, 20 km) (12 km for a 2 km deck, about 23 m texels) and cascade 1 ten times that.

shell top shell base sun front back p R = total optical depth G = top → front (along sun) B = front → back thickness τ(p) = R · (dtop(p) − G) / B
One texel of the Beer Shadow Map summarizes a whole sun ray. A point inside the cloud takes the share of the optical depth that lies between it and the sun, so the top of a cumulus is lit even when its column holds a lot of cloud below it, and the air above the deck is unshadowed.
Depth-aware lookup (beer_shadow_od)
τ(p) = min( R · clamp(dtop(p) − G, 0, B) / B , R ) · kBSM ,   Tsun = e−τ
  • dtop(p)distance from p to the shell top along the sun, recomputed per sample with the exact sphere form
  • kBSMbeerShadowStrength, 1 by default (physical)

Three constraints shape this. A map storing only the whole column's optical depth would give a point near the top of a cloud the shadow of everything below it; the depth-aware G and B channels prevent that. The fragment shader accepts sun-ray distances below zero, because the map plane is tilted with the sun, so half of it lies above the shell and its cloud is behind the texel's point; rejecting them would leave half of every cascade unshadowed, with a hard seam across the deck. And reading the map right at the sample would band the lit tops: in a cloud's surface layer a few meters of error swing the lighting, and bilinear depths over texels of 21–23 m are not that precise. Hence the hybrid, an exact local march over the first 400 m and the map beyond. The map is pinned to the world between rebuilds: its stored origin is re-expressed relative to the camera every frame, and it is rebuilt every BSM_INTERVAL = 4 frames, or at once when the sun turns (dot below 0.99995), the camera moves 4% of the extent, or any cloud parameter in its key changes. On phones, 256-texel cascades rebuilt every 8 frames.

With typed layers and a ready volume, eval_cloud returns the volume's density, so the map, the ground shadows and the god rays come from the same clouds that are drawn. Layers that cast no shadow are left out while “casting” (g_casting).

Cost

The march and its budget

src/shaders/clouds_hq.wgsl (fs_main) · src/renderer/render_graph/passes/hq_cloud_types.ts (CLOUD_DETAIL_QUALITY) · explorer/main.ts (syncHqClouds, GRAPHICS_PRESETS)

The rays are cast through pixel centers with no sub-pixel jitter; only the start of the march is offset, by interleaved gradient noise seeded on the march grid plus a phase that advances by the golden ratio once per full interleave cycle. (A phase tied to the frame index would give every pixel the same offset at each of its visits sixteen frames apart, and the noise would stay in the image as a fixed hatch.) Jittering the ray direction would make a static camera sample a different sub-pixel every frame, a residual sizzle the history cannot settle.

The volume march (layered)

Each layer's span is marched separately. Steps start short near the camera and grow with distance, are capped at 150 m of height change, and put at least eight samples through any span:

src/shaders/clouds_hq.wgsl · fs_main, volume marchWGSL
var st = min(min(cloud.quality.w * (10.0 + 0.006 * t), 150.0 / climb), max(seg_len / 8.0, 10.0));
let ts = t + st * noise01;
let p = camera.position + ray_dir * ts;
g_footprint = max(ts * pixel_angle * 2.0, st * 0.5);   // what this sample can resolve
var pr = vol_sample(p, altitude_of(p), st, true);
…
// Clear air: jump most of the way to the nearest cloud surface (the noise can
// bring it a little nearer than the volume says: keep a margin).
var adv = st;
if (dist_here < 0.0) {
  adv = max(st, (-dist_here - 200.0 - st) * 0.7);
}
t += adv;

That is sphere tracing through clear air with a 200 m margin for the displacement noise, and a step of 10 m plus 0.6% of the distance, scaled by the quality's volumeStep, inside cloud. The iteration cap is four times primarySteps. The sample footprint, twice the pixel's width at that distance (the march fills each pixel once per interleave cycle and the history does the rest) or half the step, drives every detail decision: noise mips, the edge width, whether micro detail is drawn. Grazing rays are deliberately not widened here: widening wipes the lobes off every cloud seen level or from below.

The procedural march (classic)

The classic march divides the shell's range into primarySteps steps capped at half the deck thickness (at least 250 m). After eight empty samples it switches to cheap, erosion-free probes at twice the step and backs up one step when they find cloud. Because the base step is often 100–400 m while a dense cumulus surface is a few tens of meters deep, a coarse hit triggers a refinement: back up to just past the previous empty sample and approach at max(step × fineStep, 16 m) until three empty samples, within a budget of 32 fine steps per span. Coarse probes use the erosion-free density, which never misses cloud the full density has (erosion only removes), so a ray grazing a thin edge finds it every frame. Far and grazing samples read coarser shape and erosion mips: without that band-limit, about 35% of march texels in a grazing storm-cloud band come out empty, a binary stipple.

Graphics presetcloudStepsInterleaveDetailfineStepLight detail stepsMicrovolumeStep
Low324×4low10no3
Medium484×4medium0.351no2
High644×4high0.23yes1.4
Ultra962×2ultra0.123yes1

The detail tier follows the step count. The classic style always uses the low tier and a 4×4 interleave. The march itself clamps primarySteps to 16–256.

What it costs

No timing here is a promise; GPU, resolution and view all matter. The numbers that are recorded in the repository:

MeasurementValueSource
Raymarch, Cape Town horizon with clouds, 1280×720, desktop GPU0.88 ms (bsm 0.25, reproject 0.04, godray 0.04, composite 0.02)pass-timing chart in the Explorer guide (explorer/docs/index.html)
Layered raymarch, phase per sample vs per pixel (as shipped)1.64 → 1.21 ms level; 1.71 → 1.24 above; 1.44 → 1.06 belowdevelopment notes
Interleave 1 (every pixel every frame) vs default1.4 → 4.0 ms on High; 1.8 → 4.9 ms on Ultracomment on cloudInterleave in explorer/main.ts
Temporal

Interleaving and reprojection

src/renderer/render_graph/passes/hq_cloud_pass.ts (MARCH_ORDER, addToGraph) · src/shaders/cloud_reproject.wgsl · src/shaders/cloud_composite.wgsl

The march target is one texel per n×n block of full-resolution pixels (n = 4 by default), and each frame it marches the one pixel of every block that MARCH_ORDER selects. The order is an ordered-dither sequence, so consecutive frames are spread across the block and any 3×3 neighborhood of fresh samples is evenly distributed. Every pixel is re-marched every 16 frames (every 4 with 2×2 blocks). The pass's own textures are named halfScatter and halfDepth, although the march target is 1/n resolution on each axis, not half.

0 8 2 10 12 4 14 6 3 11 1 9 15 7 13 5 4×4: the frame each pixel is marched on 0 2 3 1 2×2 (Ultra) per frame march ⌈W/n⌉ × ⌈H/n⌉ texels per pixel fresh every n² frames, history in between march offset IGN + golden-ratio phase per full cycle
MARCH_ORDER laid out on its block. Frames 0–3 already cover the block's four quadrants; the rest fill in between.

Reconstruction

The reprojection runs at full resolution into one of two persistent history textures (rgba16float, premultiplied color and opacity) and reads the other; the slots alternate, so there is no copy. For each pixel:

  1. Fast path. If the four enclosing fresh samples are bit-identical (no cloud along these rays, or a uniform deck) the result is that sample. Most of a downward city view, where rays hit the ground before the deck, takes this path and skips about 40 texture reads.
  2. Current estimate. A bilinear upsample of the fresh samples, each tap weighted by how well its scene depth matches this pixel's (σ = max(0.1·depth, 2 m)), so a foreground pixel never pulls cloud from a background tap. If this pixel was marched this frame, its own sample replaces the estimate. Weighting by the cloud's own hit depth would collapse to plain bilinear for in-front fog and halo.
  3. Clip box. Mean ± 1.5σ of the 3×3 fresh samples around the pixel (Salvi's variance clip, applied to color and alpha alike). A firefly cap pulls the current estimate down to 1.5× the neighborhood's brightest channel mean plus 0.02.
  4. Where to reproject. For sky pixels, the distance where the ray crosses the mid-deck sphere (stable per direction, yet with the deck's real parallax; a far-plane sentinel would drag history sideways across the deck while flying). Where there is cloud, the opacity-weighted mean of the fresh samples' cloud distance: a cloud passing close beside the camera keeps its history. Over terrain, the nearer of the two.
  5. History. A 5-tap Catmull-Rom read (bilinear reads would blur the history a little more every frame), clipped to the box. Off screen or on the first frame: three quarters of the 3×3 fresh mean.
  6. Blend. Motion-adaptive weights toward the current estimate, below.
src/shaders/cloud_reproject.wgsl · fs_mainWGSL
let flow_px = length((prev_uv - in.uv) * u.sizes.xy);
let motion = saturate((flow_px - 1.0) / 12.0);
// In fast motion a pixel is close to one raw march sample: lean on the fresh mean.
let soften = 0.75 * saturate(motion * 3.0);
if (soften > 0.0) { current = mix(current, fresh_mean(qc, scene_lin), soften); }
let quick = block_n() < 3.0;                       // 2x2 blocks
var blend = mix(select(0.15, 0.06, quick), 0.5, motion);
if (fresh) {                                        // this frame's marched pixel
  blend = mix(select(0.3, 0.12, quick), 0.75, motion);
}
return mix(history, current, blend);

A still image converges over many cycles; a pixel moving more than about a pixel per frame leans toward the fresh data, which cuts short the compounding of sub-pixel mis-registration into streaks. With 2×2 blocks samples arrive four times as often, so each counts for less and the settling time stays about the same. (The reprojectBlend setting is uploaded, but the shader's blend weights are these constants.)

camera mid-deck sphere cloud distance (opacity-weighted) sky: sphere hit geometry: scene depth prev_uv = project(prevViewProj, ray · d)
The reprojection distance per pixel. Cloud distance when the fresh samples around the pixel hold cloud (the nearer of it and the scene over terrain), the mid-deck sphere for clear sky, the scene depth for geometry.

The near march

Flying fast near cloud, the reprojected history falls behind: what is a few tens of meters off moves many pixels a frame, and each pixel is marched fresh only every 16 frames. With nearMarch set to a reach (Explorer: 250 m, above 30 m/s when the probed surface is within 250 m plus two seconds of flight, held 3 s; not on phones), a second march (fs_near) covers the ray up to that reach, at one pixel per 4×4 block every frame, and the main march starts at the reach. The near march keeps no history, so its start offset changes every frame, where the main march keeps one offset per cycle of its 16 frames (a fixed offset per pixel had left a fixed hatch). It writes how far its ray went. The reprojection then puts it in front of the resolved history: each full-resolution pixel blends the four nearest near-march texels bilinearly, weighted by how well their distance matches its own (min(scene depth, reach)), so geometry edges keep the right texel.

Composite and the rest of the frame

The composite is a manual premultiplied “over” rather than a hardware blend, because it softens the cloud's transmittance against the scene behind it: the transmittance is re-applied in Reinhard-tonemapped space against the scene luminance, so a bright background (the sun, bright sky) reduces the effective opacity and removes hard dark fringes and sun-edge flicker. The scene and its airlight are also multiplied by the god-ray factor (next section):

Composite
Lout = Ccloud + Lscene · Tperc(Lscene, 1 − α) · g
  • Tpercmax(ℓ′(1−α)/(1 − ℓ′(1−α)) / ℓ, (1−α)6), ℓ′ = ℓ/(1+ℓ)
  • gthe god-ray factor, mean sun transmittance along the view ray (1 when off)

Antialiasing runs later, so TAA sees the clouds as part of the HDR image. The cloud pass does not rely on it: it uses the un-jittered view-projection, does its own accumulation, and so is stable before TAA and works with any antialiasing mode (see Motion, antialiasing and the lens).

Coupling

What the clouds give the frame

src/shaders/clouds_hq.wgsl (fs_ground_lut, fs_godray) · src/shaders/reflection_probe_capture.wgsl (real_cloud_cover) · explorer/main.ts (DeferredLightingFeature cloudShadow, GodrayFeature groundShadowLut, probeCloudLut)

Shadows on the ground

addGroundShadowLutToGraph adds the Beer Shadow Map early in the graph, before deferred lighting, and bakes from it a top-down 1024² r8unorm map, 60 km across and recentered on the camera, of the clouds' transmittance to the sun. Each texel is a point on a receiving plane at the ground (the camera's altitude below it, not the camera's own height, so shadows land under the right clouds when flying high), and the full column optical depth of the sun ray through it gives exp(−τ). Because the lookup follows the sun ray, shadows fall offset from their clouds at a low sun. The deferred sun term reads this map (Shadows), as does the engine's god-ray feature. The format and parameter buffer match the engine's procedural cloud-shadow pass, so consumers read either one unchanged.

The Grand Canyon from high above with no clouds. The same view with a soft cloud deck below the camera and its shadows darkening the canyon.
Clouds offClouds on
Grand Canyon from above the deck. Drag to compare. The deck and the shadows it casts on the canyon, which the deferred lighting reads from the ground LUT baked out of the Beer Shadow Map.

God rays

fs_godray marches the view ray at half resolution, 24 regular (unjittered) steps over at most 12 km or to the scene depth, reading exp(−τ) from the depth-aware Beer Shadow Map, and outputs the mean as a factor mixed toward 1 by the god-ray strength (0.6 in Explorer). The composite multiplies the scene and its airlight by it, so shadowed air darkens and the lit gaps read as beams. An additive glow would be, in clear sky, a uniform sun haze that blows out, and with per-frame jitter and no accumulation the rays would shimmer. The multiplicative factor cannot blow out and needs no jitter, because the map is smooth. When the ground already takes the cloud shadow through the deferred sun term (surfaceShadowed), only the share of a surface pixel that is air, 1 − e−d/15 km, is darkened, so the ground is not shadowed twice. The engine's separate screen-space god-ray effect is described in Atmosphere.

The sky probe's view of the deck

Reflections need the clouds too. Each frame the ground LUT is copied into a persistent 1024² probeCloudLut texture, together with the deck and ground heights relative to the camera and the sun direction. The reflection-probe capture intersects each direction with the deck's height, follows the sun ray from there down to the ground plane, and reads the transmittance as cover: cloud seen from below (overhead) or above (a sea of cloud), lit by the probe's simple sun-and-sky model. So aircraft paint and water reflect the real deck instead of a stylized noise layer (Lighting).

Trails

Contrails and cirrus

explorer/lib/aircraft/contrails.ts · explorer/main.ts (contrailField, contrailAir, smoke sprites) · explorer/lib/fire/fire_feature.ts · explorer/lib/fire/fire_sprites.wgsl

Contrails are not part of the cloud volume. They are bookkeeping in ContrailField and are drawn as sprites. A jet leaves puffs at each of its nozzles (a little behind each exhaust, from the aircraft model's exhaust list) whenever the air there is colder than CONTRAIL_COLD_K = 233 K (−40 °C, about 26,000 ft and up on a standard day). The temperature comes from the standard atmosphere shifted by the weather's or the live report's temperature offset, so a cold day lowers the contrail level. Every jet can leave one: the player's aircraft, the other players and AI, and live ADS-B traffic in the jet categories.

LimitValueWhy
Puff spacing near the camera6 mgrows with distance beyond 1.5 km, up to 6× (a far trail looks the same with a tenth of the puffs)
Life90 sspreading and fading over a minute and a half
Thinningafter 4 s, every 4th puffonce spread, neighbors overlap
Puffs / sources9,000 / 24 per framea sky full of airliners stays cheap; own aircraft first, then nearest

Each puff becomes a blended “smoke” sprite in the fire feature's sprite batch (radix-sorted far to near, soft against the depth buffer): a white (0.9, 0.93, 1.0) puff of size 2·spread + 24√age m and opacity 0.26·(1 − age)1.6, fading in over its first 200 ms, with a brightness multiplier of 2 because ice lit like a cloud is brighter than smoke's own white. The intent recorded in the code is subtle: a thin, faint line that widens and fades, not a solid band.

Where cirrus lives

The pass supports up to three thin “sheet” layers above the main deck (layers, or the deprecated cirrus* fields): stretched 4.5:1 along X, with a feathered vertical profile, marched in the single-shell mode. Explorer does not use them: syncHqClouds sets cirrus = false, because the weathers bring their own cirrus as a typed layer (8–9.6 km in clear, few, scattered, showers, high-clouds and overcast skies): wind-stretched 4.5:1, density scale 0.05, edge sharpness 0 so it is a veil, and no shadow cast.

Design note

Options that do not earn their cost: 64 slices instead of 40 in the cloud volume (no visible change on cumulonimbus); a near/far two-layer march with two histories (no sharper edges in a strafe test, and +0.5 ms even switched off); a bicubic volume fetch out to a footprint of 150 m (no visible difference on far cumulonimbus); micro-erosion on cumulus (it erodes small cumulus away). None of these is worth adding without a failing test case first.

Further reading

References

  1. A. Schneider and N. Vos, “The Real-Time Volumetric Cloudscapes of Horizon Zero Dawn”, SIGGRAPH 2015 Advances in Real-Time Rendering course. The shape/erosion remap, height curves, beer-powder and the in-scatter (“dark edges”) term.
  2. S. Hillaire, physically based sky, atmosphere and cloud rendering, SIGGRAPH 2016 Physically Based Shading course. Energy-conserving per-step integration, octave multiple scattering, temporal reprojection of clouds.
  3. M. Wrenninge, C. Kulla and V. Lundqvist, “Oz: The Great and Volumetric”, SIGGRAPH 2013 Talks. The multiple-scattering octave approximation summed in ms_transfer.
  4. J. Jendersie and E. d'Eon, “An Approximate Mie Scattering Function for Fog and Cloud Rendering”, SIGGRAPH 2023 Talks. The HG + Draine fit used when accuratePhase is on.
  5. B. T. Draine, “Scattering by Interstellar Dust Grains. I. Optical and Ultraviolet”, The Astrophysical Journal 598, 2003. The Draine phase function.
  6. L. G. Henyey and J. L. Greenstein, “Diffuse radiation in the galaxy”, The Astrophysical Journal 93, 1941. The HG phase function.
  7. M. Salvi, “An Excursion in Temporal Supersampling”, GDC 2016. The variance clip box in the reprojection.
  8. J. Jimenez, “Next Generation Post Processing in Call of Duty: Advanced Warfare”, SIGGRAPH 2014 Advances course. Interleaved gradient noise for the march start offset.
  9. C. Sigg and M. Hadwiger, “Fast Third-Order Texture Filtering”, GPU Gems 2, 2005. The cubic B-spline from four bilinear fetches used on the cloud and light volumes.
  10. J. C. Hart, “Sphere Tracing: A Geometric Method for the Antialiased Ray Tracing of Implicit Surfaces”, The Visual Computer 12, 1996. The clear-air jumps of the volume march.