diff options
author | x2048 <codeforsmile@gmail.com> | 2022-04-14 22:49:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-14 22:49:30 +0200 |
commit | a5d29fa1d4bc6849d7a6529edc522accac8219d2 (patch) | |
tree | 16643a9fcfeef12802fb867803a7de35e93d649f /src/client | |
parent | 9aabd911eb57a5ddef72dd9b7c96f5cca1bd258e (diff) | |
download | minetest-a5d29fa1d4bc6849d7a6529edc522accac8219d2.tar.gz minetest-a5d29fa1d4bc6849d7a6529edc522accac8219d2.tar.bz2 minetest-a5d29fa1d4bc6849d7a6529edc522accac8219d2.zip |
Implement shadow offsets for the new SM distortion function (#12191)
* Move shadow position calculation to vertex shaders
* Animate entire scene before rendering shadows to prevent lagging of shadows
* Remove unnecessary use of PolygonOffsetFactor
* Apply normal offset to both nodes and objects
* Rename getPerspectiveFactor -> applyPerspectiveDistortion
* Remove perspective distortion from fragment shaders
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/render/core.cpp | 5 | ||||
-rw-r--r-- | src/client/shadows/dynamicshadows.h | 8 | ||||
-rw-r--r-- | src/client/shadows/dynamicshadowsrender.cpp | 13 |
3 files changed, 12 insertions, 14 deletions
diff --git a/src/client/render/core.cpp b/src/client/render/core.cpp index c67f297c4..55cc4e490 100644 --- a/src/client/render/core.cpp +++ b/src/client/render/core.cpp @@ -76,8 +76,11 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_min draw_wield_tool = _draw_wield_tool; draw_crosshair = _draw_crosshair; - if (shadow_renderer) + if (shadow_renderer) { + // This is necessary to render shadows for animations correctly + smgr->getRootSceneNode()->OnAnimate(device->getTimer()->getTime()); shadow_renderer->update(); + } beforeDraw(); drawAll(); diff --git a/src/client/shadows/dynamicshadows.h b/src/client/shadows/dynamicshadows.h index 70574aa6c..6e9d96b15 100644 --- a/src/client/shadows/dynamicshadows.h +++ b/src/client/shadows/dynamicshadows.h @@ -69,12 +69,18 @@ public: const core::matrix4 &getFutureProjectionMatrix() const; core::matrix4 getViewProjMatrix(); - /// Gets the light's far value. + /// Gets the light's maximum far value, i.e. the shadow boundary f32 getMaxFarValue() const { return farPlane * BS; } + /// Gets the current far value of the light + f32 getFarValue() const + { + return shadow_frustum.zFar; + } + /// Gets the light's color. const video::SColorf &getLightColor() const diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index 1dfc90d1c..a008c3e06 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -143,7 +143,7 @@ size_t ShadowRenderer::getDirectionalLightCount() const f32 ShadowRenderer::getMaxShadowFar() const { if (!m_light_list.empty()) { - float zMax = m_light_list[0].getMaxFarValue(); + float zMax = m_light_list[0].getFarValue(); return zMax; } return 0.0f; @@ -418,10 +418,6 @@ void ShadowRenderer::renderShadowMap(video::ITexture *target, material.BackfaceCulling = false; material.FrontfaceCulling = true; - material.PolygonOffsetFactor = 4.0f; - material.PolygonOffsetDirection = video::EPO_BACK; - //material.PolygonOffsetDepthBias = 1.0f/4.0f; - //material.PolygonOffsetSlopeScale = -1.f; if (m_shadow_map_colored && pass != scene::ESNRP_SOLID) { material.MaterialType = (video::E_MATERIAL_TYPE) depth_shader_trans; @@ -431,9 +427,6 @@ void ShadowRenderer::renderShadowMap(video::ITexture *target, material.BlendOperation = video::EBO_MIN; } - // FIXME: I don't think this is needed here - map_node->OnAnimate(m_device->getTimer()->getTime()); - m_driver->setTransform(video::ETS_WORLD, map_node->getAbsoluteTransformation()); @@ -479,10 +472,6 @@ void ShadowRenderer::renderShadowObjects( current_mat.BackfaceCulling = true; current_mat.FrontfaceCulling = false; - current_mat.PolygonOffsetFactor = 1.0f/2048.0f; - current_mat.PolygonOffsetDirection = video::EPO_BACK; - //current_mat.PolygonOffsetDepthBias = 1.0 * 2.8e-6; - //current_mat.PolygonOffsetSlopeScale = -1.f; } m_driver->setTransform(video::ETS_WORLD, |