mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
8x block meshes (#13133)
Reduce the number of drawcalls by generating a mesh per 8 blocks (2x2x2). Only blocks with even coordinates (lowest bit set to 0) will get a mesh. Note: This also removes the old 'loops' algorithm for building the draw list, because it produces visual artifacts and cannot be made compatible with the approach of having a mesh for every 8th block without hurting performance. Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com> Co-authored-by: Lars <larsh@apache.org> Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
cded6a3945
commit
69fc206109
14 changed files with 266 additions and 118 deletions
|
@ -298,6 +298,8 @@ void ClientMap::updateDrawList()
|
|||
blocks_to_consider.push(camera_block);
|
||||
blocks_seen.getChunk(camera_block).getBits(camera_block) = 0x07; // mark all sides as visible
|
||||
|
||||
std::set<v3s16> shortlist;
|
||||
|
||||
// Recursively walk the space and pick mapblocks for drawing
|
||||
while (blocks_to_consider.size() > 0) {
|
||||
|
||||
|
@ -369,11 +371,13 @@ void ClientMap::updateDrawList()
|
|||
continue;
|
||||
}
|
||||
|
||||
// The block is visible, add to the draw list
|
||||
if (mesh) {
|
||||
// Add to set
|
||||
// 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 drawlist right away.
|
||||
if (block && m_drawlist.emplace(block_coord, block).second) {
|
||||
// only grab the ref if the block exists and was not in the list
|
||||
block->refGrab();
|
||||
m_drawlist[block_coord] = block;
|
||||
}
|
||||
|
||||
// Decide which sides to traverse next or to block away
|
||||
|
@ -474,6 +478,16 @@ void ClientMap::updateDrawList()
|
|||
}
|
||||
}
|
||||
|
||||
g_profiler->avg("MapBlocks shortlist [#]", shortlist.size());
|
||||
|
||||
for (auto pos : shortlist) {
|
||||
MapBlock * block = getBlockNoCreateNoEx(pos);
|
||||
if (block && m_drawlist.emplace(pos, block).second) {
|
||||
// only grab the ref if the block exists and was not in the list
|
||||
block->refGrab();
|
||||
}
|
||||
}
|
||||
|
||||
g_profiler->avg("MapBlocks occlusion culled [#]", blocks_occlusion_culled);
|
||||
g_profiler->avg("MapBlocks sides skipped [#]", sides_skipped);
|
||||
g_profiler->avg("MapBlocks examined [#]", blocks_visited);
|
||||
|
@ -597,7 +611,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
MapBlock *block = i.second;
|
||||
MapBlockMesh *block_mesh = block->mesh;
|
||||
|
||||
// If the mesh of the block happened to get deleted, ignore it
|
||||
// Meshes are only stored every 8-th block (where all coordinates are even),
|
||||
// but we keep all the visible blocks in the draw list to prevent client
|
||||
// from dropping them.
|
||||
// On top of that, in some cases block mesh can be removed
|
||||
// before the block is removed from the draw list.
|
||||
if (!block_mesh)
|
||||
continue;
|
||||
|
||||
|
@ -720,7 +738,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
material.TextureLayer[ShadowRenderer::TEXTURE_LAYER_SHADOW].Texture = nullptr;
|
||||
}
|
||||
|
||||
v3f block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, BS);
|
||||
v3f block_wpos = intToFloat(descriptor.m_pos / 8 * 8 * MAP_BLOCKSIZE, BS);
|
||||
m.setTranslation(block_wpos - offset);
|
||||
|
||||
driver->setTransform(video::ETS_WORLD, m);
|
||||
|
@ -1046,7 +1064,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver,
|
|||
++material_swaps;
|
||||
}
|
||||
|
||||
v3f block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, BS);
|
||||
v3f block_wpos = intToFloat(descriptor.m_pos / 8 * 8 * MAP_BLOCKSIZE, BS);
|
||||
m.setTranslation(block_wpos - offset);
|
||||
|
||||
driver->setTransform(video::ETS_WORLD, m);
|
||||
|
@ -1133,6 +1151,11 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
|
|||
g_profiler->avg("SHADOW MapBlocks loaded [#]", blocks_loaded);
|
||||
}
|
||||
|
||||
void ClientMap::reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks)
|
||||
{
|
||||
g_profiler->avg("CM::reportMetrics loaded blocks [#]", all_blocks);
|
||||
}
|
||||
|
||||
void ClientMap::updateTransparentMeshBuffers()
|
||||
{
|
||||
ScopeProfiler sp(g_profiler, "CM::updateTransparentMeshBuffers", SPT_AVG);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue