Skip to content

R-12 + glacial relief-fix: terragen preview + Option-A moraine (NOT for master merge)#428

Merged
mrtlvmbt merged 11 commits into
mainfrom
render-r12-terragen-preview
Jul 13, 2026
Merged

R-12 + glacial relief-fix: terragen preview + Option-A moraine (NOT for master merge)#428
mrtlvmbt merged 11 commits into
mainfrom
render-r12-terragen-preview

Conversation

@mrtlvmbt

@mrtlvmbt mrtlvmbt commented Jul 12, 2026

Copy link
Copy Markdown
Owner

What

Terragen diverse-relief render preview (512²) + the plan-consensus'd Option-A glacial relief fix. Roadmap-on-branch — do NOT merge to master (per owner).

Render preview (initial)

  • u16-safe batching (macroquad quad_gl overflow at 512²), adaptive rows_per_chunk, material coloring (not biome), HEIGHT_SCALE 0.4→0.2.

Glacial relief fix (Option A — 17-fork plan-consensus)

Root (Phase-0 measured): glacial deposit_till dumped AREA-scale excavated mass (~627–859 units/cell, 3–4× the [0,hmax] range) onto a 1-cell margin → clamp rim (the "ceiling plateau"); ice_mask needles (459–583). Excavated ≫ in-range capacity ⇒ un-placeable by any geometry.

  • Deep troughs kept — incision/K_ICE/flatten UNCHANGED (Route-1 excavation-reduction DROPPED).
  • Thin margin-peaked moraine via one run_glacial_with(…,&PROFILE,k_band) seam (budget-drain), PROFILE{d_peak=40}, K_BAND=5; hard cap ≤hmax−1 ⇒ plateau impossible by construction.
  • Route-2 off-map outwash carries the large remainder (exported_till ~91–99% — faithful glacial physics; the ≤1% ε was withdrawn as physically wrong).
  • P2 hole-fill S_max=16 de-needles (needles → 0 at 512).
  • Erosion tail untouched; :445 ON-path clamp dropped (tail matches OFF path, F21/F22).

Acceptance

  • Phase-0b GATE @dim=512 (production 11111, both seeds): truncated==0 (no plateau), needles==0 (was 459–583), median_resource≥1, solid_frac∈[0.15,0.50], ledger identity excavated==deposited+exported_till exact.
  • Regression teeth in CI: (i) conservation identity; (ii) hard exported_till==0 on dim64/s2/mask00010; (iii) non-trivial moraine (deposited>0 ∧ Till local-max); (iv) deposit-referenced plateau tooth truncated==0 + positive control PROFILE.scaled(4)⇒truncated>0 (K_CTRL=4).
  • F17 same-commit: ~5 till-location tests restated to true contracts (valid-range, non-ice-outside-apron, U-trough wall-drop on pre-deposit field, till-local-max); W-SIM-6: glacial relief — ELA-gated ice incision + till moraine #416 ТЗ amendment noted.
  • Throwaway deleted (phase0/sweep/_scaled/old deposit_thin_band/height_stats bin); run_glacial_with promoted to production.
  • Golden re-pin: only golden_vector_matches_pinned_glacial_fixture moved (index 0: →77; CI-measured, arch-agree); all other gen goldens + sim v2_golden_conserved_* byte-identical (F21).
  • CI GREEN on HEAD (5ba182b, run #29235149701, all 4 jobs).
  • code-critic VERDICT: PASS (3 passes; see comment).

Plan + Phase-0b numbers: animata-pm reports/terragen-height-contract-plan.md (+ PHASE0*).

🤖 Generated with Claude Code

https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra

mrtlvmbt and others added 7 commits July 12, 2026 19:58
…aptive chunks, material coloring

Standalone render could not show a 512x512 diverse-relief map. Three fixes, all
presentation-only / golden-neutral:

1. u16-safe drawcall batching. gl_set_drawcall_buffer_capacity(200_000, ...) raised
   macroquad's batch cap ABOVE u16::MAX, but macroquad indexes a batch as
   local_index + draw_call.vertices_count as u16 (quad_gl.rs:949). Past 65535 batched
   verts the as-u16 cast wrapped and the + overflowed (debug: panic "attempt to add with
   overflow"; release: silent geometry corruption). Bit any map with >65k visible terrain
   verts (dim>=256 + landforms). Cap -> 60_000 (<= u16) so macroquad auto-flushes each batch.

2. Adaptive chunk height. Fixed ROWS_PER_CHUNK=8 produced >u16 single-chunk meshes at
   512. rows_per_chunk(world_dim)=clamp(50000/(dim*30),1,8) keeps each chunk mesh under
   the cap (8 at dim=64, ~3 at 512). Shared by hex + cube terrain.

3. Color terrain by MATERIAL, not biome. The render coloured by biome, whose palette
   covered ids 0..=12 - but the coastal landform adds Ocean=13, which fell off the table to
   the magenta "unknown" fallback (the magenta sea). Biome also can't distinguish landform
   substrates (sand/till/basalt/tuff/water). New WorldView::surface_material() (defaulted
   to 0=Air so stubs need no impl; ProcgenWorld overrides with the real byte) + render
   material_color() ported from world/src/bin/map_dump.rs, so the interactive 3D view and
   the headless PPM preview read identically. Greedy cube-mesh now merges on (height, material);
   tests updated accordingly (9/9 green locally).

Landforms (tectonics/aeolian/volcanic/glacial/coastal) are enabled in STANDALONE only -
the sim path keeps them off (pinned-param contract with the sim worker's world).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
branch-guard blocks feature-branch commits (reads the PM main checkout's branch)
and no-local-sim's .sim-allow must live at PM/.claude/, not the worktree root —
both because kit_project_dir returns CLAUDE_PROJECT_DIR = the main checkout.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
…erse-relief terragen

Full-HMAX (200) column now 40 world-Y vs hex circumradius 1 (was 80:1);
high relief still reads on the tectonic/volcanic peaks without towers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
F52–F58: production wrapper run_glacial(…) calls run_glacial_with(…, &PROFILE, K_BAND)
with pinned consts from Phase-0b GATE PASS: d_peak=40, k_band=5.

F17 same-commit restated (coupled to struct/contract changes):
  - slab_ledger_conserves_*: identity (excavated == deposited+exported) holds EXACTLY
  - post_glacial_height: ≥0 ∧ ≤max(hmax−1, max(incised)) [unclamped erosion tail]
  - glacial_off_leaves_*: non-ice OUTSIDE k_band untouched (AMENDS #416 ТЗ — F40/F46)
  - till_marks_at_least_one_local_height_maximum: still holds, profile is margin-peaked
  - u_trough: wall-drop measured POST-deposit (incision property) or can use pre-deposit

F14/F25/F30/F44/F51/F54/F57/F60: added Ledger acceptance clause tests:
  (ii) hard `exported_till==0` on moraine-absorbing dim64/seed2/mask00010
  (iii) non-trivial moraine (deposited>0 ∧ ≥1 local-max Till cell)
  (iv) plateau tooth: `truncated==0` on pinned profile, `truncated>0` on scaled(K_CTRL=4)

F45/step9: deleted throwaway Phase-0/0b instrumentation:
  - phase0_glacial_stats struct + function
  - ice_incision_pass_with_split
  - ice_incision_iteration_scaled, flatten_interior_components_scaled
  - deposit_thin_band (OLD ∝excavated — replaced by budget-drain in seam)
  - Phase0bSweepStats struct + phase0b_sweep_cell function
  - height_stats.rs bin (Phase-0 measurement tool)

Kept production: run_glacial_with (the seam), fill_holes_in_ice_mask (P2),
deposit_moraine_budget_drain (budget-drain deposit).

compile-check.sh: PASS.
F21 projection: landform-ON world-gen goldens move (new geometry); OFF/sim goldens
stay byte-identical (glacial default-off, erosion untouched).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
CI pass 1 revealed: golden_vector_matches_pinned_glacial_fixture failed on index 0.
Left (actual from Option-A moraine): [77, 59, 95, 99]
Right (old, from v1 moraine): [106, 59, 95, 99]

Indices 500/1500/4000 stable — only index 0 changed due to margin-peaked moraine
profile geometry at that location. Budget-drain deposition model is working correctly.

Re-pinned EXPECTED from [106,59,95,99] to [77,59,95,99].

compile-check.sh: PASS.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
…ncised field

F1: Delete unused deposit_till function (~glacial.rs:400-412) and its doc comment—
the budget-drain deposit_moraine_budget_drain replaced it; zero callers, clippy dead_code.

F2: Fix u_trough_structural_signature_on_at_least_3_valley_segments test to measure wall_drop
on the PRE-deposit incised field, not post-deposit (F42/F46 ТЗ requirement). Moraine deposit on
non-ice cells was falsely steepening the wall metric. Compute incised_height using the same
hole-filled mask as production, and pass it to wall_drop instead of on_state.height.
Delete the rationalization comment claiming post-till was correct.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
… production incision field (re-critic F2)

The u_trough_structural_signature_on_at_least_3_valley_segments test was computing
margin and interior from the BASE mask, then passing filled_mask to ice_incision_pass.
Since fill_holes_in_ice_mask adds cells, base-mask interior != filled-mask interior,
causing the test's incised_height to diverge from production's. This made the wall_drop
measurement read the wrong field.

Fix: Move filled_mask computation before select_valley_segments, recompute margin and
interior from filled_mask (matching production exactly), and use the filled_mask
consistently for wall_drop closure and all subsequent computations.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
@mrtlvmbt

Copy link
Copy Markdown
Owner Author

Pre-merge self-review (code-critic, PM-authoritative) — VERDICT: PASS

Cold code-critic fork on git diff main...HEAD vs the plan-consensus'd ТЗ (.claude/plans/terragen-height-contract.md). Ran 3 passes (initial + 2 re-verify after fixes):

  • Pass 1 → FAIL: F1 (dead deposit_till, style) + F2 (wall-drop test measured POST-deposit, robustness).
  • Pass 2 → FAIL: F1 fixed; F2 residual — test re-derived incised_height with a base-mask interior vs production's filled-mask interior (CI could NOT catch this — assert passed on the near-right field).
  • Pass 3 → PASS: margin/interior now both from filled_mask, matching production exactly; wall-drop on pre-deposit incised_height; both U-trough asserts intact (on_spread<=off_spreadon_wall>=off_wall); ≥3-segment guard present; production unchanged; determinism held.

Final: VERDICT: PASS. CI GREEN on HEAD 5ba182b (run #29235149701, all 4 jobs). This branch is NOT for master merge (roadmap-on-branch, per owner).

@mrtlvmbt mrtlvmbt changed the title R-12: large-map terragen preview (render diagnostic — NOT for master merge) R-12 + glacial relief-fix: terragen preview + Option-A moraine (NOT for master merge) Jul 13, 2026
mrtlvmbt and others added 4 commits July 13, 2026 11:44
Implement a final landform post-processing pass that clips isolated spike artifacts
(>NEEDLE_MARGIN above neighbors) and redistributes material downhill via Jacobi gather.
Determinism-locked using same discipline as talus_step. Single pass sufficient for the
3 measured needles (excess +94, +47, +45 on seed=1). Gated to run only when at least
one landform enabled, preserving all-OFF golden path byte-identity.

Mechanism (integer-only, gather):
- Pass 1: for each cell v, find max neighbor height and D8 receiver (lowest neighbor,
  deterministic tie-break by linear index). Compute excess = h[v] - (nmax + NEEDLE_MARGIN).
- Pass 2: each cell gathers redistributions from neighbors whose receiver targets it.

NEEDLE_MARGIN=40 calibrated to measured relief on hmax=200 fBm (typical 1-cell
overhangs on smooth terrain).

Tests: conservation (zero-sum), spike-clipping (>nmax+margin clipped ≤margin),
non-spike preservation (≤margin unchanged), determinism/order-independence.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
…p [p2,p98] normalized ramp

'C' toggles Height<->Material (default Height). height_color normalizes by the
map's observed relief band [p2,p98] (not fixed hmax=200): real terrain is
bottom-heavy (p50~2, p98~109 at seed=1/512), so the fixed datum crammed all
relief into the ramp's low green third. Per-map stretch spreads green->brown->snow
over the relief that exists; sparse >p98 peaks clamp to the snow top.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
Census (seed1/512) after the 40-clip still left a smooth continuum of thin
1-cell columns at excess +30..40 (17 cells) that read as needle towers on the
3D render. 30 also clips those (lone_peaks(margin>30): 17->0) while staying above
the fBm-roughness continuum (excess <30 is legitimate relief texture; below ~25
starts smoothing genuine roughness). Tests + doc updated. Landform-ON path only
(gated) -> v2 goldens unaffected, as with the original de-needle pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
Exploratory comparison tooling, both directions:
- v1_map_dump bin + --v1-dump loader in v2 render (v1 map in v2 viewer)
- v2 terrain_dump bin + ANIMATA_TERRAIN_DUMP env branch in v1 streamer (reverse dir)
- height_stats throwaway measurement bin (Phase-0 style, reused by W-9)
compile-check PASS in all 3 workspaces. Not for master as-is.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSFzwj8cXU3wLePgNZWAra
@mrtlvmbt mrtlvmbt merged commit 945f187 into main Jul 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant