mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 14:31:50 +00:00
refactor: simplify translucent chunks ordering code
This commit is contained in:
parent
a07c161df2
commit
95188ef257
1 changed files with 5 additions and 8 deletions
|
|
@ -363,12 +363,11 @@ void ChunksRenderer::drawSortedMeshes(const Camera& camera, Shader& shader) {
|
||||||
struct VisibleChunkTrans {
|
struct VisibleChunkTrans {
|
||||||
glm::ivec2 key;
|
glm::ivec2 key;
|
||||||
const std::shared_ptr<Chunk>* chunkPtr;
|
const std::shared_ptr<Chunk>* chunkPtr;
|
||||||
long long nearestDist2;
|
|
||||||
};
|
};
|
||||||
std::vector<VisibleChunkTrans> order;
|
std::vector<VisibleChunkTrans> order;
|
||||||
order.reserve(indices.size());
|
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) {
|
for (const auto& index : indices) {
|
||||||
const auto& chunk = chunks[index.index];
|
const auto& chunk = chunks[index.index];
|
||||||
if (chunk == nullptr || !chunk->flags.lighted) {
|
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;
|
if (!frustum.isBoxVisible(bounds.min, bounds.max)) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long nearest = LLONG_MAX;
|
order.push_back(VisibleChunkTrans{
|
||||||
for (const auto& e : entries) {
|
glm::ivec2(chunk->x, chunk->z),
|
||||||
long long d2 = static_cast<long long>(glm::distance2(e.position, cameraPos));
|
&chunks[index.index]
|
||||||
if (d2 < nearest) nearest = d2;
|
});
|
||||||
}
|
|
||||||
order.push_back(VisibleChunkTrans{glm::ivec2(chunk->x, chunk->z), &chunks[index.index], nearest});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw per-chunk sorted mesh (keeps GPU buffers and avoids per-frame repack)
|
// Draw per-chunk sorted mesh (keeps GPU buffers and avoids per-frame repack)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue