1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

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>
This commit is contained in:
x2048 2021-07-25 12:36:23 +02:00 committed by GitHub
parent ff2d2a6e93
commit bf3acbf388
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 224 additions and 72 deletions

View file

@ -64,7 +64,6 @@ public:
size_t getDirectionalLightCount() const;
f32 getMaxShadowFar() const;
float getUpdateDelta() const;
/// Adds a shadow to the scene node.
/// The shadow mode can be ESM_BOTH, or ESM_RECEIVE.
/// ESM_BOTH casts and receives shadows
@ -101,6 +100,7 @@ private:
scene::ESNRP_SOLID);
void renderShadowObjects(video::ITexture *target, DirectionalLight &light);
void mixShadowsQuad();
void updateSMTextures();
// a bunch of variables
IrrlichtDevice *m_device{nullptr};
@ -108,6 +108,7 @@ private:
video::IVideoDriver *m_driver{nullptr};
Client *m_client{nullptr};
video::ITexture *shadowMapClientMap{nullptr};
video::ITexture *shadowMapClientMapFuture{nullptr};
video::ITexture *shadowMapTextureFinal{nullptr};
video::ITexture *shadowMapTextureDynamicObjects{nullptr};
video::ITexture *shadowMapTextureColors{nullptr};
@ -120,11 +121,12 @@ private:
float m_shadow_map_max_distance;
float m_shadow_map_texture_size;
float m_time_day{0.0f};
float m_update_delta;
int m_shadow_samples;
bool m_shadow_map_texture_32bit;
bool m_shadows_enabled;
bool m_shadow_map_colored;
u8 m_map_shadow_update_frames; /* Use this number of frames to update map shaodw */
u8 m_current_frame{0}; /* Current frame */
video::ECOLOR_FORMAT m_texture_format{video::ECOLOR_FORMAT::ECF_R16F};
video::ECOLOR_FORMAT m_texture_format_color{video::ECOLOR_FORMAT::ECF_R16G16};
@ -135,6 +137,7 @@ private:
std::string readShaderFile(const std::string &path);
s32 depth_shader{-1};
s32 depth_shader_entities{-1};
s32 depth_shader_trans{-1};
s32 mixcsm_shader{-1};