Ratatoskr/scripts/ridge-bake
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Meta Vens 11313b5d74
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m13s
Ridge bake README: the bake id does not hash the material; the canyon set is approved
Finding ratatoskr-backdrop:finding:cut-cut-ridge-place-materials.s1.readme-false-bake-id-claim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 23:09:35 +01:00
..
tests Ridge bake: place ground colour is an authored material; Grand Canyon strata 2026-11-27 21:37:15 +01:00
.gitignore Ridge backdrop A+D: baked ridge planes over the live sky (Vienna) (#163) 2026-11-14 11:07:58 +00:00
export.py Ridge bake: place ground colour is an authored material; Grand Canyon strata 2026-11-27 21:37:15 +01:00
places.json Ridge bake: place ground colour is an authored material; Grand Canyon strata 2026-11-27 21:37:15 +01:00
README.md Ridge bake README: the bake id does not hash the material; the canyon set is approved 2026-11-27 23:09:35 +01:00
refusal.py ridge-bake: the baker's own Refusal(ValueError), raised at every refusal site; the fixtures catch it only 2026-11-26 00:26:18 +01:00
ridge-bake.schema.json ridge-bake: near-only card-0 tiles bind r_max at the clip they are slid at; mutate.py runs the unmutated copy first and kills only on an AssertionError 2026-11-25 03:10:04 +01:00
ridge.py Ridge bake: place ground colour is an authored material; Grand Canyon strata 2026-11-27 21:37:15 +01:00

ridge-bake

Offline baker for the ridge backdrop: it turns a Copernicus DEM into K+1 G-buffer cards per place, split by K authored seams and cut into 32 azimuth tiles round the whole 360 degree ring, plus a manifest.json (schema 3) and an index.json that the runtime reads. Each card tile is a colour WebP (albedo and coverage) and a geometry WebP (normal and log-distance). The baker is not shipped; public/ridge/ holds its output. The client owns lighting, haze and ink: no sun, haze or shadow is baked.

Run

python3 -I scripts/ridge-bake/export.py <place-id> --tiles DIR --out public/ridge/ [--work DIR] [--sheet contact.png]

Needs Python 3 with numpy, tifffile and imagecodecs. --tiles is a directory of Copernicus GLO-30 tiles (never committed); --work caches the mosaic and rays (default $TMPDIR/ridge-bake-work); --sheet writes the contact sheet at 1/4 of the ring's width (the ring composite, every card's strip alone and the depth image with every seam, the 32 tile boundaries drawn, lit by one fixed light). The bake prints r_max_m, the resident run and the worst fit error per card. python3 -I scripts/ridge-bake/export.py --write-schema rewrites ridge-bake.schema.json, which the tests pin.

Tests: RIDGE_PY=<python> RIDGE_TILES=DIR scripts/ridge-bake/tests/run.sh [test_ridge.py|mutate.py] (mutate.py re-introduces each rule's failure into a copy of the baker and fails if a test does not notice).

Tiles per preset (places.json)

Files are Copernicus_DSM_COG_10_<N|S>dd_00_<E|W>ddd_00_DEM.tif; the list below is <N|S>dd<E|W>ddd.

place id tiles
vienna N47E015 N47E016 N47E017 N48E015 N48E016 N48E017 N49E015 N49E016
matterhorn N45E007 N45E008 N46E007 N46E008
fuji N34E138 N34E139 N35E137 N35E138 N35E139
halfdome N37W121 N37W120 N38W120
grandcanyon N35W113 N35W112 N36W113 N36W112
amadablam N27E086 N27E087 N28E086 N28E087
trecime N46E011 N46E012

Where the bakes ran

Yggdrasil (16 cores, 62 GB), as mind-void-self, work under /var/tmp/ridge-bake (never /tmp, a 31 GB tmpfs): venv/ (python 3.13 with numpy, tifffile, imagecodecs from PyPI), tiles/, work/<place>/, one out/<place>/ per place until its look is accepted. Tiles come from the public Copernicus DEM GLO-30 AWS Open Data bucket: https://copernicus-dem-30m.s3.amazonaws.com/<name>/<name>.tif with <name> = Copernicus_DSM_COG_10_<N|S>dd_00_<E|W>ddd_00_DEM (17 tiles, 598 MB).

The authored splits sit in depth gaps found by scanning candidate lists (seam medians printed per list): seams flees a split that falls inside a continuous mass of visible terrain to the nearest gap, so a split inside the mass yields an empty card 0 (Matterhorn's visible terrain is one mass from 4.9 to 15 km; gaps at 19, 28 and 43 km). Place splits at the gap medians the scan reports.

Cards

places.json gives each preset card_split_km, an ordered list of 1 to 5 seam depths in km, and optionally prefilter_m. A preset without card_split_km is refused, and so is a split that leaves a card empty (the message names the splits); K splits make K+1 cards, at most MAX_CARDS = 6 per place. New places get a seam probe look before their first bake.

  1. March. stage0 marches 6400 azimuth columns of rays over the DEM with Earth curvature and refraction (ridge.elev), cached by a key of its inputs.
  2. Low-pass. prefilter blurs the sampled heights with a Gaussian of prefilter_m metres along each ray and across rays at equal distance (sigma = prefilter_m / (distance x column width) columns), then recomputes the angles. Roofs go, hills stay.
  3. View. set_view maps angle to row linearly: the highest skyline angle of the whole ring sits at 4% of the frame height, the lowest at 66%, and the horizon keeps GROUND_ROWS_MIN = 150 rows under it (the runtime's groundRowsNeeded: (1 - 0.85) x 600 / 0.6, so the plane reaches the bottom of every viewport at rest). The scale is the lesser of the two fits, clamped to 0.5x to 10x vertical exaggeration (rulings ridge-ring-vertical-anchors, ridge-ground-rows-below-horizon: every azimuth sits inside one frame; a place whose whole-ring relief leaves too few ground rows is flattened below 1x); a skyline that cannot hold the rows even at 0.5x is refused naming sky_deg and the floor. export.validate_manifest refuses a plane with fewer than 150 rows under the horizon and manifest.ts refuses it at load.
  4. Seams. coverage counts the visible rows of the opaque view per log-distance bin and column. seams finds one seam per authored split per column by dynamic programming (seam carving, forward energy): it sits in a gap between depths, moving it costs 2 per bin plus the visible rows it sweeps (so it never hops across a ridge between two columns and splits it side by side), a seam inside visible terrain is cheap to cross-fade, the authored depth only breaks ties. Seam k stays 0.4 nat beyond seam k-1. The DP runs over the ring three times side by side and keeps the middle lap, so a seam is continuous across the wrap (column 6399 to 0) and a tile boundary is only a crop.
  5. Cards. cards runs per tile, on that tile's columns and the matching normals (it is column-independent: a tile is a crop of per-column results, so no seam appears at a tile boundary). It makes card i from the first visible hit at or beyond seam i-1 (layered depth: a farther card keeps the terrain a nearer ridge hides), alpha 1 minus a smoothstep over seam i in log-distance (the cross-fade), crest rows with fractional coverage, distance and normal interpolated between samples by angle, albedo from a small height and slope material, cropped to the rows where alpha is not zero. The rows of card i > 0 below the angle of its first sample (hit and first sample of the card) are its wall: the extruded face of the ridge the card starts at, which keeps that sample's distance, wears the ground material at its height with the face up, and is flagged wall. Card 0 also draws the near march (ruling ridge-near-ground-outline): the place's own DEM from NEAR_START_M = 1 m to the near clip NEAR_CLIP_M = 500 m (near_march: float64 bilinear samples every max(1 m, 0.02 d) up to 10 m, about 170 per column, low-passed with the place's own prefilter_m), joined to the far march by join_near on the whole ring before the tile cut, its angles capped per column at the angle of the clip sample so the near ground draws inside the silhouette of the terrain at the clip (a near hill above that edge is cut along it). Its rows are ordinary terrain with their own normal and the albedo of their own height and n_up, flagged near in memory; cards refuses a march that starts at the clip. The runtime reads them as ground at the clip distance (they decode at log_d_min) and lights them like any card pixel. The alpha-over composite of the cards equals the opaque view; check_cover refuses a tile that differs by more than 0.02.
  6. Tiles. The ring is absolute compass, column 0 = north, column c at azimuth (c + 0.5) / 6400 x 360; places.json's az_deg / look_at is only the rest azimuth (view.look_az_deg). Tile t owns columns [200 t, 200 t + 200) (11.25 degrees) and its files hold [200 t - 2, 200 t + 202): two columns of real neighbour data each side (the client's ink pass and lighting read one texel each way; the client crops it), taken periodically by ridge.ring_cols. Per card and tile the file is cropped to the rows where that tile's 8-bit alpha is not zero (top, h); a card that holds nothing in a tile is null there (the client interpolates its distance from the neighbours); a card with no solid pixel in any tile is refused.
  7. Distance and the offset range. The bake holds no camera (ruling ridge-camera-full-ring). pack gives each card tile distance_m = exp(median ln d) over the tile's solid pixels that are neither wall nor near ground (its interior 200 columns); the client derives each card's slide from that and the viewer's offset r and heading. camera.r_max_m is the largest |r| (never above half the nearest terrain's distance) at which, for every tile, card and phi (24 steps of the camera's angle on the circle against its heading; the offset-only rotation mode moves phi round the whole circle), the least-squares line a + s beta fitted to the exact view angle atan2(R sin beta - r sin phi, R cos beta - r cos phi) over the widest viewport (HFOV_MAX_DEG = 72 / 1.1) errs by at most FIT_PX_MAX = 24 card px (the continuous error: the line by quadrature over the viewport, the worst error looked for on 513 points, so a handful of samples cannot undercount it); the distance d is that of the NEAREST solid (alpha >= 0.5, neither wall nor near ground) pixel the card draws in the tile's interior columns, which is where the slide errs most (the line is fitted for the tile's distance_m, the median, but the bound is held for the nearest terrain: a tile whose terrain spans 600 to 2000 m is bound at 600 m); each tile's near pixels (under the clip) count as terrain at the clip, 500 m, alongside its solid pixels, whatever else the tile holds (they are drawn at the clip; a tile of near ground only is slid there too), so a tile with any near pixel binds at 500 m at the latest; and the resident gate (below) must hold at r_max_m too. camera.r_max_forward_m is the same search at phi = 0 alone (same FIT_PX_MAX, the same half-distance cap, the same resident gate): the camera pushed forward along its heading, which is where the offset stays when the view direction turns with it (the modes 'still' and 'both'), so it is at least r_max_m; the client takes r_max_m for the offset-only mode and for a backward offset, r_max_forward_m for a forward one in the other modes (view.ts offsetRange). FIT_PX_MAX is provisional, tuned by eye (ruling ridge-offset-range-fit). A bake whose r_max_m is below R_MAX_FLOOR_M = 25 m is refused, naming the card and tile. distance_m and the nearest-terrain table exclude the near ground (a tile with nothing outside it gets distance_m = 500 m), so card 0's distances are never nearer than the near clip (write_bake refuses one that is), and r_max_m and r_max_forward_m hold for the nearest solid terrain each card draws in each tile, at or beyond 500 m, a tile with near pixels counts them at 500 m: the ground nearer than that rides card 0's slide and is not measured beyond that.
  8. Normals. normals takes the along-ray slope and the across-ray slope at equal distance (neighbouring columns, same sample), both times the vertical exaggeration.

Files per card i and tile t: card-<i>-t<tt>-colour.webp (lossy RGB albedo, lossless straight alpha) and card-<i>-t<tt>-geometry.webp (lossless: R, G = (n + 1) / 2 for the normal's along and across components, B = log-distance normalised between encoding.log_d_min and log_d_max; wall pixels write R = G = 255, a code outside the unit disc that no real normal reaches), each 204 columns wide. The manifest lists the cards nearest first (near_m, far_m: the median seam depths over the ring) and tiles[t][i] = { top, h, distance_m, colour, geometry } or null; the runtime paints the cards last to first. The bake_id is the sha256 of the files, tile-major, then card, colour then geometry.

Budgets (check_budget; a cap is never raised to fit a bake, the lever is TILES = 64): every file of one tile at most 235 kB (1.5 MB per 72 degrees), every file of the place at most 7.5 MB, at most 6 cards, and the lit canvases (4 bytes x 202 columns x band rows, per card) of the worst run of N consecutive tiles, cyclic, at most 20 MB, where N = ceil(arc_max / 11.25) + 5 and arc_max = HFOV_MAX_DEG / s_min + 2 (r_max / Rmin) 57.3 degrees with Rmin the nearest card's smallest tile distance and s_min = Rmin / (Rmin + r_max). The loader decodes one tile at a time, so the decode transient is not gated.

Materials

places.json materials is the one owner of ground colour (ruling ridge-place-colour-authored: the topology is real, the colour is authored). A material is { base: rgb, ramps: [{ from_m, to_m, colour }], steep: { colour } | null, snow: { from_m, to_m, colour } | null }: ridge.albedo(h, n_up, material) lerps base through each ramp in order by height, then to the steep colour on steep faces (null: strata hold on cliffs), then to the snow colour on flat ground above its band. A place names its material (absent: alpine, the numbers the baker had before materials, pinned by an oracle test); an unknown name is refused (ridge.load_material). The bake id hashes the manifest and tile bytes, not the material, so a material change reaches the id only through the colours it bakes. canyon (Grand Canyon strata by height at the Unkar reach) was approved by eye on the contact sheet (ruling grandcanyon-palette-approved).

Licence

Elevation: Copernicus DEM GLO-30. The credit line is written into every manifest (attribution) and must be shown with any rendering:

Contains modified Copernicus data: DEM © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved.

Licence: free, full and open access, with the credit line shown (https://spacedata.copernicus.eu/collections/copernicus-digital-elevation-model).