]> git.lizzy.rs Git - minetest.git/commitdiff
Shadow list improvements (#12898)
authorx2048 <codeforsmile@gmail.com>
Wed, 26 Oct 2022 20:26:09 +0000 (22:26 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Oct 2022 20:26:09 +0000 (22:26 +0200)
* Remove redundant checks when attaching SM texture to entities.
  Some of the checks were broken, leading to crashes when shadow intensity is set to 0
* Avoid memory leak in shadow casters list when wield mesh changes item stacks

src/client/shadows/dynamicshadowsrender.cpp
src/client/wieldmesh.cpp

index fd3841d2d87719ca2bea048c6e60aaa6226cf688..e9b2053e3f856c6565f1a3d5c6b8b175e989fd1d 100644 (file)
@@ -107,8 +107,7 @@ void ShadowRenderer::disable()
        }
 
        for (auto node : m_shadow_node_array)
-               if (node.shadowMode & E_SHADOW_MODE::ESM_RECEIVE)
-                       node.node->setMaterialTexture(TEXTURE_LAYER_SHADOW, nullptr);
+               node.node->setMaterialTexture(TEXTURE_LAYER_SHADOW, nullptr);
 }
 
 void ShadowRenderer::initialize()
@@ -180,8 +179,7 @@ void ShadowRenderer::addNodeToShadowList(
        if (!node)
                return;
        m_shadow_node_array.emplace_back(node, shadowMode);
-       if (shadowMode == ESM_RECEIVE || shadowMode == ESM_BOTH)
-               node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
+       node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
 }
 
 void ShadowRenderer::removeNodeFromShadowList(scene::ISceneNode *node)
@@ -258,8 +256,7 @@ void ShadowRenderer::updateSMTextures()
                assert(shadowMapTextureFinal != nullptr);
 
                for (auto &node : m_shadow_node_array)
-                       if (node.shadowMode == ESM_RECEIVE || node.shadowMode == ESM_BOTH)
-                               node.node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
+                       node.node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
        }
 
        if (!m_shadow_node_array.empty() && !m_light_list.empty()) {
index d546d52ff11789adcdbdda51f3ce794a3009d2b5..155b5ecc4333733023ae56fa6ae0e4d8da33c3b2 100644 (file)
@@ -223,6 +223,11 @@ WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id, bool l
        dummymesh->drop(); // m_meshnode grabbed it
 
        m_shadow = RenderingEngine::get_shadow_renderer();
+
+       if (m_shadow) {
+               // Add mesh to shadow caster
+               m_shadow->addNodeToShadowList(m_meshnode);
+       }
 }
 
 WieldMeshSceneNode::~WieldMeshSceneNode()
@@ -230,8 +235,8 @@ WieldMeshSceneNode::~WieldMeshSceneNode()
        sanity_check(g_extrusion_mesh_cache);
 
        // Remove node from shadow casters. m_shadow might be an invalid pointer!
-       if (auto shadow = RenderingEngine::get_shadow_renderer())
-               shadow->removeNodeFromShadowList(m_meshnode);
+       if (m_shadow)
+               m_shadow->removeNodeFromShadowList(m_meshnode);
 
        if (g_extrusion_mesh_cache->drop())
                g_extrusion_mesh_cache = nullptr;
@@ -552,11 +557,6 @@ void WieldMeshSceneNode::changeToMesh(scene::IMesh *mesh)
        // need to normalize normals when lighting is enabled (because of setScale())
        m_meshnode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, m_lighting);
        m_meshnode->setVisible(true);
-
-       if (m_shadow) {
-               // Add mesh to shadow caster
-               m_shadow->addNodeToShadowList(m_meshnode);
-       }
 }
 
 void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)