Taos Explorer Technology Launch Taos ExplorerLaunch ↗

Technology / Rendering / 04

Rendering deep dive · 04

Painting the air, from the street to orbit

Mount Everest at sunrise. The sun sits just behind the summit, surrounded by a wide forward-scattering glow; the sky shades from pale gold near the sun to deep blue overhead.
Everest at sunrise. Everything in the sky here is computed: the blue from Rayleigh scattering, the broad glow around the hidden sun from the forward-peaked Mie phase function, the warm band on the horizon from the long slant path through the air, and the blue cast on the far ranges from aerial perspective.
256×64transmittance table, rgba16float, baked once at startup
192×108sky-view table, re-baked every frame
32³ × 2aerial froxel volume: in-scatter + per-channel transmittance
g = 0.758Cornette–Shanks Mie phase for the haze
60 kmEarth's shell; Mars 80 km; the Moon 500 m
32 stepshalf-resolution god-ray march, Henyey–Greenstein g = 0.55

Taos Explorer's camera can stand in a Manhattan street, sit in a cockpit at 11 km, ride the space station at 400 km, or stand in a crater on Mars, and the sky has to be right in all of them without a loading screen in between. The air has to tint a skyline 20 km away, redden the sun at dusk, dim the stars by day, and, seen from orbit, shrink to a thin glowing rim around the planet. This page follows that system from the physical constants to the pixels: one scattering model, four lookup tables, a froxel volume for the haze, an analytic height fog for weather, a shadow-mapped light-shaft march, and a small coordinator that moves all of it onto the real globe every frame.

The physical model

The air as numbers

src/shaders/modules/atmosphere_model.wgsl · src/renderer/render_graph/passes/atmosphere_pass.ts · src/geo/geo_sky.ts · explorer/main.ts

Every part of the atmosphere on this page, the sky dome, the baked tables, the haze on geometry and the cloud lighting, reads one set of parameters. In WGSL it is the AtmosphereParams struct, with Earth's reference values in a constant named EARTH_ATMOSPHERE; on the TypeScript side the same numbers appear as EARTH_PARAMS (the dome), EARTH_LUT_PARAMS (the table bakes) and EARTH_AERIAL (the haze). Units are meters. The model has three constituents.

ConstituentCoefficient (per m)Density profilePhase
Rayleigh (molecules)βR = (5.5, 13.0, 22.4)×10⁻⁶e−h/85003/(16π)·(1+μ²)
Mie (aerosols)βM = 21×10⁻⁶ scattering, ×1.1 extinctione−h/1200Cornette–Shanks, g = 0.758
Ozone (Chappuis band)βO = (0.650, 1.881, 0.085)×10⁻⁶tent: 1 at 25 km, 0 at 10 and 40 kmnone (absorbs only)

The three channels are wavelengths 680, 550 and 440 nm. Rayleigh goes roughly as λ⁻⁴, which is why blue's coefficient is four times red's. Mie is wavelength-independent, so haze is white or gray. Mie extinction is scattering times 1.1, a fixed allowance for aerosol absorption that appears in every optical-depth sum in the codebase (atm.beta_m * 1.1 * od.y); the bake shaders, the dome and the froxel march all agree on it. Ozone never scatters, so it contributes to extinction but has no phase function and no in-scatter term. Its job is the twilight zenith: with the sun down, light reaching the overhead sky has crossed a long path through the 10–40 km layer, and ozone's orange-green absorption keeps that sky blue-violet instead of gray.

0 km 10 20 30 40 50 60 top of the shell, ra = re + 60 km relative density (1 at the bottom of each profile) 1 0 Rayleigh, H = 8.5 km Mie, H = 1.2 km ozone tent, peak 25 km
The density profiles, to scale. Half of all Rayleigh optical depth lies below 5.9 km, half of the Mie below 830 m; that is why haze is a near-ground phenomenon and the deep blue of the high sky belongs to the molecules alone.

From these constants the vertical optical depth from sea level to space is τ = β·H for an exponential layer, or β·(half-width) for the tent. Rayleigh gives τ = (0.047, 0.111, 0.190), Mie 0.028 at the reference βM, ozone (0.010, 0.028, 0.001). The noon sun therefore arrives with about 92%, 85% and 80% of its red, green and blue: white, very slightly warm. A horizontal ray from the ground crosses roughly 876 km of shell (√(ra²−re²)), and the air near the bottom of it is the densest; blue barely survives that, which is the sunset.

The shell and the planet

The reference model has r_e = 6,360 km and r_a = 6,420 km, a 60 km shell. Those radii are only used when the curved-horizon mode is off (a flat-world path that parks the camera on the +Y axis at its world height). In Explorer the curved horizon is on by default, and then the ground radius is not a constant at all: it is the local radius of the WGS84 ellipsoid under the camera, set every frame (see On the real globe). The shell stays 60 km thick, which setPlanet turns into a scale factor s = thickness / 60,000 = 1, so Earth gets the coefficients unscaled.

Per-body air

The same code renders three bodies. Each carries an optional CelestialBodyAtmosphere (in src/geo/geo_sky.ts) whose fields override the dome and the aerial haze every frame while the camera is near it:

BodyβR ×10⁻⁶βM ×10⁻⁶ShellAerial hazeNotes
Earth (reference)5.5, 13.0, 22.42160 kmfullengine default
Earth in Explorer (EARTH_AIR)5.882, 12.292, 27.500from the weather (12 before the first)60 kmfullRayleigh and ozone fitted to the full spectrum (EARTH_BETA_R_FITTED, EARTH_BETA_O_FITTED, ozone 2.569, 1.662, 0 at 300 DU, scaled by the column); the haze from the weather (below)
Mars (MARS_ATMOSPHERE)21, 12, 6980 kmaerialStrength: 0red-dominant "Rayleigh"; tuned by eye, not physical
Moon(unchanged)500 moffhasAtmosphere: false, black sky

Mars is honest about being a fake. The comment on MARS_ATMOSPHERE says the real Martian sky is dust-driven Mie scattering that the model cannot reproduce, so the constants swap Rayleigh's color order to get a butterscotch dome. The interesting entry is aerialStrength: 0: Mars' air is about 1% of Earth's, and Earth-strength haze, which is additive and grows with path length, would wash the surface to sky color at grazing angles. Mars keeps its sky and loses its haze. The Moon keeps βR but its shell is collapsed to 500 m, so every integral sees almost no air and returns black, while the same shader still draws the sun disk, the stars and the lit ground globe.

Low over Jezero crater on Mars. A butterscotch sky fades to a pale band at the horizon above rust-colored terrain.
Jezero crater, Mars. The dome uses Mars' red-first coefficients over an 80 km shell; the aerial haze is switched off. The crater floor is 2–3 km below Mars' reference surface, which the scattering ground has to allow for (see On the real globe).
The core integral

Single scattering, step by step

src/shaders/modules/atmosphere_model.wgsl (scatterP, opticalDepthToSkyP, transmittanceP, phaseR, phaseM)

The dome, the sky-view bake and the 2×1 skylight bake all call one function, scatterP. It evaluates the single-scattering radiance arriving at a point x from direction v: sunlight scattered exactly once into the view ray, with attenuation on the way in and on the way out.

Single scattering along a view ray
L(x,v) = Esun ∫t0t1 T(x, p) · [ βR ρR(h) PR(μ) + βM ρM(h) PM(μ) ] · T(p, sun) dt
T(a,b) = exp( −βR∫ρR − 1.1 βM∫ρM − βO∫ρO )
  • px + t v, a point on the view ray; h = |p| − re
  • t₀, t₁where the ray enters and leaves the shell, clipped at the ground sphere (re)
  • μcos of the angle between the view ray and the sun direction
  • Esunsun_intensity, 20 in the renderer's HDR units
  • T(p, sun)0 when the planet blocks the sun from p
Phase functions
PR(μ) = 316π(1 + μ²)     PM(μ) = 38π (1 − g²)(1 + μ²)(2 + g²)(1 + g² − 2gμ)3/2
  • g0.758 everywhere the air is shaded (dome, bakes, froxel march: G and AP_MIE_G); the Cornette–Shanks form keeps a small backward lobe that pure Henyey–Greenstein lacks

With g = 0.758 the Mie lobe is about 380 times brighter straight forward than straight back. That lobe is the glow around the sun in the hero image, and why the haze toward the sun is so much brighter than the haze opposite it. The code is a direct discretization of the two lines above, with the optical depth of the view ray accumulated as it goes and a nested 8-sample march toward the sun at every step:

src/shaders/modules/atmosphere_model.wgsl · scatterP (trimmed)WGSL
let graze_chord = sqrt(max((atm.r_a - atm.r_e) * 2.0 * atm.r_a, 1.0));
let n_samples = 8 + i32(24.0 * sqrt(saturate((tMax - tMin) / graze_chord)));
let ds = (tMax - tMin) / f32(n_samples);
for (var i = 0; i < n_samples; i++) {
  let pos = ro + rd * (tMin + (f32(i) + 0.5) * ds);
  var h   = length(pos) - atm.r_e;
  if (h < 0.0) { if (!horizonless) { break; } h = 0.0; }
  let hrh = exp(-h / atm.h_r) * ds;
  let hmh = exp(-h / atm.h_m) * ds;
  odR += hrh;  odM += hmh;
  if (ozone) { odO += ozoneDensityP(h, atm) * ds; }
  // … ground-bounce accumulation …
  let tg2 = raySphere(pos, sunDir, atm.r_e);
  if (tg2.x > 0.0 && !horizonless) { continue; }   // sample in the planet's shadow
  let odL = opticalDepthToSkyP(pos, sunDir, ozone, atm, horizonless);
  let tau = atm.beta_r * (odR + odL.x)
          + atm.beta_m * 1.1 * (odM + odL.y)
          + atm.beta_o * (odO + odL.z);
  let T = exp(-tau);
  sumR += T * hrh;
  sumM += T * hmh;
}
let direct = atm.sun_intensity * (atm.beta_r * pR * sumR + vec3<f32>(atm.beta_m) * pM * sumM);

Spending samples where the sky changes

A zenith ray from the ground crosses 60 km of air; a horizon-grazing ray crosses hundreds of kilometers, and its integrand varies the whole way. A fixed count either wastes work looking up or bands at the horizon and the sunset. The count is 8 + ⌊24·√(path / grazing chord)⌋, where the grazing chord √(2·ra·shell) is about 878 km for Earth. A vertical ray from the ground gets 14 samples, a horizontal one 32. The analytic sky color the haze shader can fall back on uses the same idea with 6 to 24.

The planet-shadow guard, and the white flash

The sun-ray march, opticalDepthToSkyP, begins with a test that looks redundant and is not:

src/shaders/modules/atmosphere_model.wgsl · opticalDepthToSkyPWGSL
// If the ray toward the sky/sun is blocked by the planet (the sun is below the
// local horizon), the slant path is effectively opaque — return a huge optical
// depth so transmittance → 0. Without this the march below `break`s on its
// first below-surface sample and returns a near-zero depth, which reads as a
// full, un-reddened (white) sun …
if (!horizonless) {
  let tg = raySphere(pos, dir, atm.r_e);
  if (tg.x > 0.0) { return vec3<f32>(1e9, 1e9, 1e9); }
}

Without it, the instant the sun dips below the horizon the sun-ray march steps inside the planet, breaks out of its loop with almost no optical depth, and reports a fully transparent path. The broad flare halo would then flash pale white across the horizon for a moment between the orange sunset and night. The haze needs a sharper form of the same guard (see below-horizon guards), because a sample clamped exactly onto the surface has an entry root of zero rather than a positive one.

Ground bounce

Sunlit ground reflects light back into the low air, which brightens and warms the lower sky. scatterP folds this in as a second, isotropic source: sun irradiance on the ground (through the transmittance from the ground point to the sun) times an Oren–Nayar factor with roughness σ = 0.7, times the ground albedo (0.18, 0.15, 0.10), in-scattered with phase 1/4π and faded out above 4 km (GROUND_BOUNCE_H) with gain 6 (GROUND_BOUNCE_STRENGTH). Each body's groundAlbedo overrides the albedo, so the Martian bounce is rust.

AtmosphereLutsFeature

Tables baked once: transmittance and multiple scattering

src/renderer/features/atmosphere_luts_feature.ts · src/renderer/render_graph/passes/atmosphere_luts_pass.ts · src/shaders/atmosphere_transmittance_lut.wgsl · src/shaders/atmosphere_multiscatter_lut.wgsl · src/shaders/modules/atmosphere_luts.wgsl

Two quantities depend only on the atmosphere's constants, not on the camera or the sun: the transmittance from any altitude in any direction to the top of the shell, and the second-and-higher-order scattering that a point receives for a given sun zenith angle. Both are functions of two variables, so both are 2D textures. AtmosphereLutsFeature bakes them into persistent render-graph textures and publishes the handles under atmosphere:transmittance_lut and atmosphere:multiscatter_lut in frame.extras.

TableSize, formatAxesBake cost per texelRe-baked
Transmittance256×64 rgba16floatu: cos zenith (sqrt warp), v: altitude 0–60 km (linear)one 8-step optical-depth marchwhen a parameter changes
Multiple scattering32×32 rgba16floatu: cos sun zenith (same warp), v: altitude16 directions × 16 stepswhenever transmittance is
Correction

A comment where Explorer registers the feature says the transmittance table is "baked once per sun move". The code says otherwise: setParams compares every field and only marks the tables dirty when one changes, and Explorer never calls it, so both tables bake on the first frame that reads them and never again. Nothing in them depends on the sun. The table that really is re-baked when the sun moves is the 2×1 distant-skylight table in the next section.

Parameterization

Transmittance changes fastest for rays that skim the horizon, so the cos-zenith axis is warped: the bake maps the texel's unit coordinate x ∈ [−1, 1] to cos θ = sign(x)·x², and lookups apply the inverse, u = ½ + ½·sign(cos θ)·√|cos θ|. Half of the 256 columns cover the band within 14.5° of the horizon (|cos θ| ≤ 0.25). Altitude is linear in v.

table u: evenly spaced columns cos zenith (linear) −1 (down) 0 (horizon) +1 (up)
The sqrt warp shared by the transmittance and multiple-scattering tables. Columns bunch around the horizon, where a ray's path length through the air explodes.

Both tables also use sub-texel endpoint remapping: the unit parameter x is mapped to (x(N−1) + ½)/N before sampling, and the bake applies the inverse to its texel centers. Texel 0 then holds exactly the ground-level value and texel N−1 exactly the top of the shell. Without the remap, the "ground-level" transmittance that consumers read would really be the row about 470 m up, half a texel inside the border.

The transmittance bake calls the same opticalDepthToSkyP as the dome, but in horizonless mode: rays pointing into the planet keep accumulating air at surface density instead of returning infinity. The table is deliberately an upper bound that ignores the planet's own shadow, which is what its two consumers want (sun-disk color and sunlight reaching a cloud). Its below-horizon texels therefore stay bright, which the haze has to gate (see Aerial perspective).

Multiple scattering in one table

The multiple-scattering table follows Hillaire (2020). For a point at altitude h with the sun at a given zenith angle, the bake shoots N = 16 directions on a spherical Fibonacci spiral and marches 16 steps along each, using the transmittance table for both the sun path and the step attenuation. It accumulates two integrals with an isotropic phase:

Geometric series for all orders ≥ 2
L2 = 1N Σdirs ∫ T · Esun Tsun 14π σs dt    fms = 1N Σdirs ∫ T σs 14π dt
Ψms = L21 − fms     Lms(p) = Ψms(h, μsun) · σs(h)
  • fmsthe fraction of light re-scattered per bounce; each order is fms times the previous, so the sum is 1/(1 − fms)
  • σslocal scattering coefficient, βRρR + βMρM; the table stores luminance per unit σs, the consumer multiplies it back

Each step uses the energy-conserving segment integral ∫ = σs(1 − e−σeΔs)/σe rather than σsΔs. Directions that strike the ground add Hillaire's ground term: the sunlit surface as a Lambertian source, albedo/π · N·L · Tsun, seen through the accumulated view transmittance. It adds luminance only; it does not feed fms, since a reflection is a light source, not a scattering event. Without it, near-horizon texels would integrate only extinction toward the ground and the grazing zone would come out dark.

Baking into a persistent texture

The tables live in persistent graph textures that are only drawn into on frames that bake. The render graph culls passes whose outputs nobody reads, and on the first frame the clouds might be off. So the "needs bake" flags are cleared inside the pass's execute callback, which only runs if the pass survived culling. Clearing them when the pass is added to the graph would let a culled bake count as done and leave the table black for the rest of the session.

Who reads them in Explorer

The engine's dome can add Ψms·σs to every sky pixel, but only when the AtmosphereFeature is created with useMultiscatterLut: true. Explorer does not set it, so its dome is single scattering plus ground bounce. The tables are consumed elsewhere:

The tables are baked from EARTH_LUT_PARAMS, the reference Earth values. The per-body overrides (Explorer's clear-day βM = 12×10⁻⁶, Mars' coefficients) reach the dome and the haze every frame but not these two tables, which Explorer never re-parameterizes.

AtmosphereFeature · AtmospherePass

The sky-view table and the dome

src/renderer/features/atmosphere_feature.ts · src/renderer/render_graph/passes/atmosphere_pass.ts · src/shaders/atmosphere.wgsl · src/shaders/atmosphere_skyview_lut.wgsl · src/shaders/atmosphere_skylight_lut.wgsl

The visible sky is a fullscreen triangle drawn by AtmospherePass into the HDR target. In Explorer it runs after the G-buffer and before deferred lighting (frame order: shadows, geometry, AO, atmosphere, lighting, water, stars and distant bodies, god rays, clouds, post; see Anatomy of a frame). The pass records up to three draws per frame.

#PassWritesWhen
1AtmospherePass.skyViewBake192×108 rgba16float, transientevery frame (depends on the sun and the camera altitude)
2AtmospherePass.skylightBake2×1 rgba16float, persistentonly when its quantized inputs change
3AtmospherePassthe HDR targetevery frame; geometry pixels exit early

The sky-view table

Hillaire's sky-view table replaces the per-pixel integral with one texture tap. Each of its 20,736 texels runs exactly the scatterP integral that one sky pixel would have run, for the current camera position and sun. Then every sky pixel reads one bilinear sample. The bake shader declares the dome's uniform struct byte for byte, including fields it never reads, so both draws bind the same buffer; a per-body coefficient change or a new ground radius reaches the table on the same frame with no extra code.

The mapping is azimuth around the sun and warped elevation. The frame is built from local up and the sun's horizontal projection, so u = 0.5 always faces the sun:

Default sky-view mapping (skyViewUv)
u = φ2π + ½     v = ½ + ½ · sign(ℓ) √|ℓ|,   ℓ = elevationπ/2
  • φazimuth measured from the sun's direction projected onto the horizontal plane

The signed square root gives the horizon the most rows. But it assumes the horizon is at elevation zero, and at altitude it is not: the geometric horizon dips below horizontal by asin √(1 − (re/r)²), about 19.8° at the space station's 400 km. The bright limb of the atmosphere sits on that dipped horizon, between two widely spaced rows of the default mapping, and it banded.

default (skyViewUv) altitude-horizon, 400 km (skyViewUvH) limb at 400 km horizontal horizontal rows nearest the limb: −10°, −22.5° rows nearest the limb: −16.7°, −19.8°, −21.7°
Thirteen evenly spaced table rows (of 108), drawn at the elevation each one samples. At the ground both mappings are identical; at 400 km the altitude-horizon mapping re-centers the dense band on the limb.

The altitude-horizon variant, skyViewUvH, takes the sine of the dipped horizon from horizonSinFromUp (−√(1 − (re/r)²)) and applies the square-root warp separately above and below it: v = ½ + ½√t with t = (el − elH)/(π/2 − elH) above the horizon, mirrored below. At the surface elH = 0 and the formula reduces exactly to the default, so switching it on cannot change a ground view. It is selected by flag bit 7 of the dome's uniform, and the bake, the dome and the haze composite must all agree on it or the sky slides against the terrain. Explorer pins it on: effects.limbSkyview = true is forced after saved settings load, alongside the other pinned rendering choices.

src/shaders/modules/atmosphere_model.wgsl · skyViewUvHWGSL
fn skyViewUvH(rd: vec3<f32>, up: vec3<f32>, sunDir: vec3<f32>, sinHorizon: f32) -> vec2<f32> {
  let b   = skyViewBasis(up, sunDir);
  let el  = asin(clamp(dot(rd, up), -1.0, 1.0));
  let elH = asin(clamp(sinHorizon, -1.0, 1.0));
  var v: f32;
  if (el > elH) {
    let t = (el - elH) / max(PI * 0.5 - elH, 1e-4);   // 0 at horizon → 1 at zenith
    v = 0.5 + 0.5 * sqrt(saturate(t));
  } else {
    let t = (elH - el) / max(elH + PI * 0.5, 1e-4);   // 0 at horizon → 1 at nadir
    v = 0.5 - 0.5 * sqrt(saturate(t));
  }
  let az = atan2(dot(rd, b[1]), dot(rd, b[0]));
  return vec2<f32>(clamp(az / (2.0 * PI) + 0.5, 0.0, 1.0), clamp(v, 0.0, 1.0));
}

The table stores only the smooth part of the sky. The sun and moon disks, their halos and the stars are high-frequency and are added per pixel after the tap.

The distant-skylight table

A third bake integrates the sky into two texels: texel 0 is the cosine-weighted average over the upper hemisphere (32 directions, what a horizontal surface or a cloud top sees), texel 1 the average around the horizon ring (16 directions, what a cloud's shaded flank sees). The HQ clouds use these as their ambient light instead of evaluating scatterP along their own rays. Two texels sound free, but each is a full hemisphere of integrals; the code comment puts the bake at 0.5–1.2 ms. So it lives in a persistent texture and is re-baked only when its quantized inputs change:

Keying on the camera's world position instead would re-bake the table, at up to a millisecond, every few frames in flight, since the position moves 10 m that often. Keying on altitude and up matches what the integral actually depends on. As with the bake flags above, the "last baked" key is recorded inside the execute callback, so a frame that culls the pass does not count as a bake.

The dome fragment

The fragment shader reconstructs a world-space ray from the inverse view-projection matrix and then, before any atmosphere math, reads the G-buffer depth. Any pixel covered by geometry returns black, because the lighting pass will overwrite it. The derivative it needs later for the moon's edge (fwidth of the moon cosine) is taken above that early exit, since derivatives must sit in uniform control flow.

src/shaders/atmosphere.wgsl · fs_main (trimmed)WGSL
var ro: vec3<f32>;
if (u.mode == 0u) { ro = vec3<f32>(0.0, atm.r_e + max(u.cameraPos.y, 1.0), 0.0); }  // flat world
else               { ro = u.cameraPos - u.planetCenter; }                          // on the globe
let localUp = select(vec3<f32>(0.0, 1.0, 0.0), normalize(ro), u.mode == 1u);
let sunElev = dot(u.sunDir, localUp);
// Single scattering leaves a warm band on the horizon long after sunset; fade
// the scattering (and the sun disk) out, gone by ~7° below the horizon.
let sky_t = saturate((sunElev + 0.12) / 0.12);
var inscatter: vec3<f32>;
if (USE_SKYVIEW_LUT) {
  let sv_uv = select(skyViewUv(rd, localUp, u.sunDir),
                     skyViewUvH(rd, localUp, u.sunDir, horizonSinFromUp(ro, atm)),
                     (u.flags & 128u) != 0u);
  inscatter = textureSampleLevel(skyview_lut, atm_lut_samp, sv_uv, 0.0).rgb;
} else {
  inscatter = scatterP(ro, rd, u.sunDir, ozone, atm, horizonless);
}
var color = inscatter * sky_t;

The sky_t fade exists because single scattering cannot produce real twilight. The far, high end of a horizon-grazing ray stays sunlit long after the sun sets, so a pure single-scattering sky keeps a warm sunset band under the stars for hours. Real twilight light has scattered several times. Rather than model that, the dome fades the scattering out between sun elevation sin⁻¹(0) and sin⁻¹(−0.12) ≈ −6.9°, the end of civil twilight.

Sun disk and halo

The disk is every ray within SUN_COS_THRESH = 0.9996 of the sun, an angular radius of about 1.6°, several times the real sun's 0.27°: a real-size disk is a few pixels and reads as a dot. It is drawn at 1000 × the camera-to-sun transmittance, so it reddens and dims with the path. Around it, sunFlare adds two lobes in the cosine of the angle to the sun:

Sun flare (sunFlare)
F(μ) = S · [ μk + 0.12 · μmax(0.08k, 2) ] · Tsun · sky_t
  • k240 in Explorer (setSunFlare(240, …)): the inner lobe hugs the disk; the outer lobe, μ19.2, spreads faint glare over tens of degrees
  • Sthe Sun flare setting, default 6

This halo is a stand-in for the forward Mie peak near the disk, which the table cannot resolve at its azimuth resolution. It is separate from the lens flare and bloom, which are camera effects (see Motion, antialiasing and the lens).

The painted moon, briefly

The dome also paints a moon disk from a direction supplied each frame from the ephemeris, shaded as a lit sphere: a smoothstep terminator of half-width 0.42 in N·L, earthshine of 0.02 filling the dark side, an analytic one-pixel rim feather (temporal antialiasing rejects the tiny, high-contrast disk), and a cool halo weighted by the lit fraction with a floor of 0.12. Explorer keeps it visible by day (setMoonDaylight(true)), hides the painted disk but keeps its halo when the streamed Moon ball is drawn, and hides it entirely away from Earth. The real Moon, the stars and the other worlds are the subject of Space, stars and other worlds.

Flags

BitMeaningExplorer
0ozone absorptionon
1horizonless sky (no ground clip, no planet shadow)off
2explicit moon phase instead of the geometric oneoff: lit by the real sun
3lit planet surface where rays strike the ground sphereon with the curved horizon
4 / 5hide the painted moon / only its diskper body and streamed-Moon state
6painted moon visible by dayon
7altitude-horizon sky-view mappingon (pinned)
8Earth-style procedural continents on the lit globeEarth only
9hide the built-in procedural starson with the curved horizon (a separate star pass draws them)
Not the black hemisphere

In other Taos scenes a black lower half of the sky usually comes from CompositeFeature's blackLowerHemisphere option, which multiplies the final image by a smoothstep on the ray's Y for rays below the horizon, not from the atmosphere. Explorer does not register that feature. Its below-horizon pixels come from the dome: in flat mode a muted two-tone ground that melts into the horizon glow, and on the globe the painted planet surface.

CurvedHorizonSky

On the real globe, street to orbit

src/geo/geo_sky.ts · src/shaders/atmosphere.wgsl (planet surface, limb glow) · explorer/main.ts (bodies, sky.update)

Explorer works in a floating-origin frame: world space is a local tangent plane at the start location, with +Y up there, and the center of the Earth is millions of meters "below" the origin (see Anatomy of a frame). The dome's planet mode handles this with one subtraction. The ray origin is cameraPos − planetCenter, a planet-centered position, while the ray direction stays in world space, because a direction is the same in both frames. Every formula on this page then works unchanged, whether the camera is on the street or 3,000 km out.

CurvedHorizonSky is the coordinator that keeps the dome, the haze and the star pass consistent. Turning it on calls setPlanet({ radius: WGS84_A, atmosphereHeight: ATMOSPHERE_SHELL_M }) (60 km) on the dome, moves the haze's radii onto the globe and enables the painted planet surface. Then every frame update() does the following.

  1. Re-centers. The active body's center is mapped through the current floating frame (it moves on every re-anchor) and handed to the dome and the haze.
  2. Sets the ground radius. The atmosphere's ground is a true sphere, but Earth is an ellipsoid whose surface is about 21 km closer to the center at the poles than at the equator. With a fixed equatorial radius, a camera at mid-latitude would be kilometers underground as far as the scattering knew, and the sky would go black. So the radius is set each frame to the geocentric radius of the ellipsoid under the camera: camRadius − ecefToGeodetic(cameraEcef).height for Earth, a constant for the Moon, and a biaxial spheroid formula for Mars.
  3. Clamps it below the camera. groundR = min(rawGroundR, camRadius − 2). Real terrain dips below the datum (Jezero's floor is 2–3 km below the Mars reference surface), which would put the camera "underground" again: a black horizon and a haze optical depth so large it reads as solid fog. Keeping the scattering ground two meters under the camera makes the math valid from any real surface; the streamed terrain still shows the true crater floor.
  4. Applies the body's air. βR, βM, the shell and the ground albedo, with Earth's values as the fallback, re-applied every frame so that leaving Mars resets the sky to blue.
  5. Fades the haze with altitude. Aerial perspective's opacity cap and the height fog are multiplied by 1 − smoothstep(50 km, 150 km, altitude), and by the body's aerialStrength.
  6. Feeds the star pass. Altitude, local up, the real sun, and the planet's center and radius so stars never draw over the globe; the dome's own procedural stars are hidden.

The lit globe and the grazing hand-off

Where a view ray hits the ground sphere, flag bit 3 makes the dome shade a planet surface there: procedural continents for Earth, or, when the real-imagery layers are bound, an equirectangular day photo with night lights fading in across the terminator; flat albedo with a little noise for Mars; gray for the Moon. Sunlight on it passes through the slant transmittance, and the result is composited with the standard aerial form surface·T + in-scatter, which produces the blue limb haze from orbit at no extra cost. Streamed tiles drawn later overwrite it, so it only shows in the unstreamed gap beyond the tiles and at the limb. Rays that strike the globe at grazing incidence (cos between 0.02 and 0.12) are blended toward the horizon sky color, so the last sliver of painted globe melts into the glow the way real distant terrain does rather than ending in a flat, off-color band.

The limb from outside

Seen from orbit, single scattering produces the lit shell correctly but thinly. The dome adds an explicit limb glow, parameterized by the ray's angle off the direction to the planet's center, so it is altitude-correct and is exactly zero when looking away from the planet.

camera, r = |ro| limb_a = asin(re/r) s = 0 s = 1 horizon dip planet re, shell ra (shell thickness exaggerated) s = (angle − limb_a) / shell_a
The limb glow's coordinate s is 0 at the ray that grazes the surface and 1 at the ray that grazes the top of the shell; negative values are over the solid disk.
src/shaders/atmosphere.wgsl · limb glow (trimmed)WGSL
let glow_alt = smoothstep(30000.0, 120000.0, cam_alt);      // ground views untouched
let ang     = acos(clamp(dot(rd, -ro / R), -1.0, 1.0));
let limb_a  = asin(clamp(atm.r_e / R, 0.0, 1.0));
let shell_a = asin(clamp(atm.r_a / R, 0.0, 1.0)) - limb_a;
let s = (ang - limb_a) / max(shell_a, 1e-5);
let ring  = smoothstep(-0.2, 0.05, s);                 // suppress over the disk
let rim   = exp(-s * s * 3.5);                            // thin bright band
let broad = exp(-max(s, 0.0) * 0.5);                     // wide glow into space
// Tint from the body's own Rayleigh coefficients: Earth's blue, Mars' rust.
let tint = atm.beta_r / max(max(atm.beta_r.x, atm.beta_r.y), max(atm.beta_r.z, 1e-9));

The glow is lit only on the sunlit side of the limb, brightens toward the sun with a μ8 forward-scatter crescent, and its color comes from normalizing the body's βR: Earth's (5.5, 13, 22.4) gives the blue rim, Mars' red-first coefficients a rust one, with no per-body color constant.

The Great Lakes and the US northeast from 400 km, with a bright pale-blue band along the curved horizon fading into a darker blue sky.400 km: the limb fills the top of the view
North America and Greenland from 3,000 km, with a thin glowing blue rim around the planet against black space and stars.3,000 km: a thin rim, stars at full brightness

Above about 45 km the star pass is at full brightness: its visibility ramps with the camera's progress through the shell, from 12% (about 7 km) to 75% (about 45 km), independent of time of day. The haze has faded out by 150 km. Everything else from orbit, the real-imagery globe, city lights, the Moon and Mars as bodies you can fly to, is covered in Space, stars and other worlds.

Distance

Aerial perspective

src/renderer/render_graph/passes/aerial_volume_pass.ts · src/shaders/aerial_volume.wgsl · src/shaders/modules/aerial_perspective.wgsl · src/renderer/features/deferred_lighting_feature.ts · src/geo/geo_sky.ts (makeAerialParams)

Light from a distant surface is dimmed by the air in front of it, and sunlight scattered by that air is added. For a surface color C at distance d: C′ = C·T(d) + Lin(d). In Taos this is applied at the very end of the deferred lighting shader to every lit pixel. The two terms come from a froxel volume computed once per frame.

The froxel volume

AerialVolumePass is a compute pass that writes two 32×32×32 rgba16float 3D textures: in-scattered luminance and per-channel transmittance. Each of the 32×32 threads marches one camera ray outward through the 32 depth slices, storing the running totals at each. Transmittance is stored per channel rather than as one gray value, so distant terrain reddens as well as fades. Slice s's texel center sits at distance ((s + ½)/32)² · volumeMaxDist, where volumeMaxDist defaults to 128 km; consumers sample with w = √(d/128 km), which lands exactly on those centers.

camera 0 30 km (slice 15) 75 km (slice 24) 124 km 128 km = volumeMaxDist slices 0–3: 31 m, 281 m, 781 m, 1.5 km
Squared-depth slicing, drawn on a linear axis. Half the slices lie within the first 30 km, where the eye can tell haze differences apart.

Each slice segment is integrated with two sub-steps. At each sub-step the march computes the altitude (radial in planet mode, with samples under the datum clamped onto it), the sun's optical depth with a 4-sample march, and a source term; then it uses the energy-conserving analytic segment integral from Hillaire's 2015 volumetrics course, which is exact for a segment of constant source and extinction:

Per-segment integration in the froxel march
L += T · S − S e−σeΔtσe     T *= e−σeΔt
S = Esun Tsun · day · (PR σs,R + PM σs,M) + 0.1 · Esun Ψms (σs,R + σs,M) · gate
  • σevery coefficient is multiplied by fogScale (see below)
  • daysmoothstep(−0.1, 0.1, sun · up): sunlight in the haze is gated off below the local horizon
  • 0.1AERIAL_MS_WEIGHT: the dome adds multiple scattering once per pixel, the march along the whole path; at full weight kilometers of haze come out brighter than the horizon behind them and distant ridges glow white

The composite

ap_apply, shared by the deferred shader and the forward+ shaders (plain forward surfaces use a simpler tap of the same volume), turns two texture taps into the final color in four steps.

src/shaders/modules/aerial_perspective.wgsl · ap_apply (trimmed)WGSL
let w     = sqrt(saturate(dist / max(atm.volumeMaxDist, 1.0)));
let vol_L = textureSampleLevel(vol_l, vol_samp, vec3<f32>(uv, w), 0.0).rgb;
let vol_T = textureSampleLevel(vol_t, vol_samp, vec3<f32>(uv, w), 0.0).rgb;
// 1. Opacity cap. Scale the in-scatter by the same fraction, or capped pixels
//    get full-strength haze ON TOP of the preserved surface and wash white.
let geo_T = max(vol_T, vec3<f32>(1.0 - atm.maxOpacity));
let cap   = min((1.0 - geo_T) / max(1.0 - vol_T, vec3<f32>(1e-4)), vec3<f32>(1.0));
// 2. Sky convergence: thick haze tends to the sky color in the ray's horizontal
//    azimuth, from the dome's own sky-view table, lifted by multiple scattering.
let inscatter = mix(vol_L * cap, sky_color * (1.0 - geo_T),
                    (1.0 - clamp(gT, 0.0, 1.0)) * horizonness * conv_gate);
// 3. Aerial composite.
let aerial_out = geo_color * geo_T + inscatter;
// 4. Analytic height fog over the top, in-scattering the same sky color.
let fog_tr = ap_height_fog_t(atm, fog_vcoord, fog_vrate, dist);
return aerial_out * fog_tr + sky_color * atm.fogColor * (1.0 - fog_tr);

The convergence step is what makes far geometry meet the sky without a seam. The volume is a near-field tool (it ends at 128 km and sees the scene at 32×32 screen resolution), while the dome behind the terrain is a separate integral. Blending the haze toward the dome's exact horizon color, sampled from the very same sky-view table with the same mapping (mode 2 when the altitude-horizon flag is on), by the haze's opacity, makes a distant ridge become the sky as its haze thickens. Looking straight down, the ray's horizontal azimuth is undefined, so the blend fades out (horizonness) as the ray turns vertical.

The real sun, even at night

Explorer's key light is not always the sun. After sunset it becomes moonlight, coming from wherever the Moon is (see Lighting). If the haze used the key light it would be lit by the Moon, at full strength, after dark. The lighting feature takes a separate direction for the haze:

explorer/main.ts · DeferredLightingFeature optionsTypeScript
// Aerial scattering must track the REAL sun: the key light swaps to moonlight
// at night, so without this the haze would be lit by the moon. Feeding the
// real toward-sun vector lets the haze fade out through twilight to nothing
// after sunset.
aerialSunDirection: () => { const d = realSun.worldDirection(); return { x: -d.x, y: -d.y, z: -d.z }; },

The same "real sun" holder drives the dome and the sky probe. The fade itself is the day factor in the march (gone by sin⁻¹(−0.1) ≈ −5.7°) plus the convergence and multiple-scattering gates, which close by −1.1°.

Below-horizon guards

Around sunset, three terms of the march can leak sunlight that the sun, now below the horizon, no longer provides. Left unguarded, together they paint a pale white glow on mid-distance water, centered on the sun's azimuth, with blocky froxel edges. Each has its own guard:

fogScale, and the washed-out city

Every coefficient in the volume is multiplied by fogScale, a density multiplier that exists for game-scale scenes, hundreds of meters across, where physical haze is invisible. The engine default is 80. The shared helper makeAerialParams defaults to 8. Explorer passes 1.5:

explorer/main.tsTypeScript
// fogScale 1.5: … 1 is physical clear air; 1.5
// reads as a light summer haze on the far skyline with crisp near facades.
const aerialParams = makeAerialParams({ fogDensity: effects.fogDensity, fogHeight: effects.fogHeight, fogScale: 1.5 });
aerialParams.maxOpacity = effects.hazeOpacity;   // 0.85

The sea-level extinction is (βR + 1.1βM)·fogScale. With Explorer's Earth air (βM = 12×10⁻⁶, applied to the haze by CurvedHorizonSky) that is a 1/e distance of 36, 25 and 19 km in red, green and blue. At the shared default fogScale of 8 with the reference βM it is 3.5 km in green: the haze saturates within 2–3 km and everything past a few kilometers turns to milk. That is a density problem, and lowering the haze opacity cap only hides it; the cap sits at 0.85, where it only matters for views beyond about 50 km. With a haze from the weather it rises to 1 as the haze thickens (between 30×10⁻⁶ and 200×10⁻⁶ m⁻¹), so hills past a hazy day's visibility meet the sky without a seam.

Cape Town from above Table Mountain with no haze: the bay is a flat saturated blue and the far shore looks pasted onto the sky. The same view with aerial perspective: the bay pales with distance and the far shore fades into the horizon sky.
haze offhaze on (fogScale 1.5)

Cape Town from above Table Mountain. Drag across the image. Without haze the bay is a flat, saturated blue and the far shore sits on the sky like a cut-out; with it, the water pales with distance and the coast dissolves into the horizon.

The same Cape Town view with fogScale 8: the city, the bay and Lion's Head are washed into a pale milky veil a few kilometers out.
fogScale 8. The same frame with makeAerialParams' shared default: the air is eight times thicker than physical, and the city, the bay and Lion's Head vanish into a milky veil a few kilometers out.
Still mismatched

The haze is lit with sunIntensity: 20, the dome's value, while Explorer's scene sun has intensity 5. At ground level the opacity cap hides the difference. Making the haze physical from orbit (analytic slant-path extinction, ramping fogScale, the cap and the sun intensity to physical values with altitude) looks worse at every altitude band when flown, so the haze from orbit is simply faded out between 50 and 150 km.

AtmosphereHaze

Haze from the weather: one profile for every march

src/shaders/modules/haze_profile.wgsl · src/renderer/render_graph/passes/atmosphere_haze.ts · src/shaders/modules/atmosphere_model.wgsl (hazeMsPath) · src/shaders/aerial_volume.wgsl · explorer/lib/weather/haze.ts, haze_view.ts, haze_field.ts

With a haze set, the Mie density stops being the 1.2 km exponential above. It becomes a boundary layer under a lid, plus a thin free-troposphere haze over it: density(h) = 1/(1 + e(h − top)/edge) + ft·e−h/Hft. The AtmosphereHaze record (top, edge, ftRatio, ftScale, per-channel scattering and extinction, and g) is written into each consumer's uniform by writeHaze. A top of 0 keeps the exponential, so a scene that sets no haze looks as before. The same haze_profile.wgsl is imported by the transmittance and multi-scatter bakes, the sky-view and skylight bakes, the dome, the froxel volume and the clouds' far haze, so terrain, sky, sea and clouds see one haze. The logistic integrates to a softplus, so a march step kilometers long that crosses the lid takes the mean density over the step (haze_density_avg) rather than a point sample that could skip it.

Weather

Fog and weather: a closed-form layer

src/shaders/modules/aerial_perspective.wgsl (ap_height_fog_t) · explorer/main.ts (updateWeather, smoke) · explorer/lib/weather/weather.ts · explorer/lib/weather/metar.ts

Fog is not part of the froxel volume. It is an analytic layer applied over the aerial result, with a density that is uniform below a plane and decays exponentially above it. Along a ray the optical depth has a closed form, so it costs a few instructions per pixel and has no resolution limit, which matters for a layer a few hundred meters thick seen from a cockpit.

Height fog (ap_height_fog_t)
ρ(y) = ρ0 · e−k·max(y − yf, 0)
τ = ρ0 [ e−k a0 − e−k a1k r + min(h1,0) − min(h0,0)r ],   Tfog = e−min(τ, 32)
  • h₀, h₁height of the ray's ends relative to the fog plane yf; a = max(h, 0)
  • rvertical rate of the ray: dir·up (radial up and altitude in planet mode)
  • ρ₀, kfogDensity and fogFalloff; a level ray uses d·e−k a0

The density is uniform below the plane because a pure exponential keeps growing there: a camera or a surface a few hundred meters under the plane (a valley, the sea beside high ground, or terrain that a straight ray reaches below the curved horizon) would see ek·depth times the density and wash to flat fog color a few meters away. With the clause every exponent is ≤ 0. The optical depth is also clamped to 32 before the exponential, which keeps not-a-number pixels out at planetary distances.

The fog's in-scatter is the same horizon sky color the haze converges to, times a tint. That keeps fog in the color of the sky behind it rather than a flat gray. For weather, the tint is [0.85, 0.97, 1.12], pulling the warm horizon color back toward the gray-white of water droplets.

Where the density comes from

Explorer's weather system blends between named states, and each carries a fog density. Each frame the blended density, the local ground elevation as the fog plane, and a falloff of 0.008 m⁻¹ (the layer thins over about 125 m) are pushed to the lighting pass. Fog switches the aerial path on even when the player has turned aerial haze off, because the fog is part of it.

Weather statefogDensity (m⁻¹)Distance to 5% contrast (3/ρ₀)
clear through overcast, showers0—
light rain0.000215 km
heavy rain0.00065 km
thunderstorm0.00083.75 km
snow0.00122.5 km
light fog0.0021.5 km
dense fog0.012250 m

When the weather comes from real observations, the METAR and Open-Meteo readers turn the reported visibility V into a density with min(0.015, 3 / V) for V under 9 km. That is the meteorological visibility rule inverted: at distance V along a level ray inside the layer, T = e−3 ≈ 5%, the contrast threshold at which an object is no longer seen. Inside wildfire smoke the same path is reused with a density up to 0.03 m⁻¹ and the fog plane 150 m above the camera. Rain, snow and the rest of the weather are the subject of Rain, snow and wet weather.

GodrayFeature

God rays: shafts through shadows

src/renderer/features/godray_feature.ts · src/renderer/render_graph/passes/godray_pass.ts · src/shaders/godray_march.wgsl · src/shaders/godray_composite.wgsl · src/shaders/modules/cloud_shadow.wgsl · explorer/main.ts

The froxel volume's 32×32 screen resolution cannot resolve the edge of a building's shadow, so light shafts are a separate effect. GodrayFeature runs after deferred lighting. It marches every pixel's view ray from the camera to the depth buffer at half resolution, asking at each step whether the sun is visible:

src/shaders/godray_march.wgsl · fs_march (trimmed)WGSL
let steps    = u32(march_params.max_steps);                 // 32 in Explorer
let step_len = ray_len / f32(steps);
var pos      = camera.position + ray_dir * dither(in.uv) * step_len;
let phase    = henyey_greenstein(dot(ray_dir, sun_dir), march_params.scattering);  // g = 0.55
var accum = vec4<f32>(0.0);
for (var i = 0u; i < steps; i++) {
  let st    = shadow_and_tint(pos);                            // sun shadow map (+ stained-glass tint)
  let trans = cloud_shadow_lookup(pos, cloud_shadow_lut, lut_samp, lut_params);
  let s     = phase * st.a * trans;
  accum += vec4<f32>(st.rgb * s, s);
  pos   += ray_dir * step_len;
}
return clamp(accum / f32(steps), vec4<f32>(0.0), vec4<f32>(1.0));

The result is the fraction of the ray, weighted by the phase function, that sees the sun. Two occluders feed it. The sun shadow map, with the same clipmap-level selection as the lighting pass (see Shadows), carves shafts around buildings and ridges; the page-virtualized shadow path is skipped because the march does not bind its page table. A 2D top-down cloud transmittance table carves them under clouds, with one bilinear fetch per step in place of a vertical integration through cloud noise. The half-resolution result goes through a depth-aware bilateral blur, horizontal then vertical with 7 taps, and is upsampled by picking the half-resolution neighbor whose depth best matches each full-resolution pixel, then added to the HDR image as fog2 × key-light color × intensity, faded by smoothstep(−0.05, 0.05) on the key light's height.

Henyey–Greenstein, for the shafts
PHG(μ) = 14π 1 − g²(1 + g² − 2gμ)3/2,   g = 0.55
  • gsofter than the sky's 0.758: shafts stay visible well away from the sun, with a forward/back ratio of about 40

Phantom shafts

The procedural cloud-shadow table is baked from a cloud-density description with its own coverage. When the player turns the clouds off, that description still says coverage 0.65, and the shafts would be cut by an invisible cloud deck: bright and dark bands across a clear sky, matching nothing on screen. So Explorer passes a provider that zeroes coverage and density whenever clouds are not rendered, and buildings shadow the shafts only through the sun shadow map, which needs sun shadows on.

explorer/main.ts · GodrayFeatureTypeScript
const godrayFeature = new GodrayFeature({
  noises: cloudNoises,
  // Only let the cloud deck shadow the shafts when clouds are actually being
  // rendered — otherwise the invisible coverage-0.65 layer throws phantom shafts.
  cloudSettings: () => cloudsWanted() ? cloudSettings : { ...cloudSettings, coverage: 0, density: 0 },
  // Shadow the shafts with the HQ clouds ACTUALLY ON SCREEN: bake the ground
  // table from their Beer Shadow Map.
  groundShadowLut: (graph, lutParams, res) => (cloudsWanted() && cloudFeature.enabled && hqSettings.beerShadow)
    ? (cloudFeature.pass?.addGroundShadowLutToGraph(graph, lutParams, res) ?? null)
    : null,
  maxSteps: 32,
  scattering: 0.55,
});

The second option matters more. The procedural table samples its own cloud density field, not the one the HQ clouds draw, so even with clouds on, its shaft shadows do not line up with the visible deck. When the HQ clouds are on with their Beer shadow map, the clouds bake the top-down table from that shadow map, in the same convention, and the shafts are cut by the clouds you see. The procedural bake remains as the fallback.

The vertical seam

The top-down table is a camera-centered square, 1,200 m wide at 256² by default. Sky rays leave it quickly. Clamping those lookups to the edge texel, which under dense cloud is dark, would project the rectangle's edge as a near-vertical line across the sky, so lookups outside the square fade to unshadowed over its outer 10% (saturate(m / 0.1) in cloud_shadow.wgsl).

There are two kinds of light shaft in Explorer. These scene god rays are on in the High and Ultra graphics presets and off in Low and Medium. Separately, the HQ clouds march their own shafts against the Beer shadow map, with a strength of CLOUD_GODRAY_STRENGTH = 0.6 when the Cloud god rays setting is on, "modest so clear sky stays haze-free". Those are part of the cloud renderer (see Volumetric clouds).

Sunset

Day, twilight and night: every gate

src/shaders/atmosphere.wgsl · src/shaders/aerial_volume.wgsl · src/shaders/modules/aerial_perspective.wgsl · src/geo/geo_sky.ts · explorer/main.ts (applySun, buildProbeLighting)

Explorer's clock computes the real sun for the place and the UTC instant. From that single direction, a sunset passes through a sequence of independent fades, each placed where its own physics breaks down. They are all functions of the sine of the sun's elevation relative to the local up, s = sun·up.

GateFormula in sFades betweenControls
real sun intensityclamp(s / 0.25)+14.5° → 0°scene sun brightness; key light switches to the Moon at 0°
MS + convergencesmoothstep(−0.02, 0.08, s)+4.6° → −1.1°haze multiple scattering and sky convergence
haze sunlightsmoothstep(−0.1, 0.1, s)+5.7° → −5.7°single-scattered sun in the froxel march
sky_tsat((s + 0.12) / 0.12)0° → −6.9°dome scattering, sun disk and halo, haze convergence color
night_tsat((−s − 0.05) · 10)−2.9° → −8.6°star visibility near the ground (painted moon in flat scenes)
Interactive · the sunset gates
Each curve is computed from the shader's formula at the cursor. Drag the sun down and watch the order: the haze's multiple scattering and convergence close first, at about −1°, so the near air stops borrowing light from the sunlit horizon; the haze's own sunlight goes by −5.7°; the dome's scattering by −6.9°; stars reach full brightness by −8.6°.

The order matters. The haze gates close before sky_t because the air near the camera falls into the Earth's shadow before the distant air on the horizon does; a dusk landscape lit by the still-bright horizon color looks like it is lit from nowhere. The dome's fade outlasts both because the sky really does keep a glow for several degrees. The stars cross over with the dome so that there is never a moment of starless black or of stars on a bright sky; the star pass also dissolves them into any remaining sky brightness with its skyExtinction of 6.

Lower Manhattan from the air by day: neutral daylight, the far shore of New Jersey softened by blue haze.New York, day
The same view at dusk: warm low light, the haze toward the horizon taking on the sunset color.dusk
The same view at night: blue-gray moonlit buildings, the haze gone.night

The same camera through a sunset. By day the far shore is softened by blue haze. At dusk the haze toward the horizon picks up the warm sky color. At night the haze has gone dark with the real sun, and the cool light on the buildings is the Moon's key light and the sky probe's night floor.

What stays lit at night

The visible sky goes almost black after sky_t closes, but the ground must not. The ambient light on the ground comes from a sky reflection probe, not the atmosphere pass, and its procedural sky carries a cool-blue night "airglow" floor that fades in as the sun sinks; without it, a moonless night would leave the land pitch black. That probe and the moonlit key light belong to Lighting. The other half of the night look is exposure: the auto-exposure ceiling eases from 4.0 by day to 0.5 at night, so the dark is rendered dark rather than metered back up to gray (see Motion, antialiasing and the lens).

Everest at noon: a white sun high in a deep blue sky with a bright halo, and a lens streak across the frame.Everest, noon: the disk, the flare halo, a lens streak
Everest after dusk: a dark violet sky full of stars over a faint red band low in the sky.after dusk: stars over the last red band

High on the mountain the air above is thin, so the noon sky is a deep blue around the sun's wide halo. After dusk the sky has faded to violet with a dull red band at the horizon, and the stars are out.

Budget

Cost and open ends

explorer/docs/index.html (pass timings) · source comments

The Taos Explorer guide publishes per-pass GPU times measured with the engine's timestamp profiler in Chrome at 1280×720 on a desktop GPU, for a view over New York at 700 m and one of Cape Town with clouds. The atmosphere's share:

#PassNew York (ms)Cape Town (ms)
1AtmospherePass0.4450.321
2AtmospherePass.skyViewBake0.0580.057
3AerialVolumePass0.0700.071
4GodrayPass (march + blur + composite)0.1300.120
5CloudShadowLutPass0.0230.018

The 20,736-texel sky-view bake costs about an eighth of the dome draw. The dome is the larger number even with the table because the table only replaces the scattering integral: the dome still evaluates, per sky pixel, an 8-step transmittance march toward the sun for the disk and halo, another toward the moon, and, where rays hit the planet sphere, two more for the painted globe. Whole-frame time was 3.44 ms in both views, so these passes are a sixth to a fifth of it.

Things the code shows are not finished:

Further reading

References

  1. T. Nishita, T. Sirai, K. Tadamura, E. Nakamae, “Display of the Earth Taking into Account Atmospheric Scattering”, SIGGRAPH 1993. The single-scattering formulation with exponential density and a planet-scale ray march that scatterP follows.
  2. A. J. Preetham, P. Shirley, B. Smits, “A Practical Analytic Model for Daylight”, SIGGRAPH 1999. Cited in the model's header; the source of the aerial-perspective framing of in-scatter plus extinction.
  3. E. Bruneton, F. Neyret, “Precomputed Atmospheric Scattering”, EGSR 2008. The 4D-table alternative, considered and declined in favor of the altitude-horizon sky-view mapping for the orbital limb.
  4. S. Hillaire, “A Scalable and Production Ready Sky and Atmosphere Rendering Technique”, EGSR 2020. Transmittance, multiple-scattering and sky-view tables, the 1/(1 − fms) series, the ground term, and the camera froxel volume.
  5. S. Hillaire, “Physically Based and Unified Volumetric Rendering”, SIGGRAPH 2015 course (Advances in Real-Time Rendering). The energy-conserving analytic segment integration used in the froxel march and the multiple-scattering bake.
  6. W. M. Cornette, J. G. Shanks, “Physically Reasonable Analytic Expression for the Single-Scattering Phase Function”, Applied Optics 31(16), 1992. The Mie phase function, g = 0.758.
  7. L. G. Henyey, J. L. Greenstein, “Diffuse Radiation in the Galaxy”, Astrophysical Journal 93, 1941. The phase function of the god-ray march.
  8. M. Oren, S. K. Nayar, “Generalization of Lambert's Reflectance Model”, SIGGRAPH 1994. The rough-ground factor in the sky's ground-bounce term.
  9. World Meteorological Organization, Guide to Instruments and Methods of Observation (meteorological optical range). The 5% contrast threshold behind the 3 / visibility fog density.