Skip to content

opt: batch trail rendering and fix ribbon twisting - #39

Merged
mrpollo merged 1 commit into
PX4:mainfrom
MikePehel:opt/trail-batching
Mar 10, 2026
Merged

opt: batch trail rendering and fix ribbon twisting#39
mrpollo merged 1 commit into
PX4:mainfrom
MikePehel:opt/trail-batching

Conversation

@MikePehel

Copy link
Copy Markdown
Collaborator

Summary

  • Batch trail draw calls: Replace per-segment DrawLine3D and DrawTriangle3D with single rlBegin/rlEnd batches using rlVertex3f/rlColor4ub. Reduces draw call overhead from ~3600 per vehicle (at max trail capacity) to 1 for directional trails and 1 for speed ribbons.
  • Fix ribbon twisting on tight turns: Add perpendicular vector blending (70% previous frame + 30% current) to the speed ribbon so quad edges flow smoothly through sharp direction changes instead of overlapping/twisting.

Details

Both trail modes (directional lines and speed ribbon triangles) now submit all geometry in a single rlBegin/rlEnd pair per vehicle instead of issuing individual Raylib draw calls per segment. The color and vertex data are identical — only the submission path changes.

The ribbon blending works by lerping each segment's perpendicular vector toward the previous segment's perpendicular before computing quad corners. This produces a smooth, continuous ribbon surface even on tight orbits.

Only src/vehicle.c is modified. Uses rlgl.h which is already included. No new dependencies. Cross-platform (Mac/Windows/Linux).

Test plan

  • Verify directional trail (T key, mode 1) renders identically to before
  • Verify speed ribbon (T key, mode 2) renders without twisting on tight turns
  • Confirm no visual regression in any view mode
  • Test with multiple vehicles to verify per-vehicle batching

Replace per-segment DrawLine3D/DrawTriangle3D calls with single
rlBegin/rlEnd batches using rlVertex3f/rlColor4ub. This reduces
draw call overhead from ~3600 calls per vehicle (at max trail
capacity) down to 1 for directional trails and 1 for speed ribbons.

Add perpendicular vector blending (70% previous + 30% current) to
the speed ribbon to prevent quad twisting on tight turns.
@mrpollo
mrpollo merged commit 03fd335 into PX4:main Mar 10, 2026
5 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.

2 participants