diff options
Diffstat (limited to 'src/client/shadows')
-rw-r--r-- | src/client/shadows/dynamicshadowsrender.cpp | 25 | ||||
-rw-r--r-- | src/client/shadows/dynamicshadowsrender.h | 6 | ||||
-rw-r--r-- | src/client/shadows/shadowsshadercallbacks.cpp | 6 | ||||
-rw-r--r-- | src/client/shadows/shadowsshadercallbacks.h | 9 |
4 files changed, 41 insertions, 5 deletions
diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index 24adb21e2..262711221 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -32,7 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc., ShadowRenderer::ShadowRenderer(IrrlichtDevice *device, Client *client) : m_device(device), m_smgr(device->getSceneManager()), - m_driver(device->getVideoDriver()), m_client(client), m_current_frame(0) + m_driver(device->getVideoDriver()), m_client(client), m_current_frame(0), + m_perspective_bias_xy(0.8), m_perspective_bias_z(0.5) { m_shadows_supported = true; // assume shadows supported. We will check actual support in initialize m_shadows_enabled = true; @@ -59,6 +60,10 @@ ShadowRenderer::~ShadowRenderer() if (m_shadow_depth_cb) delete m_shadow_depth_cb; + if (m_shadow_depth_entity_cb) + delete m_shadow_depth_entity_cb; + if (m_shadow_depth_trans_cb) + delete m_shadow_depth_trans_cb; if (m_shadow_mix_cb) delete m_shadow_mix_cb; m_shadow_node_array.clear(); @@ -250,8 +255,13 @@ void ShadowRenderer::updateSMTextures() // Update SM incrementally: for (DirectionalLight &light : m_light_list) { // Static shader values. - m_shadow_depth_cb->MapRes = (f32)m_shadow_map_texture_size; - m_shadow_depth_cb->MaxFar = (f32)m_shadow_map_max_distance * BS; + 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; + cb->PerspectiveBiasXY = getPerspectiveBiasXY(); + cb->PerspectiveBiasZ = getPerspectiveBiasZ(); + } // set the Render Target // right now we can only render in usual RTT, not @@ -533,6 +543,8 @@ void ShadowRenderer::createShaders() if (depth_shader == -1) { // upsi, something went wrong loading shader. delete m_shadow_depth_cb; + m_shadow_depth_cb = nullptr; + m_shadows_enabled = false; m_shadows_supported = false; errorstream << "Error compiling shadow mapping shader." << std::endl; return; @@ -559,15 +571,19 @@ void ShadowRenderer::createShaders() errorstream << "Error shadow mapping fs shader not found." << std::endl; return; } + m_shadow_depth_entity_cb = new ShadowDepthShaderCB(); depth_shader_entities = gpu->addHighLevelShaderMaterial( readShaderFile(depth_shader_vs).c_str(), "vertexMain", video::EVST_VS_1_1, readShaderFile(depth_shader_fs).c_str(), "pixelMain", - video::EPST_PS_1_2, m_shadow_depth_cb); + video::EPST_PS_1_2, m_shadow_depth_entity_cb); if (depth_shader_entities == -1) { // upsi, something went wrong loading shader. + delete m_shadow_depth_entity_cb; + m_shadow_depth_entity_cb = nullptr; + m_shadows_enabled = false; m_shadows_supported = false; errorstream << "Error compiling shadow mapping shader (dynamic)." << std::endl; return; @@ -643,6 +659,7 @@ void ShadowRenderer::createShaders() if (depth_shader_trans == -1) { // upsi, something went wrong loading shader. delete m_shadow_depth_trans_cb; + m_shadow_depth_trans_cb = nullptr; m_shadow_map_colored = false; m_shadows_supported = false; errorstream << "Error compiling colored shadow mapping shader." << std::endl; diff --git a/src/client/shadows/dynamicshadowsrender.h b/src/client/shadows/dynamicshadowsrender.h index dc8f79c56..bbeb254b0 100644 --- a/src/client/shadows/dynamicshadowsrender.h +++ b/src/client/shadows/dynamicshadowsrender.h @@ -90,6 +90,9 @@ public: float getShadowStrength() const { return m_shadows_enabled ? m_shadow_strength : 0.0f; } float getTimeOfDay() const { return m_time_day; } + f32 getPerspectiveBiasXY() { return m_perspective_bias_xy; } + f32 getPerspectiveBiasZ() { return m_perspective_bias_z; } + private: video::ITexture *getSMTexture(const std::string &shadow_map_name, video::ECOLOR_FORMAT texture_format, @@ -131,6 +134,8 @@ private: 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 */ + f32 m_perspective_bias_xy; + f32 m_perspective_bias_z; video::ECOLOR_FORMAT m_texture_format{video::ECOLOR_FORMAT::ECF_R16F}; video::ECOLOR_FORMAT m_texture_format_color{video::ECOLOR_FORMAT::ECF_R16G16}; @@ -146,6 +151,7 @@ private: s32 mixcsm_shader{-1}; ShadowDepthShaderCB *m_shadow_depth_cb{nullptr}; + ShadowDepthShaderCB *m_shadow_depth_entity_cb{nullptr}; ShadowDepthShaderCB *m_shadow_depth_trans_cb{nullptr}; shadowScreenQuad *m_screen_quad{nullptr}; diff --git a/src/client/shadows/shadowsshadercallbacks.cpp b/src/client/shadows/shadowsshadercallbacks.cpp index 65a63f49c..51ea8aa93 100644 --- a/src/client/shadows/shadowsshadercallbacks.cpp +++ b/src/client/shadows/shadowsshadercallbacks.cpp @@ -33,4 +33,10 @@ void ShadowDepthShaderCB::OnSetConstants( m_max_far_setting.set(&MaxFar, services); s32 TextureId = 0; m_color_map_sampler_setting.set(&TextureId, services); + f32 bias0 = PerspectiveBiasXY; + m_perspective_bias0.set(&bias0, services); + f32 bias1 = 1.0f - bias0 + 1e-5f; + m_perspective_bias1.set(&bias1, services); + f32 zbias = PerspectiveBiasZ; + m_perspective_zbias.set(&zbias, services); } diff --git a/src/client/shadows/shadowsshadercallbacks.h b/src/client/shadows/shadowsshadercallbacks.h index 3549567c3..d00f59c37 100644 --- a/src/client/shadows/shadowsshadercallbacks.h +++ b/src/client/shadows/shadowsshadercallbacks.h @@ -30,7 +30,10 @@ public: m_light_mvp_setting("LightMVP"), m_map_resolution_setting("MapResolution"), m_max_far_setting("MaxFar"), - m_color_map_sampler_setting("ColorMapSampler") + m_color_map_sampler_setting("ColorMapSampler"), + m_perspective_bias0("xyPerspectiveBias0"), + m_perspective_bias1("xyPerspectiveBias1"), + m_perspective_zbias("zPerspectiveBias") {} void OnSetMaterial(const video::SMaterial &material) override {} @@ -39,10 +42,14 @@ public: s32 userData) override; f32 MaxFar{2048.0f}, MapRes{1024.0f}; + f32 PerspectiveBiasXY {0.9f}, PerspectiveBiasZ {0.5f}; private: CachedVertexShaderSetting<f32, 16> m_light_mvp_setting; CachedVertexShaderSetting<f32> m_map_resolution_setting; CachedVertexShaderSetting<f32> m_max_far_setting; CachedPixelShaderSetting<s32> m_color_map_sampler_setting; + CachedVertexShaderSetting<f32> m_perspective_bias0; + CachedVertexShaderSetting<f32> m_perspective_bias1; + CachedVertexShaderSetting<f32> m_perspective_zbias; }; |