Skip to content

Add distance-based terrain LOD system#78

Merged
brendancol merged 4 commits intomasterfrom
issue-74
Mar 6, 2026
Merged

Add distance-based terrain LOD system#78
brendancol merged 4 commits intomasterfrom
issue-74

Conversation

@brendancol
Copy link
Contributor

Closes #74 (terrain LOD portion)

Summary

Terrain LOD from the roadmap (#74). Splits terrain into tiles, picks resolution per tile based on camera distance. Nearby tiles stay full-res, distant tiles get subsampled.

What's included

  • rtxpy/lod.py — LOD utilities: compute_lod_level(), compute_lod_distances(), simplify_mesh() (quadric decimation), build_lod_chain() (progressive simplification)
  • rtxpy/viewer/terrain_lod.pyTerrainLODManager: tiles the terrain, assigns LOD per tile (0=full, 1=2x, 2=4x, 3=8x subsample), builds a separate GAS per tile, adds edge skirts to cover T-junction cracks
  • Engine integration — tiles update in the tick loop when camera moves past a threshold. Works with R/Shift+R resolution and Z/Shift+Z VE. Terrain visibility toggle (Shift+E) handles LOD tiles
  • Shift+A keybinding to toggle LOD in the viewer
  • 28 tests: LOD level computation, distance thresholds, mesh simplification, tile creation, distance-based assignment, VE, cache invalidation, skirt geometry
  • Docs: API reference for LOD utilities, keybinding in user guide, performance tip

Not included (future work per #74)

  • Instanced geometry LOD (mesh LOD chains, billboard imposters)
  • Hybrid cluster/standard GAS selection by distance
  • LOD budget system (auto-adjust thresholds for target frame time)

Test plan

  • 28 new tests pass (pytest rtxpy/tests/test_lod.py)
  • Existing mesh tests unaffected (42 total pass)
  • Manual: launch examples/terrain_lod_demo.py, press Shift+A, check tiles render at varying resolution
  • Manual: with LOD on, press R/Shift+R to change base resolution, check tiles rebuild
  • Manual: with LOD on, press Z/Shift+Z to change VE, check tiles update

Implement terrain level-of-detail with per-tile resolution control:

- TerrainLODManager divides terrain into tiles, assigns LOD levels
  based on camera distance, and builds separate GAS per tile
- LOD levels: 0 (full res), 1 (2x subsample), 2 (4x), 3 (8x)
- Tile edge skirts hide T-junction cracks between different LOD levels
- Toggle with Shift+A keybinding in interactive viewer
- Integrates with existing R/Shift+R resolution and Z/Shift+Z VE controls
- Core LOD utilities (compute_lod_level, simplify_mesh, build_lod_chain)
  in rtxpy/lod.py for terrain and instanced geometry LOD
28 tests covering:
- compute_lod_level distance-to-LOD mapping (boundary, edge cases)
- compute_lod_distances threshold generation
- simplify_mesh quadric decimation
- build_lod_chain progressive simplification
- TerrainLODManager tile creation, LOD assignment, VE, cache invalidation
- Tile helper functions and skirt geometry
- Add LOD utilities section to api-reference.md
- Add Shift+A keybinding to user-guide.md keyboard controls
- Add terrain LOD tip to performance section
Script generates synthetic terrain and launches the viewer with
instructions to toggle LOD via Shift+A. Supports xarray-spatial
Perlin noise or falls back to sine-based terrain.
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.

Level of detail: terrain LOD, instanced LOD, and hybrid cluster GAS

1 participant