mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Generalize mesh chunking, and make it configurable. (#13179)
* Generalize mesh chunking. Set 3x3x3 chunks. * Make mesh chunk size configurable... Default to 1 (off). * Extract all mesh grid maths into a dedicated class --------- Co-authored-by: x2048 <codeforsmile@gmail.com>
This commit is contained in:
parent
56d2567b5d
commit
d3a6ee00e6
11 changed files with 116 additions and 116 deletions
|
@ -304,6 +304,7 @@ void ClientMap::updateDrawList()
|
|||
blocks_seen.getChunk(camera_block).getBits(camera_block) = 0x07; // mark all sides as visible
|
||||
|
||||
std::set<v3s16> shortlist;
|
||||
MeshGrid mesh_grid = m_client->getMeshGrid();
|
||||
|
||||
// Recursively walk the space and pick mapblocks for drawing
|
||||
while (blocks_to_consider.size() > 0) {
|
||||
|
@ -330,7 +331,6 @@ void ClientMap::updateDrawList()
|
|||
|
||||
MapBlockMesh *mesh = block ? block->mesh : nullptr;
|
||||
|
||||
|
||||
// Calculate the coordinates for range and frutum culling
|
||||
v3f mesh_sphere_center;
|
||||
f32 mesh_sphere_radius;
|
||||
|
@ -376,13 +376,21 @@ void ClientMap::updateDrawList()
|
|||
continue;
|
||||
}
|
||||
|
||||
// Block meshes are stored in blocks where all coordinates are even (lowest bit set to 0)
|
||||
// Add them to the de-dup set.
|
||||
shortlist.emplace(block_coord.X & ~1, block_coord.Y & ~1, block_coord.Z & ~1);
|
||||
// All other blocks we can grab and add to the keeplist right away.
|
||||
if (block) {
|
||||
m_keeplist.push_back(block);
|
||||
if (mesh_grid.cell_size > 1) {
|
||||
// Block meshes are stored in the corner block of a chunk
|
||||
// (where all coordinate are divisible by the chunk size)
|
||||
// Add them to the de-dup set.
|
||||
shortlist.emplace(mesh_grid.getMeshPos(block_coord.X), mesh_grid.getMeshPos(block_coord.Y), mesh_grid.getMeshPos(block_coord.Z));
|
||||
// All other blocks we can grab and add to the keeplist right away.
|
||||
if (block) {
|
||||
m_keeplist.push_back(block);
|
||||
block->refGrab();
|
||||
}
|
||||
}
|
||||
else if (mesh) {
|
||||
// without mesh chunking we can add the block to the drawlist
|
||||
block->refGrab();
|
||||
m_drawlist.emplace(block_coord, block);
|
||||
}
|
||||
|
||||
// Decide which sides to traverse next or to block away
|
||||
|
@ -485,7 +493,7 @@ void ClientMap::updateDrawList()
|
|||
|
||||
g_profiler->avg("MapBlocks shortlist [#]", shortlist.size());
|
||||
|
||||
assert(m_drawlist.empty());
|
||||
assert(m_drawlist.empty() || shortlist.empty());
|
||||
for (auto pos : shortlist) {
|
||||
MapBlock * block = getBlockNoCreateNoEx(pos);
|
||||
if (block) {
|
||||
|
@ -612,6 +620,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
|
||||
auto is_frustum_culled = m_client->getCamera()->getFrustumCuller();
|
||||
|
||||
const MeshGrid mesh_grid = m_client->getMeshGrid();
|
||||
for (auto &i : m_drawlist) {
|
||||
v3s16 block_pos = i.first;
|
||||
MapBlock *block = i.second;
|
||||
|
@ -740,7 +749,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
material.TextureLayer[ShadowRenderer::TEXTURE_LAYER_SHADOW].Texture = nullptr;
|
||||
}
|
||||
|
||||
v3f block_wpos = intToFloat(descriptor.m_pos / 8 * 8 * MAP_BLOCKSIZE, BS);
|
||||
v3f block_wpos = intToFloat(mesh_grid.getMeshPos(descriptor.m_pos) * MAP_BLOCKSIZE, BS);
|
||||
m.setTranslation(block_wpos - offset);
|
||||
|
||||
driver->setTransform(video::ETS_WORLD, m);
|
||||
|
@ -978,6 +987,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver,
|
|||
return;
|
||||
}
|
||||
|
||||
const MeshGrid mesh_grid = m_client->getMeshGrid();
|
||||
for (const auto &i : m_drawlist_shadow) {
|
||||
// only process specific part of the list & break early
|
||||
++count;
|
||||
|
@ -1066,7 +1076,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver,
|
|||
++material_swaps;
|
||||
}
|
||||
|
||||
v3f block_wpos = intToFloat(descriptor.m_pos / 8 * 8 * MAP_BLOCKSIZE, BS);
|
||||
v3f block_wpos = intToFloat(mesh_grid.getMeshPos(descriptor.m_pos) * MAP_BLOCKSIZE, BS);
|
||||
m.setTranslation(block_wpos - offset);
|
||||
|
||||
driver->setTransform(video::ETS_WORLD, m);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue