Skip to content

generated_world: tree and rock LOD, each rung the same full tree coarser - #994

Merged
transfix merged 1 commit into
masterfrom
perf/foliage-cost
Nov 3, 2026
Merged

transfix merged 1 commit into
masterfrom
perf/foliage-cost

Conversation

@transfix

@transfix transfix commented Nov 3, 2026

Copy link
Copy Markdown
Owner

The deployed terrain lab spends most of its GPU time on the trees. Hooking WebGL in the live page (Intel Arc, 1.2 km world) found one merged mesh, world_props: 771,994 triangles of branch tubes for 403 trees, plus 149,481 needle lines. Skipping that one draw took the lab from 29 fps to 51.

  • A branchy tree is about 1,900 triangles.
  • A maturity-4 pine is 7,600 triangles and 2,754 needle lines.
  • At the overview distance, most of those branches are thinner than a pixel.

This adds LOD for the trees and rocks. Every rung is the same full-maturity tree: same skeleton, jitter, size and height. Only the tessellation gets coarser with distance.

What changes

  • cvc::lsys::tree_detail, with grow_pine / grow_branchy overloads that take it. It draws the same tree:
    • ring-sided uncapped tubes;
    • tubes thinner than min_radius left out;
    • leaves as solids: a pine leaf (9 needles fanned in a cone) becomes a 4-triangle cone of the same shape, and a broadleaf fork's leaf twigs become one blob, narrowed to the twigs' side-on area.
  • generate_world lays the props down one 128 m ground cell at a time (at most 12 cells a side).
    • prop_cells records each cell's contiguous run of every mesh. prop_span_mesh cuts a run out of a mesh.
    • props_r1 is rung 1 (tree_detail: 3-sided tubes, none under 5 cm, leaves as solids).
    • props_r2 is rung 2: each tree's trunk plus a crown over its full canopy, and a box per rock.
    • A broadleaf's crown takes the full tree's area-weighted colour and is narrowed to cover what its limbs and twigs do, so the look holds when a cell switches. A pine's crown keeps the needle colour at full size, because needle lines draw at least a pixel wide and fill it.
    • props, foliage and needles stay as they were (rung 0), so geometry() and physics and nav are unchanged.
  • The generated_world node draws each cell as a LodGraphicsNode ladder under <id>_props, <id>_foliage and <id>_needles.
    • The ladders are selected every frame with cvc::lod screen error. Rung 1 starts at 260 m and rung 2 at 700 m, the vegetation bands of LSYSTEM-LABORATORY-ROADMAP §8.4, authored against the reference view so the quality preset scales them. The wasm build uses the aggressive preset, like the room view.
    • A cell's leaves and needles follow its wood ladder.
    • A rung change invalidates the shadow bake.

Measured

Mesh sizes for terrain_lab's default world (seed 5, 1.2 km, 500 trees):

triangles lines
rung 0 (unchanged) 771,994 149,481
rung 1 277,740 (36%) 0
rung 2 8,766 (1.1%) 0

The props sit in 96 cells; the largest has 21.5k rung-0 triangles.

Per tree, tree_detail{ring 3, min_radius 0.05} cuts the triangle count to under half of the full tree's, with the same extent and height (TreeDetailIsTheSameTreeCoarser).

A native arigl snapshot of terrain_lab at its default view, compared before and after: the overview, where most cells are on rung 2, keeps the full trees' look. The crowns match the tree's colour mix and coverage.

Not measured yet: the browser frame rate. That's the deploy after this merges.

Tests

  • LsysForest.TreeDetailIsTheSameTreeCoarser: pines of maturity 2–4 and a branchy tree. The coarse tree has the full tree's extent within 15% (height within 5%), less than half the triangles, no needle lines, and leaves in the leaf colour.
  • WorldGenerated.PropCellsAreTheFullTreesCoarsened:
    • the cells cover every mesh exactly, in order, with each cell's rung 0 inside its bounds;
    • the coarser rungs stand where the full trees do and are nearly as tall, with no lines;
    • rung 1 is under half of rung 0's triangles, and rung 2 under 1/20.
  • SteppedBuildIsTheSameWorld also compares props_r1, props_r2 and prop_cells.
  • cvcgl_ariadne_realize: the props are three-rung ladders; a close camera draws rung 0 and one 5 km off draws a coarser rung (153 checks pass).
  • ctest World|Lsys|Lod|lod|Ariadne|ariadne|Road|NavTerrain|Sites|world|road: 1,103 of 1,103 pass on Windows Release (some skipped).
  • clang-format is clean on the changed lines.

Still to do

  • The terrain: chunks with skirts (§8.4's T0–T4). It is the other half of the 5–11 km worlds' cost.
  • Cards past 1.6 km.

The terrain lab drew its props as one merged mesh: 771,994 triangles of
branch tubes for 403 trees plus 149,481 needle lines, the GPU's largest
single cost on the deployed page (skipping it took 29 fps to 51).

- cvc::lsys::tree_detail and grow_pine / grow_branchy overloads draw the
  same tree (maturity, skeleton, jitter, size) coarser: n-sided uncapped
  tubes, tubes under min_radius left out, and the leaves as solids (a pine
  leaf a 4-triangle cone of its needles' shape, a broadleaf fork's leaf
  twigs one blob narrowed to the twigs' side-on area).
- generate_world lays the props down a 128 m cell at a time (prop_cells:
  each cell a contiguous run of every mesh) and adds props_r1 (the
  tree_detail rung: 36% of the triangles, no lines) and props_r2 (a trunk
  and a crown per tree, a box per rock: 1.1%). A broadleaf's crown takes
  the full tree's area-weighted colour and covers what its limbs do.
  prop_span_mesh cuts a cell's run out of a mesh.
- The generated_world node draws each cell as a LodGraphicsNode ladder
  under <id>_props / _foliage / _needles and selects it every frame with
  cvc::lod (rung 1 from 260 m, rung 2 from 700 m, the roadmap's vegetation
  bands, scaled by the quality preset); a cell's leaves and needles follow
  its wood, and a rung change re-bakes the shadows.

Tests: LsysForest.TreeDetailIsTheSameTreeCoarser,
WorldGenerated.PropCellsAreTheFullTreesCoarsened, the stepped build
compares the new meshes, and cvcgl_ariadne_realize checks the ladders and
that a near camera draws rung 0 and a far one a coarser rung.
@transfix
transfix merged commit a04de3b into master Nov 3, 2026
27 checks passed
@transfix
transfix deleted the perf/foliage-cost branch November 3, 2026 15:07
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