From ed26ed5a1f49fc66facd4a745d29441aba5a92c3 Mon Sep 17 00:00:00 2001 From: x2048 Date: Mon, 23 May 2022 23:45:18 +0200 Subject: Quantize light frustum calculations (#12357) * Quantize light frustum calculations Reduces shadow flicker * Fix function name to match conventions --- src/client/shadows/dynamicshadows.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/client') diff --git a/src/client/shadows/dynamicshadows.cpp b/src/client/shadows/dynamicshadows.cpp index ca2d3ce37..9f26ba94a 100644 --- a/src/client/shadows/dynamicshadows.cpp +++ b/src/client/shadows/dynamicshadows.cpp @@ -27,10 +27,24 @@ with this program; if not, write to the Free Software Foundation, Inc., using m4f = core::matrix4; +static v3f quantizeDirection(v3f direction, float step) +{ + + float yaw = std::atan2(direction.Z, direction.X); + float pitch = std::asin(direction.Y); // assume look is normalized + + yaw = std::floor(yaw / step) * step; + pitch = std::floor(pitch / step) * step; + + return v3f(std::cos(yaw)*std::cos(pitch), std::sin(pitch), std::sin(yaw)*std::cos(pitch)); +} + void DirectionalLight::createSplitMatrices(const Camera *cam) { + const float DISTANCE_STEP = BS * 2.0; // 2 meters v3f newCenter; v3f look = cam->getDirection(); + look = quantizeDirection(look, M_PI / 12.0); // 15 degrees // camera view tangents float tanFovY = tanf(cam->getFovY() * 0.5f); @@ -42,6 +56,10 @@ void DirectionalLight::createSplitMatrices(const Camera *cam) // adjusted camera positions v3f cam_pos_world = cam->getPosition(); + cam_pos_world = v3f( + floor(cam_pos_world.X / DISTANCE_STEP) * DISTANCE_STEP, + floor(cam_pos_world.Y / DISTANCE_STEP) * DISTANCE_STEP, + floor(cam_pos_world.Z / DISTANCE_STEP) * DISTANCE_STEP); v3f cam_pos_scene = v3f(cam_pos_world.X - cam->getOffset().X * BS, cam_pos_world.Y - cam->getOffset().Y * BS, cam_pos_world.Z - cam->getOffset().Z * BS); @@ -61,7 +79,7 @@ void DirectionalLight::createSplitMatrices(const Camera *cam) v3f boundVec = (cam_pos_scene + farCorner * sfFar) - center_scene; float radius = boundVec.getLength(); float length = radius * 3.0f; - v3f eye_displacement = direction * length; + v3f eye_displacement = quantizeDirection(direction, M_PI / 2880 /*15 seconds*/) * length; // we must compute the viewmat with the position - the camera offset // but the future_frustum position must be the actual world position -- cgit v1.2.3 From 5d26ac00883eed2f522e6e0fa3adcd7081814c9b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 9 May 2022 19:28:27 +0200 Subject: Improve code in mapblock_mesh.cpp a bit --- src/client/mapblock_mesh.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/client') diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 965dd5e29..3be9e13b8 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -1349,30 +1349,22 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): scene::SMeshBuffer *buf = new scene::SMeshBuffer(); buf->Material = material; - switch (p.layer.material_type) { - // list of transparent materials taken from tile.h - case TILE_MATERIAL_ALPHA: - case TILE_MATERIAL_LIQUID_TRANSPARENT: - case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT: - { - buf->append(&p.vertices[0], p.vertices.size(), - &p.indices[0], 0); - - MeshTriangle t; - t.buffer = buf; - for (u32 i = 0; i < p.indices.size(); i += 3) { - t.p1 = p.indices[i]; - t.p2 = p.indices[i + 1]; - t.p3 = p.indices[i + 2]; - t.updateAttributes(); - m_transparent_triangles.push_back(t); - } + if (p.layer.isTransparent()) { + buf->append(&p.vertices[0], p.vertices.size(), nullptr, 0); + + MeshTriangle t; + t.buffer = buf; + m_transparent_triangles.reserve(p.indices.size() / 3); + for (u32 i = 0; i < p.indices.size(); i += 3) { + t.p1 = p.indices[i]; + t.p2 = p.indices[i + 1]; + t.p3 = p.indices[i + 2]; + t.updateAttributes(); + m_transparent_triangles.push_back(t); } - break; - default: + } else { buf->append(&p.vertices[0], p.vertices.size(), &p.indices[0], p.indices.size()); - break; } mesh->addMeshBuffer(buf); buf->drop(); -- cgit v1.2.3 From ef22c0206f225dbccd67bff9fb888867c63039b3 Mon Sep 17 00:00:00 2001 From: x2048 Date: Thu, 26 May 2022 22:28:34 +0200 Subject: Force-update shadows when the world is changed (#12364) --- src/client/client.cpp | 9 ++++++++- src/client/shadows/dynamicshadowsrender.cpp | 14 +++++++++----- src/client/shadows/dynamicshadowsrender.h | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/client') diff --git a/src/client/client.cpp b/src/client/client.cpp index 8ab96b7d1..e078dc530 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -530,6 +530,7 @@ void Client::step(float dtime) { int num_processed_meshes = 0; std::vector blocks_to_ack; + bool force_update_shadows = false; while (!m_mesh_update_thread.m_queue_out.empty()) { num_processed_meshes++; @@ -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; @@ -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(); } /* diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index c13cfe252..b8ceeb623 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -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; @@ -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, @@ -298,7 +298,7 @@ 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); @@ -306,6 +306,7 @@ void ShadowRenderer::updateSMTextures() for (DirectionalLight &light : m_light_list) light.commitFrustum(); } + m_force_update_shadow_map = false; } } @@ -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; } } diff --git a/src/client/shadows/dynamicshadowsrender.h b/src/client/shadows/dynamicshadowsrender.h index 0e4ef6b70..2e3b58f6f 100644 --- a/src/client/shadows/dynamicshadowsrender.h +++ b/src/client/shadows/dynamicshadowsrender.h @@ -74,6 +74,7 @@ public: 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() @@ -131,6 +132,7 @@ private: 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; -- cgit v1.2.3 From 5cd7b0c6e4551fd53171fba8b30ac9f0a4e13a36 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 26 May 2022 17:41:23 +0200 Subject: Remove remains of video mode querying --- doc/minetest.6 | 2 -- src/client/renderingengine.cpp | 15 --------------- src/client/renderingengine.h | 1 - 3 files changed, 18 deletions(-) (limited to 'src/client') diff --git a/doc/minetest.6 b/doc/minetest.6 index 6a3601f80..27a3d0024 100644 --- a/doc/minetest.6 +++ b/doc/minetest.6 @@ -92,8 +92,6 @@ Set password from contents of file .B \-\-random\-input Enable random user input, for testing (client only) .TP -.B \-\-videomodes -List available video modes (client only) .TP .B \-\-speedtests Run speed tests diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 455d5e538..7afca4500 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -638,25 +638,10 @@ float RenderingEngine::getDisplayDensity() #endif -v2u32 RenderingEngine::getDisplaySize() -{ - IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL); - - core::dimension2d deskres = - nulldevice->getVideoModeList()->getDesktopResolution(); - nulldevice->drop(); - - return deskres; -} - #else // __ANDROID__ float RenderingEngine::getDisplayDensity() { return porting::getDisplayDensity(); } -v2u32 RenderingEngine::getDisplaySize() -{ - return porting::getDisplaySize(); -} #endif // __ANDROID__ diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 6f104bba9..38420010f 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -55,7 +55,6 @@ public: static const VideoDriverInfo &getVideoDriverInfo(irr::video::E_DRIVER_TYPE type); static float getDisplayDensity(); - static v2u32 getDisplaySize(); bool setupTopLevelWindow(const std::string &name); void setupTopLevelXorgWindow(const std::string &name); -- cgit v1.2.3 From 85c824ed136269ee3ee0b650406ce80c8a60c014 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 26 May 2022 20:47:16 +0200 Subject: Make sure real disconnect reason isn't overwritten bug introduced in 2f32044273d107e82fb1c35d4a0f616fa480cdf0 --- src/client/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client') diff --git a/src/client/client.cpp b/src/client/client.cpp index e078dc530..93a403e81 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -803,7 +803,7 @@ void Client::deletingPeer(con::Peer *peer, bool timeout) m_access_denied = true; if (timeout) m_access_denied_reason = gettext("Connection timed out."); - else + else if (m_access_denied_reason.empty()) m_access_denied_reason = gettext("Connection aborted (protocol error?)."); } -- cgit v1.2.3