pub fn render_scene_composed(
fb: &mut [u32],
zb: &mut [f32],
pitch_pixels: usize,
width: u32,
height: u32,
pool: &mut ScratchPool,
scene: &mut Scene,
camera: &Camera,
settings: &OpticastSettings,
sky_color: u32,
sky: Option<&Sky>,
) -> RenderOutcomeExpand description
Render every grid in scene with per-grid temporary buffers +
z-buffer composition. The canonical multi-grid scene render
path.
Algorithm:
- Caller pre-fills
fbwith the desired sky colour andzbwithf32::INFINITY(so any rendered pixel wins the initial composition). - For each grid, allocate a temporary
(temp_fb, temp_zb)of the same size, pre-fill them with sky /INFINITY, and runopticastinto them via aScalarRasterizerover the temporary buffers AND the grid’s combined-world view (S4.0). - Merge the temporary buffers into the shared
(fb, zb)viacompose_into— closer pixels (smallerz) win.
Pixel correctness across overlapping grids: sky pixels emerge
with z = gxmax / i32::MAX (a very large value), so they
always lose to any hit. Hits compete on actual perpendicular
distance — the closer grid’s surface is what gets composited.
pitch_pixels is the framebuffer’s row stride in pixels (×4 for
bytes). width × height must equal fb.len() /
zb.len(). sky is the optional textured sky resource the
rasterizer threads through to phase_startsky; None ⇒ solid
pool.skycast fill.
Heap allocation per call: two Vec allocations per grid (a
temp framebuffer and zbuffer). For repeated frame rendering an
owned scratch struct that pre-allocates these is the obvious
optimisation; deferred until profiling shows it matters.