From 1935cfc7e596000dba35689e7dd176c85ddca696 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 19 Oct 2026 01:13:12 +0200 Subject: [PATCH] Translucent draws: main's order when no distant tile has water Sections arrive back to front (visible is sorted by distance, then key), so the merged list only needs sorting when a distant tile adds translucent draws, and ties now break the same way as main's reversed visible order: with LODs off the draw order and cost are exactly main's. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index c44689e8d..99a755941 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -71,7 +71,6 @@ pub mod translucency; pub(crate) mod upload; mod world_post; -/// A new value for `Renderer::block_entity_revision`. /// A section's instance: its camera-relative origin and, in `w`, the step of /// its fixed-point UVs (`terrain.wgsl`'s `terrain_uv`). fn section_instance(origin: [f32; 3]) -> [f32; 4] { @@ -82,6 +81,7 @@ fn section_instance(origin: [f32; 3]) -> [f32; 4] { 1.0 / crate::mesher::UV_STEPS, ] } +/// A new value for `Renderer::block_entity_revision`. fn next_block_entity_revision() -> u64 { static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed) @@ -2814,6 +2814,9 @@ impl Renderer { )); } } + // Sections went back to front (`visible` is sorted by distance, then + // key): tiles' water only needs sorting in when there is some. + let section_translucent = self.translucent_draws.len(); for (i, v) in visible_lods.iter().enumerate() { let instance = visible.len() + i; let tile = self.lods.get_mut(&v.key).expect("visible resident tile"); @@ -2850,8 +2853,10 @@ impl Renderer { } } // Near water and distant water share one back-to-front draw order. - self.translucent_draws - .sort_unstable_by(|a, b| b.0.cmp(&a.0).then(a.1.cmp(&b.1))); + if self.translucent_draws.len() > section_translucent { + self.translucent_draws + .sort_unstable_by(|a, b| b.0.cmp(&a.0).then(b.1.cmp(&a.1))); + } for &(_, _, draw, pages) in &self.translucent_draws { self.draws.push(draw); self.draw_pages.push(pages);