Skip to content

feat: distance-based LOD for trail rendering#48

Open
MikePehel wants to merge 1 commit intomavlink:mainfrom
MikePehel:feat/trail-lod
Open

feat: distance-based LOD for trail rendering#48
MikePehel wants to merge 1 commit intomavlink:mainfrom
MikePehel:feat/trail-lod

Conversation

@MikePehel
Copy link
Contributor

Summary

  • Distance-based LOD for both directional trails (mode 1) and speed ribbons (mode 2). Segments are culled based on squared distance to camera:
    • 400m from camera: render every 2nd segment

    • 1500m from camera: render every 4th segment

  • Uses only float multiply-add (no sqrt), so the LOD check itself is essentially free
  • Trail buffer increased from 1800 → 2700 samples (1.5×). The vertex savings from LOD give us headroom to store longer trails without performance regression. Longer trails improve situational awareness in multi-drone scenarios where vehicles may be spread across a wide area.

Benchmark results (64 drones, speed ribbon, 1080p, 30s run)

Config Median frame time
LOD OFF, 1800 buffer 8.55 ms
LOD ON, 2700 buffer 7.68 ms
LOD ON, 1800 buffer 7.43 ms

LOD consistently saves ~1ms per frame (~12%) with ribbons enabled. The larger buffer adds negligible cost (<0.3ms difference at same LOD setting).

Changes

  • src/vehicle.c: LOD skip logic in both trail rendering loops, TRAIL_MAX 1800 → 2700
  • src/vehicle.h: extern bool trail_lod_enabled declaration

Test plan

  • Verify trails render correctly up close (no visible gaps)
  • Zoom out and confirm distant trails are visually smooth (gaps not perceptible at distance)
  • Test with speed ribbon (T key to cycle trail modes)
  • Test with directional trail
  • Confirm trails are longer than before (1.5× more history)
  • Build on Linux/macOS/Windows (pure C float math, no platform-specific code)

Add level-of-detail segment skipping for both directional trails and
speed ribbons. Segments are culled based on squared distance to camera:
  - >400m: render every 2nd segment
  - >1500m: render every 4th segment

This uses only float arithmetic (no sqrt) so it's essentially free.
In benchmarks with 64 drones and speed ribbons enabled, LOD reduces
median frame time by ~12% (8.7ms → 7.7ms at 1080p).

The vertex savings from LOD give us headroom to increase the trail
buffer from 1800 to 2700 samples (1.5×) without any performance
regression. Longer trails improve situational awareness in multi-drone
scenarios where vehicles may be spread across a wide area.

Pure C float math — no platform-specific code.
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