From eb8b44981754ba5f13be3caa0de63b18937554b4 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 24 Feb 2025 18:45:23 +0100 Subject: [PATCH] Fix shadow performance regression due to force update broken by: b861f0c5c59546b64e937fdf384634175df4a372 --- src/client/shadows/dynamicshadows.h | 1 + src/client/shadows/dynamicshadowsrender.cpp | 18 ++++++------------ src/client/shadows/dynamicshadowsrender.h | 1 + 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/client/shadows/dynamicshadows.h b/src/client/shadows/dynamicshadows.h index 640a5479f..70135ea69 100644 --- a/src/client/shadows/dynamicshadows.h +++ b/src/client/shadows/dynamicshadows.h @@ -85,6 +85,7 @@ public: return mapRes; } + /// If true, shadow map needs to be invalidated due to frustum change bool should_update_map_shadow{true}; void commitFrustum(); diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index b213cf12a..9898b08e6 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -254,17 +254,14 @@ void ShadowRenderer::updateSMTextures() if (!m_shadow_node_array.empty()) { bool reset_sm_texture = false; - // detect if SM should be regenerated + // clear texture if requested for (DirectionalLight &light : m_light_list) { - if (light.should_update_map_shadow) - m_force_update_shadow_map = true; + reset_sm_texture |= light.should_update_map_shadow; light.should_update_map_shadow = false; } - if (m_force_update_shadow_map) { + if (reset_sm_texture || m_force_update_shadow_map) m_current_frame = 0; - reset_sm_texture = true; - } video::ITexture* shadowMapTargetTexture = shadowMapClientMapFuture; if (shadowMapTargetTexture == nullptr) @@ -273,7 +270,7 @@ void ShadowRenderer::updateSMTextures() // Update SM incrementally: for (DirectionalLight &light : m_light_list) { // Static shader values. - for (auto cb : {m_shadow_depth_cb, m_shadow_depth_entity_cb, m_shadow_depth_trans_cb}) + for (auto cb : {m_shadow_depth_cb, m_shadow_depth_entity_cb, m_shadow_depth_trans_cb}) { if (cb) { cb->MapRes = (f32)m_shadow_map_texture_size; cb->MaxFar = (f32)m_shadow_map_max_distance * BS; @@ -281,12 +278,9 @@ void ShadowRenderer::updateSMTextures() cb->PerspectiveBiasZ = getPerspectiveBiasZ(); cb->CameraPos = light.getFuturePlayerPos(); } + } - // set the Render Target - // right now we can only render in usual RTT, not - // Depth texture is available in irrlicth maybe we - // should put some gl* fn here - + // Note that force_update means we're drawing everything one go. if (m_current_frame < m_map_shadow_update_frames || m_force_update_shadow_map) { m_driver->setRenderTarget(shadowMapTargetTexture, reset_sm_texture, true, diff --git a/src/client/shadows/dynamicshadowsrender.h b/src/client/shadows/dynamicshadowsrender.h index 9bc4f6b94..5854dc4ed 100644 --- a/src/client/shadows/dynamicshadowsrender.h +++ b/src/client/shadows/dynamicshadowsrender.h @@ -68,6 +68,7 @@ public: void removeNodeFromShadowList(scene::ISceneNode *node); void update(video::ITexture *outputTarget = nullptr); + /// Force shadow map to be re-drawn in one go next frame void setForceUpdateShadowMap() { m_force_update_shadow_map = true; } void drawDebug();