garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/two-tiers-one-sphere.md

raw


triggers:


Two tiers, one sphere: what the world looks like between 2 km and 50 km

The client has a flat tier (the streamed clipmap around the map anchor, in a tangent frame measured in metres) and a globe tier (a quadtree of ellipsoid tile patches). Until 2026-08-24 they were alternatives, switched at GLOBE_SHOW_ALT = 50 km. They are now layers: the flat tier owns the near ground at every altitude, the globe fills in past it from GLOBE_DRAW_ALT = 2 km, and the flat tier's tiles are bent onto the globe's own sphere so the two meet without a step.

What was wrong, and the measurement that says so

Three constants had to agree and did not:

reach
flat clipmap (7×7 z10 ring at lat 53)±82 km
ground skirt (GROUND_DISC_RADIUS)150 km
true horizon from 12 km altitude391 km
camera far plane below the space tier200 km

So between roughly 5 km and 50 km the view was: map out to 82 km, then blank paper to 150 km, then nothing. GLOBE_SHOW_ALT's own doc comment claimed "below it the detailed flat-tile city view fully covers the sky-facing hemisphere", which is true at 2 km and false by 10.

Two things made it worse than the geometry alone. The skirt renders brown, not paper — see the aerial-perspective section below. And the horizon-haze shell that exists to cover exactly that band turns itself off above 5 km: fog_altitude_factor smoothsteps to zero by FOG_FADE_HIGH = 5 km, so peak is 0 and sky.rs hides the shell. The cover disappears precisely where the defect appears.

Reproduced headlessly at Groningen, 12 km, looking north (--shot, 2026-08-24): hard straight map edge partway up the frame, a brown band above it, flat rim, sky. Identical to the phone screenshots that reported it.

Why the flat tier is curved rather than the globe being brought closer

setup_globe builds the sphere in the anchor's tangent frame with the anchor exactly on its surface at the local origin. So the flat tier's y = 0 plane is that sphere's tangent plane, and y = -GlobeState::drop_at(d) is not an approximation of the globe — it is the globe, evaluated in the frame the basemap is already placed in. That is the whole reason a handoff is possible at all: had the two been built in unrelated frames there would be no way to make them meet.

Every ground tile therefore takes the drop at its own centre in its transform and carries the remainder across itself in vertices. Consequences worth knowing:

Numbers: 0.08 m of drop at 1 km, 7.8 m at 10 km, 528 m at the clipmap's 82 km edge, 1,764 m at the skirt's 150 km rim.

What this costs, and the errors that are being accepted

Aerial perspective past 32 km needs the raymarched atmosphere

render_sky.wgsl composites a geometry pixel as scene x transmittance(t) + inscattering(t). In LookupTexture mode the transmittance uses the true distance while the in-scattering is clamped at aerial_view_lut_max_distance (32 km), so ground past that is extincted without the airlight that should replace it — and since blue scatters out first, what remains is red. That is what made the old ground skirt brown, and once the globe carries the view to a 391 km horizon it is 300 km of real map with a magenta cast.

Raymarched takes both terms from one integral over the true distance with no clamp, so the switch moved from GLOBE_SHOW_ALT to GLOBE_DRAW_ALT. This is a correctness fix, not a quality setting: the far ground now washes toward the sky the way aerial perspective does.

Raising aerial_view_lut_max_distance instead was rejected. It stretches the same 32 slices over a longer range, so buying the horizon costs the near field its accuracy — an earlier session recorded it as "does not work", which is the same finding seen from the near end.

Two things this does not reach. A handset that fails space_raymarch keeps LookupTexture and the magenta with it, which is what it renders today anyway; and the other handset path (no FLOAT32_FILTERABLE, so SkyMode::Dome) has no Bevy atmosphere at all and never had the artefact — which is how the cause was isolated, since the same viewpoint captured on the dome path was already clean.

Below GLOBE_DRAW_ALT nothing changed, and the step at the threshold is masked because DistanceFog is still at ~46 % strength at 3 km. That fog is the dominant haze at low altitude and it was tuned against a clamped atmosphere; if it is ever revisited, it is now compounding with a correct one.

Everything that stands between the ground and the far plane had to move

The far plane, the sky-dome shell and the star/moon shells were all sized against "the world ends at the 150 km skirt". They are now sized against free_camera::horizon_distance_m, and the ordering they must keep is:

horizon  <  sky shells  <  far plane

Getting the middle one wrong is invisible on a desktop, because the sky-dome shell is the phone's sky (SkyMode::Dome, an adapter with no FLOAT32_FILTERABLE). A shell left at 160 km while the ground runs to 391 km paints over the far half of the view. sky_dome's test asserts the ordering at four altitudes; CARTO_SKY_DOME=1 forces the path anywhere.

The far plane's margin is 1.5×, not a hair over 1.0, because the Earth's silhouette is drawn by the far edges of the tiles that straddle the horizon — z9 tiles ~70 km across at 12 km altitude. At 1.2× the skyline came out as a sawtooth: the tile grid, clipped one tile at a time.

Both overrides (this band's, and the space tier's far-limb plane) live in free_camera::camera_controls after the camera-mode match, so they hold in every mode; the system resets near/far to the ground defaults (0.1 m, 200 km) at the top of every frame. They used to sit in the Orbit arm alone, so climbing in Fly or Follow left the far plane at 200 km and clipped the whole planet to a black screen.

Still open