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 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.
| Constituent | Coefficient (per m) | Density profile | Phase |
|---|---|---|---|
| Rayleigh (molecules) | βR = (5.5, 13.0, 22.4)×10⁻⁶ | e−h/8500 | 3/(16π)·(1+μ²) |
| Mie (aerosols) | βM = 21×10⁻⁶ scattering, ×1.1 extinction | e−h/1200 | Cornette–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 km | none (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.
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⁻⁶ | Shell | Aerial haze | Notes |
|---|---|---|---|---|---|
| Earth (reference) | 5.5, 13.0, 22.4 | 21 | 60 km | full | engine default |
Earth in Explorer (EARTH_AIR) | 5.882, 12.292, 27.500 | from the weather (12 before the first) | 60 km | full | Rayleigh 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, 6 | 9 | 80 km | aerialStrength: 0 | red-dominant "Rayleigh"; tuned by eye, not physical |
| Moon | (unchanged) | 500 m | off | hasAtmosphere: 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.
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.
- 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
- Esun
sun_intensity, 20 in the renderer's HDR units - T(p, sun)0 when the planet blocks the sun from p
- g0.758 everywhere the air is shaded (dome, bakes, froxel march:
GandAP_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:
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:
// 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.
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.
| Table | Size, format | Axes | Bake cost per texel | Re-baked |
|---|---|---|---|---|
| Transmittance | 256×64 rgba16float | u: cos zenith (sqrt warp), v: altitude 0–60 km (linear) | one 8-step optical-depth march | when a parameter changes |
| Multiple scattering | 32×32 rgba16float | u: cos sun zenith (same warp), v: altitude | 16 directions × 16 steps | whenever transmittance is |
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.
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:
- 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.
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 HQ clouds read the transmittance table to redden and dim the sunlight
reaching each cloud sample (
useTransmittanceLut: true), the source of the deep amber undersides at sunset (see Volumetric clouds). - The aerial froxel volume adds the multiple-scattering term as an isotropic source at every march sample.
- The haze composite lifts its sky-convergence color by the same term so that distant geometry fades to the brightness the sky actually has.
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.
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.
| # | Pass | Writes | When |
|---|---|---|---|
| 1 | AtmospherePass.skyViewBake | 192×108 rgba16float, transient | every frame (depends on the sun and the camera altitude) |
| 2 | AtmospherePass.skylightBake | 2×1 rgba16float, persistent | only when its quantized inputs change |
| 3 | AtmospherePass | the HDR target | every 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:
- φ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.
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.
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:
- camera radiusto 10 m; the integral depends on altitude, which varies on a 100 km scale
- local upto 1/1000 per component, about 0.06°, or roughly 6 km of travel over the Earth
- sun directionto about 0.06°
- parametersexactly (all 20 floats of the block)
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.
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:
- 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
| Bit | Meaning | Explorer |
|---|---|---|
| 0 | ozone absorption | on |
| 1 | horizonless sky (no ground clip, no planet shadow) | off |
| 2 | explicit moon phase instead of the geometric one | off: lit by the real sun |
| 3 | lit planet surface where rays strike the ground sphere | on with the curved horizon |
| 4 / 5 | hide the painted moon / only its disk | per body and streamed-Moon state |
| 6 | painted moon visible by day | on |
| 7 | altitude-horizon sky-view mapping | on (pinned) |
| 8 | Earth-style procedural continents on the lit globe | Earth only |
| 9 | hide the built-in procedural stars | on with the curved horizon (a separate star pass draws them) |
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.
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.
- 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.
- 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).heightfor Earth, a constant for the Moon, and a biaxial spheroid formula for Mars. - 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. - 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.
- 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. - 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.
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.
400 km: the limb fills the top of the view
3,000 km: a thin rim, stars at full brightnessAbove 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.
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.
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:
- σ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.1
AERIAL_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.
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:
// 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:
- The sun optical-depth guard is
tg.x > 0.0 || (tg.y > 0.0 && dot(pos, dir) <= 0.0), not justtg.x > 0(the planet ahead of the sample). The march clamps below-datum samples onto the surface exactly, where the entry root is 0, not positive. With the simpler test the optical-depth loop would break on its first sample, inside the planet, and return zero depth: full, unattenuated sunlight on every clamped sample, the moment the sun sets. - The multiple-scattering table is baked from the horizonless (no planet shadow) transmittance, so its below-horizon texels stay bright. Added ungated, it would fill the volume with a white glow at dusk, so it is multiplied by smoothstep(−0.02, 0.08, sun · up).
- The convergence blend toward the horizon color carries the same gate. At twilight the near air is in the Earth's shadow while the horizon color still comes from far-off sunlit air, so blending toward it would paint the sunset band onto mid-distance geometry.
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:
// 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.
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.
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.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.
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.
- Re-bakes. The transmittance and multi-scatter tables depend on the haze, so a new haze
re-bakes them. The tables' pass compares by value (
hazeEqual), and Explorer'sHazeVieweases the haze but hands a new one over only when a value moves by 3%. A re-bake costs 0.2–0.3 ms on a desktop GPU, seconds apart at most. - Multiple scattering of the haze. A thick haze is lit mostly by light it has already
scattered. Single scattering alone turned a hazy day's distance dark brown-gray. The froxel
volume therefore adds the multi-scatter table's light to the haze's share at weight 0.35
(
AERIAL_MS_WEIGHT_MIE), against 0.1 for the air's own. The sky gets the same term fromhazeMsPath: along the view ray to the ground or to space, the haze's J(1 − T)/σe at that weight. It is baked into the sky-view table (bind group 1 is the multi-scatter table, a 1×1 dummy without a haze); the dome adds it per pixel only on its integral path. This matters because the aerial composite converges far terrain on the sky-view table's color. Without the term there, hazed hills (190 of 255) met a whiter sky (254) at a seam on the horizon. From above a haze,hazeMsHeighttakes the term at the layer's half depth, not at the camera: at cruise the haze's multiple scattering is the layer's own, and the table's horizon is not a bright band over a dark ground. - Seen from above.
ap_apply_litconverges far terrain on the sky-view color, the horizon sky at the camera's height. That holds for a camera inside the haze. From above, it painted a smoke layer the blue of the sky over it. The convergence is now weighted by the share of the view path's haze inside the first 2 km (AP_NEAR_M), against what the whole path holds: near 1 inside the haze, near 0 looking down onto a layer far below, where the march's own in-scatter gives the layer its color (gray-cream for smoke from FL350). - Varying across the view. Up to eight stations (
AerialVolumePass.hazeField) each carry a world position, an amount and a color: the logarithms of the scale and of the scattering and extinction ratios per channel, against the camera's haze (writeHazeField).av_haze_scaleblends them by inverse distance squared, softened over 10 km, in the logarithm: a geometric mean, so one very smoky station tints its own side without lifting the rest of the view. The result scales the Mie scattering and extinction of each froxel sample per channel, and the sun's Mie optical depth to it. Explorer fills the stations from the nearest report in each of seven sectors around the camera (5–150 km), with the camera's own place as station 0, each amount held to 0.01–100 and each color ratio to 0.25–4. The cloud pass takes the same field (HQCloudPass.setHazeField): its aerial term scales the haze by the field averaged at a quarter, half and three quarters of the way to the cloud. The cost is about 0.03 ms on the volume. The profile, phase and the sky behind stay the camera's. - Clouds behind a haze. The clouds' far fade normally runs at half strength
(
ATM_AERIAL_STRENGTH). With a haze set it runs at full strength, so a cloud seen through a thick haze melts into the sky behind it. At half strength it kept a dark, singly scattered veil. - The opacity cap. The
maxOpacitycap (0.85 by default, the Haze opacity setting) keeps distant ridges faintly there on a clear day. Explorer raises it to 1 as the haze thickens, between 30×10⁻⁶ and 200×10⁻⁶ m⁻¹ (about 100 to 20 km visibility), so hills past a hazy day's visibility are hidden.
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.
- 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)
- ρ₀, k
fogDensityandfogFalloff; 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 state | fogDensity (m⁻¹) | Distance to 5% contrast (3/ρ₀) |
|---|---|---|
| clear through overcast, showers | 0 | — |
| light rain | 0.0002 | 15 km |
| heavy rain | 0.0006 | 5 km |
| thunderstorm | 0.0008 | 3.75 km |
| snow | 0.0012 | 2.5 km |
| light fog | 0.002 | 1.5 km |
| dense fog | 0.012 | 250 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.
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:
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.
- 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.
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 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).
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.
| Gate | Formula in s | Fades between | Controls |
|---|---|---|---|
| real sun intensity | clamp(s / 0.25) | +14.5° → 0° | scene sun brightness; key light switches to the Moon at 0° |
| MS + convergence | smoothstep(−0.02, 0.08, s) | +4.6° → −1.1° | haze multiple scattering and sky convergence |
| haze sunlight | smoothstep(−0.1, 0.1, s) | +5.7° → −5.7° | single-scattered sun in the froxel march |
sky_t | sat((s + 0.12) / 0.12) | 0° → −6.9° | dome scattering, sun disk and halo, haze convergence color |
night_t | sat((−s − 0.05) · 10) | −2.9° → −8.6° | star visibility near the ground (painted moon in flat scenes) |
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.
New York, day
dusk
nightThe 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, noon: the disk, the flare halo, a lens streak
after dusk: stars over the last red bandHigh 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.
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:
| # | Pass | New York (ms) | Cape Town (ms) |
|---|---|---|---|
| 1 | AtmospherePass | 0.445 | 0.321 |
| 2 | AtmospherePass.skyViewBake | 0.058 | 0.057 |
| 3 | AerialVolumePass | 0.070 | 0.071 |
| 4 | GodrayPass (march + blur + composite) | 0.130 | 0.120 |
| 5 | CloudShadowLutPass | 0.023 | 0.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:
- One haze for the whole sky. The tables follow the body's air (its βR, βO, βM and haze), but there is one set of them: the haze that varies across the view (above) changes only the froxel volume, not the sky behind the terrain or the sun's color.
- Two sun intensities. The sky and haze use 20; the scene sun uses 5. The
engine has an opt-in coupling (
coupleSunIntensity) for physical-unit scenes, which Explorer does not enable because it would change every ground view. - Little multiple scattering in the dome. Explorer's dome is single scattering, ground bounce, the haze's multiple scattering (in the sky-view table) and an explicit twilight fade; the engine can add the air's own multiple scattering too, but Explorer does not turn that on.
- The haze from orbit. The froxel volume ends at 128 km; from orbit every ground pixel is beyond it, and the haze is faded out rather than computed.
References
- 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
scatterPfollows. - 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.
- 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.
- 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.
- 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.
- 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.
- L. G. Henyey, J. L. Greenstein, “Diffuse Radiation in the Galaxy”, Astrophysical Journal 93, 1941. The phase function of the god-ray march.
- M. Oren, S. K. Nayar, “Generalization of Lambert's Reflectance Model”, SIGGRAPH 1994. The rough-ground factor in the sky's ground-bounce term.
- World Meteorological Organization, Guide to Instruments and Methods of Observation
(meteorological optical range). The 5% contrast threshold behind the
3 / visibilityfog density.