]> git.lizzy.rs Git - minetest.git/commitdiff
Fix incorrect culling introduced by ##12710 (#12887)
authorlhofhansl <larsh@apache.org>
Fri, 28 Oct 2022 16:52:54 +0000 (09:52 -0700)
committerGitHub <noreply@github.com>
Fri, 28 Oct 2022 16:52:54 +0000 (09:52 -0700)
src/client/clientmap.cpp

index b74499ac31915a92db564ebc18559185dafb4d41..3b6a319f330b43b18bdf94c6d102fce1f59a1255 100644 (file)
@@ -259,11 +259,13 @@ void ClientMap::updateDrawList()
                        }
 
                        v3s16 block_coord = block->getPos();
-                       v3s16 block_position = block->getPosRelative() + MAP_BLOCKSIZE / 2;
-
-                       // First, perform a simple distance check, with a padding of one extra block.
+                       v3f mesh_sphere_center = intToFloat(block->getPosRelative(), BS)
+                                       + block->mesh->getBoundingSphereCenter();
+                       f32 mesh_sphere_radius = block->mesh->getBoundingRadius();
+                       // First, perform a simple distance check.
                        if (!m_control.range_all &&
-                                       block_position.getDistanceFrom(cam_pos_nodes) > m_control.wanted_range)
+                               mesh_sphere_center.getDistanceFrom(intToFloat(cam_pos_nodes, BS)) >
+                                       m_control.wanted_range * BS + mesh_sphere_radius)
                                continue; // Out of range, skip.
 
                        // Keep the block alive as long as it is in range.
@@ -274,9 +276,6 @@ void ClientMap::updateDrawList()
                        // Only do coarse culling here, to account for fast camera movement.
                        // This is needed because this function is not called every frame.
                        constexpr float frustum_cull_extra_radius = 300.0f;
-                       v3f mesh_sphere_center = intToFloat(block->getPosRelative(), BS)
-                                       + block->mesh->getBoundingSphereCenter();
-                       f32 mesh_sphere_radius = block->mesh->getBoundingRadius();
                        if (is_frustum_culled(mesh_sphere_center,
                                        mesh_sphere_radius + frustum_cull_extra_radius))
                                continue;