Render Pipeline
DownDraft uses a deferred WebGPU rendering pipeline with a Bevy-style render graph for automatic resource management.
Pipeline Stages
Section titled “Pipeline Stages”The deferred pipeline executes in this order:
-
Depth Prepass — Early-Z prepass writes depth buffer for occlusion culling. Reduces overdraw in the main pass.
-
G-Buffer Pass — Opaque geometry rendered to multiple render targets:
- Albedo (RGBA8)
- Normal (RGBA8, packed)
- Metallic + Emissive (RGBA8)
- Roughness + AO (RGBA8)
- Velocity (RG16F) — for TAA
- Depth (Depth32Float)
-
Shadow Map Pass — Shadow depth maps rendered from light perspectives. Supports cascaded shadow maps for directional lights and point shadow maps for point lights.
-
Deferred Lighting — Fullscreen pass reads G-Buffer and shadow maps to calculate lighting (with clustered light assignment for dynamic lights). Supports:
- Directional lights (sun)
- Point lights (dynamic, distance-culled)
- Spot lights (flashlight, etc.)
- Ambient and fog
-
Sky Pass — Sky dome rendered with atmospheric scattering, sun/moon, weather blending.
-
Transparent Pass — Back-to-front rendering of transparent geometry (water, particles, clouds).
-
Post-Process Chain — Configurable post-processing stack:
- Tonemapping (ACES, Reinhard, etc.)
- Bloom
- FXAA / TAA
- Depth of field
- Sobel edge detection
- Afterimage
- ASCII art
- Color grading (LUT)
- Pixelation
Render Graph
Section titled “Render Graph”The FrameGraph is a DAG of render passes with:
- Automatic resource aliasing — GPU resources (textures, buffers) are reused across passes when lifetimes don’t overlap
- Usage flag synchronization — Resource transitions between read/write are handled automatically
- Pass validation — Resource dependencies validated at graph build time
- Pipeline caching — Render pipelines cached and specialized
Viewport Support
Section titled “Viewport Support”The renderer supports split-screen with 1-4 viewports. Each viewport renders independently with its own camera, sharing the same render pass (offscreen targets are cleared on first viewport, loaded on subsequent).
Frame Rate Limiting
Section titled “Frame Rate Limiting”A frame rate limiter is available for X11 multi-monitor vsync issues where the render loop is driven at the fastest monitor’s refresh rate. The limiter uses an adaptive accumulator to skip frames when the frame interval is faster than the target frame time.
GPU Profiling
Section titled “GPU Profiling”When supported, GPU timestamp queries provide per-pass timing data:
- Sky, Terrain, Entities, Clouds, Water, Debug, Models, Particles, Gizmo, UnderwaterFog
- Each pass tracks draw calls and triangle counts
- Exposed via telemetry collector and MCP tools