Skip to content

Commit

Permalink
Force-update shadows when the world is changed (minetest#12364)
Browse files Browse the repository at this point in the history
  • Loading branch information
x2048 committed May 26, 2022
1 parent 8b74257 commit ef22c02
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ void Client::step(float dtime)
{
int num_processed_meshes = 0;
std::vector<v3s16> blocks_to_ack;
bool force_update_shadows = false;
while (!m_mesh_update_thread.m_queue_out.empty())
{
num_processed_meshes++;
Expand All @@ -556,9 +557,11 @@ void Client::step(float dtime)

if (is_empty)
delete r.mesh;
else
else {
// Replace with the new mesh
block->mesh = r.mesh;
force_update_shadows = true;
}
}
} else {
delete r.mesh;
Expand All @@ -583,6 +586,10 @@ void Client::step(float dtime)

if (num_processed_meshes > 0)
g_profiler->graphAdd("num_processed_meshes", num_processed_meshes);

auto shadow_renderer = RenderingEngine::get_shadow_renderer();
if (shadow_renderer && force_update_shadows)
shadow_renderer->setForceUpdateShadowMap();
}

/*
Expand Down
14 changes: 9 additions & 5 deletions src/client/shadows/dynamicshadowsrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void ShadowRenderer::updateSMTextures()

// detect if SM should be regenerated
for (DirectionalLight &light : m_light_list) {
if (light.should_update_map_shadow) {
if (light.should_update_map_shadow || m_force_update_shadow_map) {
light.should_update_map_shadow = false;
m_current_frame = 0;
reset_sm_texture = true;
Expand Down Expand Up @@ -271,14 +271,14 @@ void ShadowRenderer::updateSMTextures()
// should put some gl* fn here


if (m_current_frame < m_map_shadow_update_frames) {
if (m_current_frame < m_map_shadow_update_frames || m_force_update_shadow_map) {
m_driver->setRenderTarget(shadowMapTargetTexture, reset_sm_texture, true,
video::SColor(255, 255, 255, 255));
renderShadowMap(shadowMapTargetTexture, light);

// Render transparent part in one pass.
// This is also handled in ClientMap.
if (m_current_frame == m_map_shadow_update_frames - 1) {
if (m_current_frame == m_map_shadow_update_frames - 1 || m_force_update_shadow_map) {
if (m_shadow_map_colored) {
m_driver->setRenderTarget(0, false, false);
m_driver->setRenderTarget(shadowMapTextureColors,
Expand All @@ -298,14 +298,15 @@ void ShadowRenderer::updateSMTextures()
++m_current_frame;

// pass finished, swap textures and commit light changes
if (m_current_frame == m_map_shadow_update_frames) {
if (m_current_frame == m_map_shadow_update_frames || m_force_update_shadow_map) {
if (shadowMapClientMapFuture != nullptr)
std::swap(shadowMapClientMapFuture, shadowMapClientMap);

// Let all lights know that maps are updated
for (DirectionalLight &light : m_light_list)
light.commitFrustum();
}
m_force_update_shadow_map = false;
}
}

Expand Down Expand Up @@ -432,7 +433,10 @@ void ShadowRenderer::renderShadowMap(video::ITexture *target,
m_driver->setTransform(video::ETS_WORLD,
map_node->getAbsoluteTransformation());

map_node->renderMapShadows(m_driver, material, pass, m_current_frame, m_map_shadow_update_frames);
int frame = m_force_update_shadow_map ? 0 : m_current_frame;
int total_frames = m_force_update_shadow_map ? 1 : m_map_shadow_update_frames;

map_node->renderMapShadows(m_driver, material, pass, frame, total_frames);
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/client/shadows/dynamicshadowsrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ShadowRenderer
void removeNodeFromShadowList(scene::ISceneNode *node);

void update(video::ITexture *outputTarget = nullptr);
void setForceUpdateShadowMap() { m_force_update_shadow_map = true; }
void drawDebug();

video::ITexture *get_texture()
Expand Down Expand Up @@ -131,6 +132,7 @@ class ShadowRenderer
bool m_shadows_enabled;
bool m_shadows_supported;
bool m_shadow_map_colored;
bool m_force_update_shadow_map;
u8 m_map_shadow_update_frames; /* Use this number of frames to update map shaodw */
u8 m_current_frame{0}; /* Current frame */
f32 m_perspective_bias_xy;
Expand Down

0 comments on commit ef22c02

Please sign in to comment.