aboutsummaryrefslogtreecommitdiff
path: root/src/client/clientmap.cpp
diff options
context:
space:
mode:
authorlhofhansl <larsh@apache.org>2023-02-16 15:43:08 -1000
committerGitHub <noreply@github.com>2023-02-16 15:43:08 -1000
commit2a8becd650a8adaa86fd7f76122ea75f11f49dad (patch)
tree39d4af0be1762c632ef0edaf27bad143793df479 /src/client/clientmap.cpp
parent4cd6b773bb5de2594c682ae7e5793c80ad6a22e6 (diff)
downloadminetest-2a8becd650a8adaa86fd7f76122ea75f11f49dad.tar.xz
Add mesh-holding blocks to shadow drawlist. (#13203)
When mesh chunking and shadows are enabled, make sure that the mesh-holding blocks are added to the shadow drawlist. Otherwise those portions of the shadows will not be rendered.
Diffstat (limited to 'src/client/clientmap.cpp')
-rw-r--r--src/client/clientmap.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp
index af77e5ab2..39c811b85 100644
--- a/src/client/clientmap.cpp
+++ b/src/client/clientmap.cpp
@@ -1121,6 +1121,9 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
// Number of blocks occlusion culled
u32 blocks_occlusion_culled = 0;
+ std::set<v3s16> shortlist;
+ MeshGrid mesh_grid = m_client->getMeshGrid();
+
for (auto &sector_it : m_sectors) {
MapSector *sector = sector_it.second;
if (!sector)
@@ -1134,8 +1137,8 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
Loop through blocks in sector
*/
for (MapBlock *block : sectorblocks) {
- if (!block->mesh) {
- // Ignore if mesh doesn't exist
+ if (mesh_grid.cell_size == 1 && !block->mesh) {
+ // fast out in the case of no mesh chunking
continue;
}
@@ -1144,6 +1147,17 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
if (projection.getDistanceFrom(block_pos) > radius)
continue;
+ 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->getPos()));
+ }
+ if (!block->mesh) {
+ // Ignore if mesh doesn't exist
+ continue;
+ }
+
blocks_in_range_with_mesh++;
// This block is in range. Reset usage timer.
@@ -1155,6 +1169,12 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
}
}
}
+ for (auto pos : shortlist) {
+ MapBlock * block = getBlockNoCreateNoEx(pos);
+ if (block && block->mesh && m_drawlist_shadow.emplace(pos, block).second) {
+ block->refGrab();
+ }
+ }
g_profiler->avg("SHADOW MapBlock meshes in range [#]", blocks_in_range_with_mesh);
g_profiler->avg("SHADOW MapBlocks occlusion culled [#]", blocks_occlusion_culled);