From a07c161df2fb0b99af74bef174aab1d98a26c71c Mon Sep 17 00:00:00 2001 From: eliotbyte Date: Mon, 24 Nov 2025 01:27:56 +0300 Subject: [PATCH 1/2] fix: remove redundant sorting --- src/graphics/render/ChunksRenderer.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/graphics/render/ChunksRenderer.cpp b/src/graphics/render/ChunksRenderer.cpp index 170fe754b..937468d0c 100644 --- a/src/graphics/render/ChunksRenderer.cpp +++ b/src/graphics/render/ChunksRenderer.cpp @@ -396,11 +396,6 @@ void ChunksRenderer::drawSortedMeshes(const Camera& camera, Shader& shader) { order.push_back(VisibleChunkTrans{glm::ivec2(chunk->x, chunk->z), &chunks[index.index], nearest}); } - // Sort chunks by nearest translucent distance back-to-front (far to near) - std::sort(order.begin(), order.end(), [](const VisibleChunkTrans& a, const VisibleChunkTrans& b) { - return a.nearestDist2 > b.nearestDist2; - }); - // Draw per-chunk sorted mesh (keeps GPU buffers and avoids per-frame repack) for (const auto& item : order) { const auto& chunk = *item.chunkPtr; From 95188ef257d215c6bc068eb19260cfe54d83f930 Mon Sep 17 00:00:00 2001 From: eliotbyte Date: Mon, 24 Nov 2025 01:31:43 +0300 Subject: [PATCH 2/2] refactor: simplify translucent chunks ordering code --- src/graphics/render/ChunksRenderer.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/graphics/render/ChunksRenderer.cpp b/src/graphics/render/ChunksRenderer.cpp index 937468d0c..3309e3a94 100644 --- a/src/graphics/render/ChunksRenderer.cpp +++ b/src/graphics/render/ChunksRenderer.cpp @@ -363,12 +363,11 @@ void ChunksRenderer::drawSortedMeshes(const Camera& camera, Shader& shader) { struct VisibleChunkTrans { glm::ivec2 key; const std::shared_ptr* chunkPtr; - long long nearestDist2; }; std::vector order; order.reserve(indices.size()); - // Build per-chunk nearest distance for translucent entries + // Build list of visible translucent chunks in the same order as indices for (const auto& index : indices) { const auto& chunk = chunks[index.index]; if (chunk == nullptr || !chunk->flags.lighted) { @@ -388,12 +387,10 @@ void ChunksRenderer::drawSortedMeshes(const Camera& camera, Shader& shader) { if (!frustum.isBoxVisible(bounds.min, bounds.max)) continue; } - long long nearest = LLONG_MAX; - for (const auto& e : entries) { - long long d2 = static_cast(glm::distance2(e.position, cameraPos)); - if (d2 < nearest) nearest = d2; - } - order.push_back(VisibleChunkTrans{glm::ivec2(chunk->x, chunk->z), &chunks[index.index], nearest}); + order.push_back(VisibleChunkTrans{ + glm::ivec2(chunk->x, chunk->z), + &chunks[index.index] + }); } // Draw per-chunk sorted mesh (keeps GPU buffers and avoids per-frame repack)