Skip to content

generated_world: terrain LOD, chunks of the ground's own samples with skirts - #1001

Merged
transfix merged 1 commit into
masterfrom
perf/terrain-lod
Nov 3, 2026
Merged

transfix merged 1 commit into
masterfrom
perf/terrain-lod

Conversation

@transfix

@transfix transfix commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

The terrain lab's ground was one mesh drawn whole: 8.4 M triangles on an 11.2 km world (2049^2 samples), 2.2 M on a 5.3 km one, whatever the camera saw. This draws it with chunked LOD and skirts, section 8.4 of the L-system laboratory roadmap.

Follows #994 (tree LOD, merged); rebased onto master after it.

cvc::world::terrain_lod (new, inc/cvc/world/terrain_lod.h)

  • plan_terrain_chunks: chunks of 64 cells a side, doubled until at most 16 span the world. Rungs are strides 1, 2, 4, ... down to 4 cells a side, so a 64-cell chunk has 5 rungs and a 128-cell chunk has 6.
  • make_terrain_chunk:
    • Every rung's vertices are the terrain's own samples: its points, normals and UVs. Rung 0 is its mesh exactly, cut up. Nothing is resampled or smoothed. Normals come from the whole surface, so chunk borders light alike.
    • error_m[k] is rung k's largest vertical distance from the samples it skips, measured with the mesh's own diagonal split.
    • Skirts hang from each edge a neighbour shares, deep enough for a neighbour a rung either side. The floor is 0.5 m, for T-junction pixel cracks. The world's border has none.
  • constrain_terrain_rungs refines chunks until none is more than a rung off a neighbour, which is what the skirts are deep enough for.

generated_world

  • terrain_layout and terrain_chunks.
  • world_builder gains a lod stage that builds whole chunks per step. Natively they build in parallel; on wasm the stage is sliced like the others.

The generated_world node

  • The terrain node keeps the texture and draws nothing itself. Its children are a LodGraphicsNode per chunk.
  • Each frame, every chunk picks its rung from its own error_m (cvc::lod::select_rung, with hysteresis), then the picks are constrained.
  • The props and the ground share one view and preset: balanced natively, aggressive on wasm.
  • Rungs follow the measured error, not fixed radii: flat ground coarsens at once, and a channel's banks stay fine.
  • GeometryNode::shareTexture gives every rung the node's one vtkTexture, so the GPU holds one copy. A repaint shares the new one.
  • apply_mesh_keys (public in scene_realize.h, now used by the realize tail too) gives each rung the node's casts_shadow, shader: and material:. So terrain_bump and opaque: true still apply to the ground.
  • The shadow bake is invalidated on a chunk switch only when the ground casts.
  • Physics, nav and ground: still read the full height_field.

Measured natively, terrain only, balanced preset, 720 px view (terraincost harness):

world ground before overview low at the edge standing in the middle
1.2 km (241^2) 115 k 121 k (rung 0 + skirts) 121 k 121 k
5.3 km (1061^2) 2.25 M 6.8 k 174 k 388 k
11.2 km (2049^2) 8.39 M 15.9 k 136 k 259 k
  • The 1.2 km world's 5 m relief errs 4.7 m at stride 2, so the balanced preset keeps it at rung 0; skirts add 5%. The aggressive (wasm) preset coarsens 6 of its 16 chunks in the overview.
  • The rungs hold 1.42x the terrain's vertices, beside the terrain's own mesh. The chunk build takes well under a second on the 11.2 km world.
  • A native arigl snapshot of terrain_lab looks the same as before: the texture is on every chunk and no seam shows.

Tests

  • world_generated_test:
    • Chunks are the terrain's own samples, and rung 0's surface tiles its mesh exactly.
    • No skipped sample is further from a rung than its error_m.
    • Skirts sit only on shared edges.
    • The gap along a shared edge, for every pair of rungs a rung apart, is under both chunks' skirts.
    • Narrow last chunks and a single-chunk ground (no skirts) build correctly.
    • The neighbour constraint, and a stepped build matching a whole one.
  • cvcgl_ariadne_realize:
    • 2 x 2 chunks of five rungs, each with the node's casts_shadow: false, and an empty terrain node.
    • Rung 0 underfoot with the rest within a rung; every chunk coarser from 5 km.
    • Chunks follow a regenerated world.
    • The prop-ladder checks now look under the prop groups.
  • The world, LOD and Ariadne ctest subset passes, and clang-format is clean.

Not done here: a browser measurement (after the deploy), and morphing between rungs (CDLOD, deferred by the roadmap). Cards past 1.6 km are still to do on the tree side.

@transfix
transfix changed the base branch from perf/foliage-cost to master November 3, 2026 07:41
… skirts

The ground was one mesh drawn whole (8.4 M triangles on an 11.2 km world). cvc::world::terrain_lod
cuts it into chunks of 64 cells (doubled to at most 16 across), each a ladder of strides 1, 2, 4,
... whose vertices are the terrain's own samples (rung 0 is its mesh exactly), with each rung's
measured height error and skirts on the edges a neighbour shares. world_builder builds them in a
new "lod" stage. The generated_world node draws them as LodGraphicsNode children of the terrain
node, which keeps the one texture they share (GeometryNode::shareTexture) and draws nothing
itself; each frame a chunk chooses its rung by screen error and is held within one rung of its
neighbours. apply_mesh_keys gives the rungs the node's casts_shadow, shader and material keys.
@transfix
transfix enabled auto-merge (squash) November 3, 2026 15:08
@transfix
transfix merged commit 8a8d353 into master Nov 3, 2026
16 of 28 checks passed
@transfix
transfix deleted the perf/terrain-lod branch November 3, 2026 15:42
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