aboutsummaryrefslogtreecommitdiff
path: root/src/client/game.cpp
diff options
context:
space:
mode:
authorx2048 <codeforsmile@gmail.com>2021-07-25 12:36:23 +0200
committerGitHub <noreply@github.com>2021-07-25 12:36:23 +0200
commitbf3acbf388406f736286d990adb5f35a9023c390 (patch)
tree9fdff755e37253580c222ff768802a6b0170be10 /src/client/game.cpp
parentff2d2a6e93d75d24b3f69f2b3690bcac6440961e (diff)
downloadminetest-bf3acbf388406f736286d990adb5f35a9023c390.tar.gz
minetest-bf3acbf388406f736286d990adb5f35a9023c390.tar.bz2
minetest-bf3acbf388406f736286d990adb5f35a9023c390.zip
Distribute shadow map update over multiple frames to reduce stutter (#11422)
Reduces stutter and freezes when playing. * Maintains double SM and SM Color textures * Light frustum update triggers incremental generation of shadow map into secondary 'future' textures. * Every incremental update renders a portion of the shadow draw list (split equally). * After defined number of frames (currently, 4), 'future' and 'current' textures are swapped, and DirectionalLight 'commits' the new frustum to use when rendering shadows on screen. Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/client/game.cpp')
-rw-r--r--src/client/game.cpp17
1 files changed, 3 insertions, 14 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 85dd8f4bb..6fc57c8cc 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -609,7 +609,6 @@ struct GameRunData {
float jump_timer;
float damage_flash;
float update_draw_list_timer;
- float update_shadows_timer;
f32 fog_range;
@@ -3881,10 +3880,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
changed much
*/
runData.update_draw_list_timer += dtime;
- runData.update_shadows_timer += dtime;
float update_draw_list_delta = 0.2f;
- bool draw_list_updated = false;
v3f camera_direction = camera->getDirection();
if (runData.update_draw_list_timer >= update_draw_list_delta
@@ -3894,18 +3891,10 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
runData.update_draw_list_timer = 0;
client->getEnv().getClientMap().updateDrawList();
runData.update_draw_list_last_cam_dir = camera_direction;
- draw_list_updated = true;
}
- if (ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer()) {
- update_draw_list_delta = shadow->getUpdateDelta();
-
- if (m_camera_offset_changed ||
- (runData.update_shadows_timer > update_draw_list_delta &&
- (!draw_list_updated || shadow->getDirectionalLightCount() == 0))) {
- runData.update_shadows_timer = 0;
- updateShadows();
- }
+ if (RenderingEngine::get_shadow_renderer()) {
+ updateShadows();
}
m_game_ui->update(*stats, client, draw_control, cam, runData.pointed_old, gui_chat_console, dtime);
@@ -4062,7 +4051,7 @@ void Game::updateShadows()
shadow->getDirectionalLight().setDirection(sun_pos);
shadow->setTimeOfDay(in_timeofday);
- shadow->getDirectionalLight().update_frustum(camera, client);
+ shadow->getDirectionalLight().update_frustum(camera, client, m_camera_offset_changed);
}
/****************************************************************************