From a27362de6a66692b191f8db0eea13f8d9302cef6 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 16 Oct 2021 19:21:53 +0200 Subject: Disable dynamic shadows for the 5.5.0 release The dynamic shadows are yet not in the desired state to justify the inclusion into version 5.5.0. A stable release is long overdue, hence this allows fixes to continue in 5.6.0-dev to finally release an acceptable version of the dynamic shadows feature. Reverting this commit is highly recommended to proceed in development. --- src/client/shader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client/shader.cpp') diff --git a/src/client/shader.cpp b/src/client/shader.cpp index dc9e9ae6d..c04a25862 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -733,7 +733,7 @@ ShaderInfo ShaderSource::generateShader(const std::string &name, shaders_header << "#define FOG_START " << core::clamp(g_settings->getFloat("fog_start"), 0.0f, 0.99f) << "\n"; - if (g_settings->getBool("enable_dynamic_shadows")) { + if (false && g_settings->getBool("enable_dynamic_shadows")) { shaders_header << "#define ENABLE_DYNAMIC_SHADOWS 1\n"; if (g_settings->getBool("shadow_map_color")) shaders_header << "#define COLORED_SHADOWS 1\n"; -- cgit v1.2.3 From c61998bd2000427b96fc506edffa9fa4e27a1a9b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 31 Jan 2022 21:48:14 +0000 Subject: Revert "Disable dynamic shadows for the 5.5.0 release" (#12032) --- builtin/mainmenu/tab_settings.lua | 14 +++++------ builtin/settingtypes.txt | 52 +++++++++++++++++++++++++++++++++++++++ src/client/mapblock_mesh.cpp | 2 +- src/client/render/core.cpp | 2 +- src/client/renderingengine.h | 4 +-- src/client/shader.cpp | 2 +- src/client/sky.cpp | 2 +- 7 files changed, 65 insertions(+), 13 deletions(-) (limited to 'src/client/shader.cpp') diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 700b7390f..42f7f8daf 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -218,10 +218,10 @@ local function formspec(tabview, name, tabdata) "checkbox[8.25,1.5;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";" .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" .. "checkbox[8.25,2;cb_waving_plants;" .. fgettext("Waving Plants") .. ";" - .. dump(core.settings:get_bool("enable_waving_plants")) .. "]" - --"label[8.25,3.0;" .. fgettext("Dynamic shadows: ") .. "]" .. - --"dropdown[8.25,3.5;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";" - -- .. getSettingIndex.ShadowMapping() .. "]" + .. dump(core.settings:get_bool("enable_waving_plants")) .. "]".. + "label[8.25,3.0;" .. fgettext("Dynamic shadows: ") .. "]" .. + "dropdown[8.25,3.5;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";" + .. getSettingIndex.ShadowMapping() .. "]" else tab_string = tab_string .. "label[8.38,0.7;" .. core.colorize("#888888", @@ -231,9 +231,9 @@ local function formspec(tabview, name, tabdata) "label[8.38,1.7;" .. core.colorize("#888888", fgettext("Waving Leaves")) .. "]" .. "label[8.38,2.2;" .. core.colorize("#888888", - fgettext("Waving Plants")) .. "]" - --"label[8.38,2.7;" .. core.colorize("#888888", - -- fgettext("Dynamic shadows")) .. "]" + fgettext("Waving Plants")) .. "]".. + "label[8.38,2.7;" .. core.colorize("#888888", + fgettext("Dynamic shadows")) .. "]" end return tab_string diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 42b45aa00..ef8b84cff 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -586,6 +586,58 @@ enable_waving_leaves (Waving leaves) bool false # Requires shaders to be enabled. enable_waving_plants (Waving plants) bool false +[***Dynamic shadows] + +# Set to true to enable Shadow Mapping. +# Requires shaders to be enabled. +enable_dynamic_shadows (Dynamic shadows) bool false + +# Set the shadow strength. +# Lower value means lighter shadows, higher value means darker shadows. +shadow_strength (Shadow strength) float 0.2 0.05 1.0 + +# Maximum distance to render shadows. +shadow_map_max_distance (Shadow map max distance in nodes to render shadows) float 120.0 10.0 1000.0 + +# Texture size to render the shadow map on. +# This must be a power of two. +# Bigger numbers create better shadows but it is also more expensive. +shadow_map_texture_size (Shadow map texture size) int 1024 128 8192 + +# Sets shadow texture quality to 32 bits. +# On false, 16 bits texture will be used. +# This can cause much more artifacts in the shadow. +shadow_map_texture_32bit (Shadow map texture in 32 bits) bool true + +# Enable Poisson disk filtering. +# On true uses Poisson disk to make "soft shadows". Otherwise uses PCF filtering. +shadow_poisson_filter (Poisson filtering) bool true + +# Define shadow filtering quality. +# This simulates the soft shadows effect by applying a PCF or Poisson disk +# but also uses more resources. +shadow_filters (Shadow filter quality) enum 1 0,1,2 + +# Enable colored shadows. +# On true translucent nodes cast colored shadows. This is expensive. +shadow_map_color (Colored shadows) bool false + +# Spread a complete update of shadow map over given amount of frames. +# Higher values might make shadows laggy, lower values +# will consume more resources. +# Minimum value: 1; maximum value: 16 +shadow_update_frames (Map shadows update frames) int 8 1 16 + +# Set the soft shadow radius size. +# Lower values mean sharper shadows, bigger values mean softer shadows. +# Minimum value: 1.0; maximum value: 10.0 +shadow_soft_radius (Soft shadow radius) float 1.0 1.0 10.0 + +# Set the tilt of Sun/Moon orbit in degrees. +# Value of 0 means no tilt / vertical orbit. +# Minimum value: 0.0; maximum value: 60.0 +shadow_sky_body_orbit_tilt (Sky Body Orbit Tilt) float 0.0 0.0 60.0 + [**Advanced] # Arm inertia, gives a more realistic movement of diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 249a56087..03522eca9 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -861,7 +861,7 @@ static void updateFastFaceRow( g_settings->getBool("enable_waving_water"); static thread_local const bool force_not_tiling = - false && g_settings->getBool("enable_dynamic_shadows"); + g_settings->getBool("enable_dynamic_shadows"); v3s16 p = startpos; diff --git a/src/client/render/core.cpp b/src/client/render/core.cpp index 44ef1c98c..f151832f3 100644 --- a/src/client/render/core.cpp +++ b/src/client/render/core.cpp @@ -36,7 +36,7 @@ RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud virtual_size = screensize; if (g_settings->getBool("enable_shaders") && - false && g_settings->getBool("enable_dynamic_shadows")) { + g_settings->getBool("enable_dynamic_shadows")) { shadow_renderer = new ShadowRenderer(device, client); } } diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index a0ddb0d9a..6f104bba9 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -123,8 +123,8 @@ public: // FIXME: this is still global when it shouldn't be static ShadowRenderer *get_shadow_renderer() { - //if (s_singleton && s_singleton->core) - // return s_singleton->core->get_shadow_renderer(); + if (s_singleton && s_singleton->core) + return s_singleton->core->get_shadow_renderer(); return nullptr; } static std::vector getSupportedVideoDrivers(); diff --git a/src/client/shader.cpp b/src/client/shader.cpp index c04a25862..dc9e9ae6d 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -733,7 +733,7 @@ ShaderInfo ShaderSource::generateShader(const std::string &name, shaders_header << "#define FOG_START " << core::clamp(g_settings->getFloat("fog_start"), 0.0f, 0.99f) << "\n"; - if (false && g_settings->getBool("enable_dynamic_shadows")) { + if (g_settings->getBool("enable_dynamic_shadows")) { shaders_header << "#define ENABLE_DYNAMIC_SHADOWS 1\n"; if (g_settings->getBool("shadow_map_color")) shaders_header << "#define COLORED_SHADOWS 1\n"; diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 7fe90c6cd..0ab710eee 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -103,7 +103,7 @@ Sky::Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShade m_directional_colored_fog = g_settings->getBool("directional_colored_fog"); - if (false && g_settings->getBool("enable_dynamic_shadows")) { + if (g_settings->getBool("enable_dynamic_shadows")) { float val = g_settings->getFloat("shadow_sky_body_orbit_tilt"); m_sky_body_orbit_tilt = rangelim(val, 0.0f, 60.0f); } -- cgit v1.2.3 From 51294163bbe39ca8b4a4620af724c9402f374142 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 26 Feb 2022 15:07:00 +0100 Subject: Use Irrlicht bindings for GL call --- src/client/shader.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'src/client/shader.cpp') diff --git a/src/client/shader.cpp b/src/client/shader.cpp index dc9e9ae6d..fa5ffb914 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -40,20 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/tile.h" #include "config.h" -#if ENABLE_GLES -#ifdef _IRR_COMPILE_WITH_OGLES1_ -#include -#else -#include -#endif -#else -#ifndef __APPLE__ -#include -#else -#define GL_SILENCE_DEPRECATION -#include -#endif -#endif +#include /* A cache from shader name to shader path @@ -667,13 +654,19 @@ ShaderInfo ShaderSource::generateShader(const std::string &name, )"; } + // Since this is the first time we're using the GL bindings be extra careful. + // This should be removed before 5.6.0 or similar. + if (!GL.GetString) { + errorstream << "OpenGL procedures were not loaded correctly, " + "please open a bug report with details about your platform/OS." << std::endl; + abort(); + } + bool use_discard = use_gles; -#ifdef __unix__ // For renderers that should use discard instead of GL_ALPHA_TEST - const char* gl_renderer = (const char*)glGetString(GL_RENDERER); - if (strstr(gl_renderer, "GC7000")) + const char *renderer = reinterpret_cast(GL.GetString(GL.RENDERER)); + if (strstr(renderer, "GC7000")) use_discard = true; -#endif if (use_discard) { if (shaderinfo.base_material == video::EMT_TRANSPARENT_ALPHA_CHANNEL) shaders_header << "#define USE_DISCARD 1\n"; -- cgit v1.2.3 From 31578303a4eab6b6b083e57b6bf8d12ff3b3d991 Mon Sep 17 00:00:00 2001 From: x2048 Date: Thu, 31 Mar 2022 22:40:06 +0200 Subject: Tune shadow perspective distortion (#12146) * Pass perspective distortion parameters as uniforms * Set all perspective bias parameters via ShadowRenderer * Recalibrate perspective distortion and shadow range to render less shadow geometry with the same quality and observed shadow distance --- builtin/mainmenu/tab_settings.lua | 10 ++--- client/shaders/nodes_shader/opengl_fragment.glsl | 18 ++++---- client/shaders/nodes_shader/opengl_vertex.glsl | 8 ++-- client/shaders/object_shader/opengl_fragment.glsl | 18 ++++---- client/shaders/object_shader/opengl_vertex.glsl | 8 ++-- .../shaders/shadow_shaders/pass1_trans_vertex.glsl | 10 ++--- client/shaders/shadow_shaders/pass1_vertex.glsl | 10 ++--- src/client/shader.cpp | 48 ++++++++++++++++------ src/client/shadows/dynamicshadowsrender.cpp | 25 +++++++++-- src/client/shadows/dynamicshadowsrender.h | 6 +++ src/client/shadows/shadowsshadercallbacks.cpp | 6 +++ src/client/shadows/shadowsshadercallbacks.h | 9 +++- 12 files changed, 117 insertions(+), 59 deletions(-) (limited to 'src/client/shader.cpp') diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 42f7f8daf..0e761d324 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -364,11 +364,11 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) core.settings:set("enable_dynamic_shadows", "false") else local shadow_presets = { - [2] = { 80, 512, "true", 0, "false" }, - [3] = { 120, 1024, "true", 1, "false" }, - [4] = { 350, 2048, "true", 1, "false" }, - [5] = { 350, 2048, "true", 2, "true" }, - [6] = { 450, 4096, "true", 2, "true" }, + [2] = { 55, 512, "true", 0, "false" }, + [3] = { 82, 1024, "true", 1, "false" }, + [4] = { 240, 2048, "true", 1, "false" }, + [5] = { 240, 2048, "true", 2, "true" }, + [6] = { 300, 4096, "true", 2, "true" }, } local s = shadow_presets[table.indexof(labels.shadow_levels, fields["dd_shadows"])] if s then diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index adc8adccb..3dc66bdb3 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -47,17 +47,17 @@ const float fogShadingParameter = 1.0 / ( 1.0 - fogStart); #ifdef ENABLE_DYNAMIC_SHADOWS -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } @@ -172,12 +172,12 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis float getBaseLength(vec2 smTexCoord) { float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords - return bias1 / (1.0 / l - bias0); // return to undistorted coords + return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords } float getDeltaPerspectiveFactor(float l) { - return 0.1 / (bias0 * l + bias1); // original distortion factor, divided by 10 + return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 } float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier) @@ -489,8 +489,8 @@ void main(void) vec3 shadow_color = vec3(0.0, 0.0, 0.0); vec3 posLightSpace = getLightSpacePosition(); - float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 20.0)); - float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z ),0.0); + float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0)); + float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0); if (distance_rate > 1e-7) { diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index 5e77ac719..935fbf043 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -45,8 +45,8 @@ varying float nightRatio; const vec3 artificialLight = vec3(1.04, 1.04, 1.04); const float e = 2.718281828459; const float BS = 10.0; -const float bias0 = 0.9; -const float bias1 = 1.0 - bias0; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; #ifdef ENABLE_DYNAMIC_SHADOWS // custom smoothstep implementation because it's not defined in glsl1.2 @@ -206,9 +206,9 @@ void main(void) // Distance from the vertex to the player float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar; // perspective factor estimation according to the - float perspectiveFactor = distanceToPlayer * bias0 + bias1; + float perspectiveFactor = distanceToPlayer * xyPerspectiveBias0 + xyPerspectiveBias1; float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor / - (f_textureresolution * bias1 - perspectiveFactor * bias0); + (f_textureresolution * xyPerspectiveBias1 - perspectiveFactor * xyPerspectiveBias0); float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0); normalOffsetScale = texelSize * slopeScale; diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl index edb9d2bb1..2b9a59cd7 100644 --- a/client/shaders/object_shader/opengl_fragment.glsl +++ b/client/shaders/object_shader/opengl_fragment.glsl @@ -43,17 +43,17 @@ const float fogShadingParameter = 1.0 / (1.0 - fogStart); #endif #ifdef ENABLE_DYNAMIC_SHADOWS -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } @@ -162,12 +162,12 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis float getBaseLength(vec2 smTexCoord) { float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords - return bias1 / (1.0 / l - bias0); // return to undistorted coords + return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords } float getDeltaPerspectiveFactor(float l) { - return 0.1 / (bias0 * l + bias1); // original distortion factor, divided by 10 + return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 } float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier) @@ -477,8 +477,8 @@ void main(void) vec3 shadow_color = vec3(0.0, 0.0, 0.0); vec3 posLightSpace = getLightSpacePosition(); - float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 20.0)); - float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z ),0.0); + float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0)); + float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0); if (distance_rate > 1e-7) { diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index ff0067302..55861b0e9 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -37,8 +37,8 @@ const vec3 artificialLight = vec3(1.04, 1.04, 1.04); varying float vIDiff; const float e = 2.718281828459; const float BS = 10.0; -const float bias0 = 0.9; -const float bias1 = 1.0 - bias0; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; #ifdef ENABLE_DYNAMIC_SHADOWS // custom smoothstep implementation because it's not defined in glsl1.2 @@ -116,9 +116,9 @@ void main(void) // Distance from the vertex to the player float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar; // perspective factor estimation according to the - float perspectiveFactor = distanceToPlayer * bias0 + bias1; + float perspectiveFactor = distanceToPlayer * xyPerspectiveBias0 + xyPerspectiveBias1; float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor / - (f_textureresolution * bias1 - perspectiveFactor * bias0); + (f_textureresolution * xyPerspectiveBias1 - perspectiveFactor * xyPerspectiveBias0); float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0); normalOffsetScale = texelSize * slopeScale; diff --git a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl index 0a9efe450..6d2877d18 100644 --- a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl +++ b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl @@ -4,15 +4,15 @@ varying vec4 tPos; varying vec3 varColor; #endif -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } diff --git a/client/shaders/shadow_shaders/pass1_vertex.glsl b/client/shaders/shadow_shaders/pass1_vertex.glsl index feee9467f..3873ac6e6 100644 --- a/client/shaders/shadow_shaders/pass1_vertex.glsl +++ b/client/shaders/shadow_shaders/pass1_vertex.glsl @@ -1,15 +1,15 @@ uniform mat4 LightMVP; // world matrix varying vec4 tPos; -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } diff --git a/src/client/shader.cpp b/src/client/shader.cpp index fa5ffb914..d9c1952c4 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -210,17 +210,23 @@ public: class MainShaderConstantSetter : public IShaderConstantSetter { - CachedVertexShaderSetting m_world_view_proj; - CachedVertexShaderSetting m_world; + CachedVertexShaderSetting m_world_view_proj; + CachedVertexShaderSetting m_world; // Shadow-related - CachedPixelShaderSetting m_shadow_view_proj; - CachedPixelShaderSetting m_light_direction; - CachedPixelShaderSetting m_texture_res; - CachedPixelShaderSetting m_shadow_strength; - CachedPixelShaderSetting m_time_of_day; - CachedPixelShaderSetting m_shadowfar; + CachedPixelShaderSetting m_shadow_view_proj; + CachedPixelShaderSetting m_light_direction; + CachedPixelShaderSetting m_texture_res; + CachedPixelShaderSetting m_shadow_strength; + CachedPixelShaderSetting m_time_of_day; + CachedPixelShaderSetting m_shadowfar; CachedPixelShaderSetting m_shadow_texture; + CachedVertexShaderSetting m_perspective_bias0_vertex; + CachedPixelShaderSetting m_perspective_bias0_pixel; + CachedVertexShaderSetting m_perspective_bias1_vertex; + CachedPixelShaderSetting m_perspective_bias1_pixel; + CachedVertexShaderSetting m_perspective_zbias_vertex; + CachedPixelShaderSetting m_perspective_zbias_pixel; #if ENABLE_GLES // Modelview matrix @@ -247,6 +253,12 @@ public: , m_time_of_day("f_timeofday") , m_shadowfar("f_shadowfar") , m_shadow_texture("ShadowMapSampler") + , m_perspective_bias0_vertex("xyPerspectiveBias0") + , m_perspective_bias0_pixel("xyPerspectiveBias0") + , m_perspective_bias1_vertex("xyPerspectiveBias1") + , m_perspective_bias1_pixel("xyPerspectiveBias1") + , m_perspective_zbias_vertex("zPerspectiveBias") + , m_perspective_zbias_pixel("zPerspectiveBias") {} ~MainShaderConstantSetter() = default; @@ -293,26 +305,36 @@ public: shadowViewProj *= light.getViewMatrix(); m_shadow_view_proj.set(shadowViewProj.pointer(), services); - float v_LightDirection[3]; + f32 v_LightDirection[3]; light.getDirection().getAs3Values(v_LightDirection); m_light_direction.set(v_LightDirection, services); - float TextureResolution = light.getMapResolution(); + f32 TextureResolution = light.getMapResolution(); m_texture_res.set(&TextureResolution, services); - float ShadowStrength = shadow->getShadowStrength(); + f32 ShadowStrength = shadow->getShadowStrength(); m_shadow_strength.set(&ShadowStrength, services); - float timeOfDay = shadow->getTimeOfDay(); + f32 timeOfDay = shadow->getTimeOfDay(); m_time_of_day.set(&timeOfDay, services); - float shadowFar = shadow->getMaxShadowFar(); + f32 shadowFar = shadow->getMaxShadowFar(); m_shadowfar.set(&shadowFar, services); // I dont like using this hardcoded value. maybe something like // MAX_TEXTURE - 1 or somthing like that?? s32 TextureLayerID = 3; m_shadow_texture.set(&TextureLayerID, services); + + f32 bias0 = shadow->getPerspectiveBiasXY(); + m_perspective_bias0_vertex.set(&bias0, services); + m_perspective_bias0_pixel.set(&bias0, services); + f32 bias1 = 1.0f - bias0 + 1e-5f; + m_perspective_bias1_vertex.set(&bias1, services); + m_perspective_bias1_pixel.set(&bias1, services); + f32 zbias = shadow->getPerspectiveBiasZ(); + m_perspective_zbias_vertex.set(&zbias, services); + m_perspective_zbias_pixel.set(&zbias, services); } } }; 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 m_light_mvp_setting; CachedVertexShaderSetting m_map_resolution_setting; CachedVertexShaderSetting m_max_far_setting; CachedPixelShaderSetting m_color_map_sampler_setting; + CachedVertexShaderSetting m_perspective_bias0; + CachedVertexShaderSetting m_perspective_bias1; + CachedVertexShaderSetting m_perspective_zbias; }; -- cgit v1.2.3 From 48f7c5603e5b2dfca941d228e76e452bc269a1fa Mon Sep 17 00:00:00 2001 From: x2048 Date: Thu, 7 Apr 2022 22:13:50 +0200 Subject: Adjust shadowmap distortion to use entire SM texture (#12166) --- client/shaders/nodes_shader/opengl_fragment.glsl | 25 +++--- client/shaders/object_shader/opengl_fragment.glsl | 89 +++++++++++++--------- .../shaders/shadow_shaders/pass1_trans_vertex.glsl | 10 ++- client/shaders/shadow_shaders/pass1_vertex.glsl | 10 ++- src/client/clientmap.cpp | 36 +++------ src/client/clientmap.h | 2 +- src/client/shader.cpp | 6 ++ src/client/shadows/dynamicshadows.cpp | 58 ++++++++------ src/client/shadows/dynamicshadows.h | 10 ++- src/client/shadows/dynamicshadowsrender.cpp | 11 +-- src/client/shadows/shadowsshadercallbacks.cpp | 6 ++ src/client/shadows/shadowsshadercallbacks.h | 5 +- 12 files changed, 156 insertions(+), 112 deletions(-) (limited to 'src/client/shader.cpp') diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index 3dc66bdb3..4d0d107d1 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -17,6 +17,7 @@ uniform float animationTimer; uniform mat4 m_ShadowViewProj; uniform float f_shadowfar; uniform float f_shadow_strength; + uniform vec4 CameraPos; varying float normalOffsetScale; varying float adj_shadow_strength; varying float cosLight; @@ -53,12 +54,13 @@ uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { - - float pDistance = length(shadowPosition.xy); + vec2 s = vec2(shadowPosition.x > CameraPos.x ? 1.0 : -1.0, shadowPosition.y > CameraPos.y ? 1.0 : -1.0); + vec2 l = s * (shadowPosition.xy - CameraPos.xy) / (1.0 - s * CameraPos.xy); + float pDistance = length(l); float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); - + l /= pFactor; + shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l; + shadowPosition.z *= zPerspectiveBias; return shadowPosition; } @@ -171,13 +173,13 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis float getBaseLength(vec2 smTexCoord) { - float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords + float l = length(2.0 * smTexCoord.xy - 1.0 - CameraPos.xy); // length in texture coords return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords } float getDeltaPerspectiveFactor(float l) { - return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 + return 0.04 * pow(512.0 / f_textureresolution, 0.4) / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 } float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier) @@ -185,7 +187,6 @@ float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDist float baseLength = getBaseLength(smTexCoord); float perspectiveFactor; - if (PCFBOUND == 0.0) return 0.0; // Return fast if sharp shadows are requested if (PCFBOUND == 0.0) return 0.0; @@ -489,11 +490,13 @@ void main(void) vec3 shadow_color = vec3(0.0, 0.0, 0.0); vec3 posLightSpace = getLightSpacePosition(); - float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0)); + float distance_rate = (1.0 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 10.0)); + if (max(abs(posLightSpace.x - 0.5), abs(posLightSpace.y - 0.5)) > 0.5) + distance_rate = 0.0; float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0); if (distance_rate > 1e-7) { - + #ifdef COLORED_SHADOWS vec4 visibility; if (cosLight > 0.0) @@ -527,7 +530,7 @@ void main(void) } shadow_int *= f_adj_shadow_strength; - + // calculate fragment color from components: col.rgb = adjusted_night_ratio * col.rgb + // artificial light diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl index 2b9a59cd7..2611bf8ef 100644 --- a/client/shaders/object_shader/opengl_fragment.glsl +++ b/client/shaders/object_shader/opengl_fragment.glsl @@ -6,8 +6,33 @@ uniform vec4 skyBgColor; uniform float fogDistance; uniform vec3 eyePosition; +// The cameraOffset is the current center of the visible world. +uniform vec3 cameraOffset; +uniform float animationTimer; +#ifdef ENABLE_DYNAMIC_SHADOWS + // shadow texture + uniform sampler2D ShadowMapSampler; + // shadow uniforms + uniform vec3 v_LightDirection; + uniform float f_textureresolution; + uniform mat4 m_ShadowViewProj; + uniform float f_shadowfar; + uniform float f_shadow_strength; + uniform vec4 CameraPos; + varying float normalOffsetScale; + varying float adj_shadow_strength; + varying float cosLight; + varying float f_normal_length; +#endif + + varying vec3 vNormal; varying vec3 vPosition; +// World position in the visible world (i.e. relative to the cameraOffset.) +// This can be used for many shader effects without loss of precision. +// If the absolute position is required it can be calculated with +// cameraOffset + worldPosition (for large coordinates the limits of float +// precision must be considered). varying vec3 worldPosition; varying lowp vec4 varColor; #ifdef GL_ES @@ -15,32 +40,15 @@ varying mediump vec2 varTexCoord; #else centroid varying vec2 varTexCoord; #endif - varying vec3 eyeVec; varying float nightRatio; varying float vIDiff; -const float e = 2.718281828459; -const float BS = 10.0; const float fogStart = FOG_START; const float fogShadingParameter = 1.0 / (1.0 - fogStart); -#ifdef ENABLE_DYNAMIC_SHADOWS - // shadow texture - uniform sampler2D ShadowMapSampler; - // shadow uniforms - uniform vec3 v_LightDirection; - uniform float f_textureresolution; - uniform mat4 m_ShadowViewProj; - uniform float f_shadowfar; - uniform float f_timeofday; - uniform float f_shadow_strength; - varying float normalOffsetScale; - varying float adj_shadow_strength; - varying float cosLight; - varying float f_normal_length; -#endif + #ifdef ENABLE_DYNAMIC_SHADOWS uniform float xyPerspectiveBias0; @@ -49,15 +57,22 @@ uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { - - float pDistance = length(shadowPosition.xy); + vec2 s = vec2(shadowPosition.x > CameraPos.x ? 1.0 : -1.0, shadowPosition.y > CameraPos.y ? 1.0 : -1.0); + vec2 l = s * (shadowPosition.xy - CameraPos.xy) / (1.0 - s * CameraPos.xy); + float pDistance = length(l); float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); - + l /= pFactor; + shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l; + shadowPosition.z *= zPerspectiveBias; return shadowPosition; } +// assuming near is always 1.0 +float getLinearDepth() +{ + return 2.0 * f_shadowfar / (f_shadowfar + 1.0 - (2.0 * gl_FragCoord.z - 1.0) * (f_shadowfar - 1.0)); +} + vec3 getLightSpacePosition() { vec4 pLightSpace; @@ -161,13 +176,13 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis float getBaseLength(vec2 smTexCoord) { - float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords + float l = length(2.0 * smTexCoord.xy - 1.0 - CameraPos.xy); // length in texture coords return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords } float getDeltaPerspectiveFactor(float l) { - return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 + return 0.04 * pow(512.0 / f_textureresolution, 0.4) / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 } float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier) @@ -178,7 +193,7 @@ float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDist // Return fast if sharp shadows are requested if (PCFBOUND == 0.0) return 0.0; - + if (SOFTSHADOWRADIUS <= 1.0) { perspectiveFactor = getDeltaPerspectiveFactor(baseLength); return max(2 * length(smTexCoord.xy) * 2048 / f_textureresolution / pow(perspectiveFactor, 3), SOFTSHADOWRADIUS); @@ -418,6 +433,7 @@ float getShadow(sampler2D shadowsampler, vec2 smTexCoord, float realDistance) #endif #if ENABLE_TONE_MAPPING + /* Hable's UC2 Tone mapping parameters A = 0.22; B = 0.30; @@ -448,12 +464,14 @@ vec4 applyToneMapping(vec4 color) } #endif + + void main(void) { vec3 color; vec2 uv = varTexCoord.st; - vec4 base = texture2D(baseTexture, uv).rgba; + vec4 base = texture2D(baseTexture, uv).rgba; // If alpha is zero, we can just discard the pixel. This fixes transparency // on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa, // and also on GLES 2, where GL_ALPHA_TEST is missing entirely. @@ -467,8 +485,7 @@ void main(void) #endif color = base.rgb; - vec4 col = vec4(color.rgb, base.a); - col.rgb *= varColor.rgb; + vec4 col = vec4(color.rgb * varColor.rgb, 1.0); col.rgb *= vIDiff; #ifdef ENABLE_DYNAMIC_SHADOWS @@ -477,11 +494,13 @@ void main(void) vec3 shadow_color = vec3(0.0, 0.0, 0.0); vec3 posLightSpace = getLightSpacePosition(); - float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0)); + float distance_rate = (1.0 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 10.0)); + if (max(abs(posLightSpace.x - 0.5), abs(posLightSpace.y - 0.5)) > 0.5) + distance_rate = 0.0; float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0); if (distance_rate > 1e-7) { - + #ifdef COLORED_SHADOWS vec4 visibility; if (cosLight > 0.0) @@ -506,8 +525,8 @@ void main(void) // Power ratio was measured on torches in MTG (brightness = 14). float adjusted_night_ratio = pow(max(0.0, nightRatio), 0.6); - // cosine of the normal-to-light angle when - // we start to apply self-shadowing + // Apply self-shadowing when light falls at a narrow angle to the surface + // Cosine of the cut-off angle. const float self_shadow_cutoff_cosine = 0.14; if (f_normal_length != 0 && cosLight < self_shadow_cutoff_cosine) { shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine); @@ -541,5 +560,7 @@ void main(void) float clarity = clamp(fogShadingParameter - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0); col = mix(skyBgColor, col, clarity); - gl_FragColor = vec4(col.rgb, base.a); + col = vec4(col.rgb, base.a); + + gl_FragColor = col; } diff --git a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl index 6d2877d18..c2f575876 100644 --- a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl +++ b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl @@ -1,4 +1,5 @@ uniform mat4 LightMVP; // world matrix +uniform vec4 CameraPos; varying vec4 tPos; #ifdef COLORED_SHADOWS varying vec3 varColor; @@ -10,10 +11,13 @@ uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { - float pDistance = length(shadowPosition.xy); + vec2 s = vec2(shadowPosition.x > CameraPos.x ? 1.0 : -1.0, shadowPosition.y > CameraPos.y ? 1.0 : -1.0); + vec2 l = s * (shadowPosition.xy - CameraPos.xy) / (1.0 - s * CameraPos.xy); + float pDistance = length(l); float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); - + l /= pFactor; + shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l; + shadowPosition.z *= zPerspectiveBias; return shadowPosition; } diff --git a/client/shaders/shadow_shaders/pass1_vertex.glsl b/client/shaders/shadow_shaders/pass1_vertex.glsl index 3873ac6e6..38aef3619 100644 --- a/client/shaders/shadow_shaders/pass1_vertex.glsl +++ b/client/shaders/shadow_shaders/pass1_vertex.glsl @@ -1,4 +1,5 @@ uniform mat4 LightMVP; // world matrix +uniform vec4 CameraPos; // camera position varying vec4 tPos; uniform float xyPerspectiveBias0; @@ -7,10 +8,13 @@ uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { - float pDistance = length(shadowPosition.xy); + vec2 s = vec2(shadowPosition.x > CameraPos.x ? 1.0 : -1.0, shadowPosition.y > CameraPos.y ? 1.0 : -1.0); + vec2 l = s * (shadowPosition.xy - CameraPos.xy) / (1.0 - s * CameraPos.xy); + float pDistance = length(l); float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); - + l /= pFactor; + shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l; + shadowPosition.z *= zPerspectiveBias; return shadowPosition; } diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index f070a58bb..8a059c922 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -862,20 +862,14 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, /* Custom update draw list for the pov of shadow light. */ -void ClientMap::updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range) +void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length) { ScopeProfiler sp(g_profiler, "CM::updateDrawListShadow()", SPT_AVG); - const v3f camera_position = shadow_light_pos; - const v3f camera_direction = shadow_light_dir; - // I "fake" fov just to avoid creating a new function to handle orthographic - // projection. - const f32 camera_fov = m_camera_fov * 1.9f; - - v3s16 cam_pos_nodes = floatToInt(camera_position, BS); + v3s16 cam_pos_nodes = floatToInt(shadow_light_pos, BS); v3s16 p_blocks_min; v3s16 p_blocks_max; - getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max, shadow_range); + getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max, radius + length); std::vector blocks_in_range; @@ -889,10 +883,10 @@ void ClientMap::updateDrawListShadow(const v3f &shadow_light_pos, const v3f &sha // they are not inside the light frustum and it creates glitches. // FIXME: This could be removed if we figure out why they are missing // from the light frustum. - for (auto &i : m_drawlist) { - i.second->refGrab(); - m_drawlist_shadow[i.first] = i.second; - } + // for (auto &i : m_drawlist) { + // i.second->refGrab(); + // m_drawlist_shadow[i.first] = i.second; + // } // Number of blocks currently loaded by the client u32 blocks_loaded = 0; @@ -919,23 +913,13 @@ void ClientMap::updateDrawListShadow(const v3f &shadow_light_pos, const v3f &sha continue; } - float range = shadow_range; - - float d = 0.0; - if (!isBlockInSight(block->getPos(), camera_position, - camera_direction, camera_fov, range, &d)) + v3f block_pos = intToFloat(block->getPos() * MAP_BLOCKSIZE, BS); + v3f projection = shadow_light_pos + shadow_light_dir * shadow_light_dir.dotProduct(block_pos - shadow_light_pos); + if (projection.getDistanceFrom(block_pos) > radius) continue; blocks_in_range_with_mesh++; - /* - Occlusion culling - */ - if (isBlockOccluded(block, cam_pos_nodes)) { - blocks_occlusion_culled++; - continue; - } - // This block is in range. Reset usage timer. block->resetUsageTimer(); diff --git a/src/client/clientmap.h b/src/client/clientmap.h index 4edad0d20..7bd7af266 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -116,7 +116,7 @@ public: void getBlocksInViewRange(v3s16 cam_pos_nodes, v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f); void updateDrawList(); - void updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range); + void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length); // Returns true if draw list needs updating before drawing the next frame. bool needsUpdateDrawList() { return m_needs_update_drawlist; } void renderMap(video::IVideoDriver* driver, s32 pass); diff --git a/src/client/shader.cpp b/src/client/shader.cpp index d9c1952c4..1be9ef128 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -220,6 +220,7 @@ class MainShaderConstantSetter : public IShaderConstantSetter CachedPixelShaderSetting m_shadow_strength; CachedPixelShaderSetting m_time_of_day; CachedPixelShaderSetting m_shadowfar; + CachedPixelShaderSetting m_camera_pos; CachedPixelShaderSetting m_shadow_texture; CachedVertexShaderSetting m_perspective_bias0_vertex; CachedPixelShaderSetting m_perspective_bias0_pixel; @@ -252,6 +253,7 @@ public: , m_shadow_strength("f_shadow_strength") , m_time_of_day("f_timeofday") , m_shadowfar("f_shadowfar") + , m_camera_pos("CameraPos") , m_shadow_texture("ShadowMapSampler") , m_perspective_bias0_vertex("xyPerspectiveBias0") , m_perspective_bias0_pixel("xyPerspectiveBias0") @@ -321,6 +323,10 @@ public: f32 shadowFar = shadow->getMaxShadowFar(); m_shadowfar.set(&shadowFar, services); + f32 cam_pos[4]; + shadowViewProj.transformVect(cam_pos, light.getPlayerPos()); + m_camera_pos.set(cam_pos, services); + // I dont like using this hardcoded value. maybe something like // MAX_TEXTURE - 1 or somthing like that?? s32 TextureLayerID = 3; diff --git a/src/client/shadows/dynamicshadows.cpp b/src/client/shadows/dynamicshadows.cpp index ddec3a5d5..ca2d3ce37 100644 --- a/src/client/shadows/dynamicshadows.cpp +++ b/src/client/shadows/dynamicshadows.cpp @@ -29,7 +29,6 @@ using m4f = core::matrix4; void DirectionalLight::createSplitMatrices(const Camera *cam) { - float radius; v3f newCenter; v3f look = cam->getDirection(); @@ -42,17 +41,16 @@ void DirectionalLight::createSplitMatrices(const Camera *cam) float sfFar = adjustDist(future_frustum.zFar, cam->getFovY()); // adjusted camera positions - v3f camPos2 = cam->getPosition(); - v3f camPos = v3f(camPos2.X - cam->getOffset().X * BS, - camPos2.Y - cam->getOffset().Y * BS, - camPos2.Z - cam->getOffset().Z * BS); - camPos += look * sfNear; - camPos2 += look * sfNear; + v3f cam_pos_world = cam->getPosition(); + 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); + cam_pos_scene += look * sfNear; + cam_pos_world += look * sfNear; // center point of light frustum - float end = sfNear + sfFar; - newCenter = camPos + look * (sfNear + 0.05f * end); - v3f world_center = camPos2 + look * (sfNear + 0.05f * end); + v3f center_scene = cam_pos_scene + look * 0.35 * (sfFar - sfNear); + v3f center_world = cam_pos_world + look * 0.35 * (sfFar - sfNear); // Create a vector to the frustum far corner const v3f &viewUp = cam->getCameraNode()->getUpVector(); @@ -60,22 +58,21 @@ void DirectionalLight::createSplitMatrices(const Camera *cam) v3f farCorner = (look + viewRight * tanFovX + viewUp * tanFovY).normalize(); // Compute the frustumBoundingSphere radius - v3f boundVec = (camPos + farCorner * sfFar) - newCenter; - radius = boundVec.getLength(); - // boundVec.getLength(); - float vvolume = radius; - v3f frustumCenter = newCenter; - v3f eye_displacement = direction * vvolume; + v3f boundVec = (cam_pos_scene + farCorner * sfFar) - center_scene; + float radius = boundVec.getLength(); + float length = radius * 3.0f; + v3f eye_displacement = direction * length; // we must compute the viewmat with the position - the camera offset // but the future_frustum position must be the actual world position - v3f eye = frustumCenter - eye_displacement; - future_frustum.position = world_center - eye_displacement; - future_frustum.length = vvolume; - future_frustum.ViewMat.buildCameraLookAtMatrixLH(eye, frustumCenter, v3f(0.0f, 1.0f, 0.0f)); - future_frustum.ProjOrthMat.buildProjectionMatrixOrthoLH(future_frustum.length, - future_frustum.length, -future_frustum.length, - future_frustum.length,false); + v3f eye = center_scene - eye_displacement; + future_frustum.player = cam_pos_scene; + future_frustum.position = center_world - eye_displacement; + future_frustum.length = length; + future_frustum.radius = radius; + future_frustum.ViewMat.buildCameraLookAtMatrixLH(eye, center_scene, v3f(0.0f, 1.0f, 0.0f)); + future_frustum.ProjOrthMat.buildProjectionMatrixOrthoLH(radius, radius, + 0.0f, length, false); future_frustum.camera_offset = cam->getOffset(); } @@ -94,7 +91,7 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo float zNear = cam->getCameraNode()->getNearValue(); float zFar = getMaxFarValue(); if (!client->getEnv().getClientMap().getControl().range_all) - zFar = MYMIN(zFar, client->getEnv().getClientMap().getControl().wanted_range * BS * 1.5); + zFar = MYMIN(zFar, client->getEnv().getClientMap().getControl().wanted_range * BS); /////////////////////////////////// // update splits near and fars @@ -105,7 +102,7 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo createSplitMatrices(cam); // get the draw list for shadows client->getEnv().getClientMap().updateDrawListShadow( - getPosition(), getDirection(), future_frustum.length); + getPosition(), getDirection(), future_frustum.radius, future_frustum.length); should_update_map_shadow = true; dirty = true; @@ -115,6 +112,7 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo v3f rotated_offset; shadow_frustum.ViewMat.rotateVect(rotated_offset, intToFloat(cam_offset - shadow_frustum.camera_offset, BS)); shadow_frustum.ViewMat.setTranslation(shadow_frustum.ViewMat.getTranslation() + rotated_offset); + shadow_frustum.player += intToFloat(shadow_frustum.camera_offset - cam->getOffset(), BS); shadow_frustum.camera_offset = cam_offset; } } @@ -139,6 +137,16 @@ v3f DirectionalLight::getPosition() const return shadow_frustum.position; } +v3f DirectionalLight::getPlayerPos() const +{ + return shadow_frustum.player; +} + +v3f DirectionalLight::getFuturePlayerPos() const +{ + return future_frustum.player; +} + const m4f &DirectionalLight::getViewMatrix() const { return shadow_frustum.ViewMat; diff --git a/src/client/shadows/dynamicshadows.h b/src/client/shadows/dynamicshadows.h index 03dd36014..70574aa6c 100644 --- a/src/client/shadows/dynamicshadows.h +++ b/src/client/shadows/dynamicshadows.h @@ -29,12 +29,14 @@ class Client; struct shadowFrustum { - float zNear{0.0f}; - float zFar{0.0f}; - float length{0.0f}; + f32 zNear{0.0f}; + f32 zFar{0.0f}; + f32 length{0.0f}; + f32 radius{0.0f}; core::matrix4 ProjOrthMat; core::matrix4 ViewMat; v3f position; + v3f player; v3s16 camera_offset; }; @@ -57,6 +59,8 @@ public: return direction; }; v3f getPosition() const; + v3f getPlayerPos() const; + v3f getFuturePlayerPos() const; /// Gets the light's matrices. const core::matrix4 &getViewMatrix() const; diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index 262711221..1dfc90d1c 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -158,7 +158,6 @@ void ShadowRenderer::setShadowIntensity(float shadow_intensity) disable(); } - void ShadowRenderer::addNodeToShadowList( scene::ISceneNode *node, E_SHADOW_MODE shadowMode) { @@ -261,8 +260,9 @@ void ShadowRenderer::updateSMTextures() cb->MaxFar = (f32)m_shadow_map_max_distance * BS; cb->PerspectiveBiasXY = getPerspectiveBiasXY(); cb->PerspectiveBiasZ = getPerspectiveBiasZ(); + cb->CameraPos = light.getFuturePlayerPos(); } - + // set the Render Target // right now we can only render in usual RTT, not // Depth texture is available in irrlicth maybe we @@ -322,9 +322,10 @@ void ShadowRenderer::update(video::ITexture *outputTarget) if (!m_shadow_node_array.empty() && !m_light_list.empty()) { 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; + // Static shader values for entities are set in updateSMTextures + // SM texture for entities is not updated incrementally and + // must by updated using current player position. + m_shadow_depth_entity_cb->CameraPos = light.getPlayerPos(); // render shadows for the n0n-map objects. m_driver->setRenderTarget(shadowMapTextureDynamicObjects, true, diff --git a/src/client/shadows/shadowsshadercallbacks.cpp b/src/client/shadows/shadowsshadercallbacks.cpp index 51ea8aa93..b571ea939 100644 --- a/src/client/shadows/shadowsshadercallbacks.cpp +++ b/src/client/shadows/shadowsshadercallbacks.cpp @@ -26,6 +26,10 @@ void ShadowDepthShaderCB::OnSetConstants( core::matrix4 lightMVP = driver->getTransform(video::ETS_PROJECTION); lightMVP *= driver->getTransform(video::ETS_VIEW); + + f32 cam_pos[4]; + lightMVP.transformVect(cam_pos, CameraPos); + lightMVP *= driver->getTransform(video::ETS_WORLD); m_light_mvp_setting.set(lightMVP.pointer(), services); @@ -39,4 +43,6 @@ void ShadowDepthShaderCB::OnSetConstants( m_perspective_bias1.set(&bias1, services); f32 zbias = PerspectiveBiasZ; m_perspective_zbias.set(&zbias, services); + + m_cam_pos_setting.set(cam_pos, services); } diff --git a/src/client/shadows/shadowsshadercallbacks.h b/src/client/shadows/shadowsshadercallbacks.h index d00f59c37..87833c0ec 100644 --- a/src/client/shadows/shadowsshadercallbacks.h +++ b/src/client/shadows/shadowsshadercallbacks.h @@ -33,7 +33,8 @@ public: m_color_map_sampler_setting("ColorMapSampler"), m_perspective_bias0("xyPerspectiveBias0"), m_perspective_bias1("xyPerspectiveBias1"), - m_perspective_zbias("zPerspectiveBias") + m_perspective_zbias("zPerspectiveBias"), + m_cam_pos_setting("CameraPos") {} void OnSetMaterial(const video::SMaterial &material) override {} @@ -43,6 +44,7 @@ public: f32 MaxFar{2048.0f}, MapRes{1024.0f}; f32 PerspectiveBiasXY {0.9f}, PerspectiveBiasZ {0.5f}; + v3f CameraPos; private: CachedVertexShaderSetting m_light_mvp_setting; @@ -52,4 +54,5 @@ private: CachedVertexShaderSetting m_perspective_bias0; CachedVertexShaderSetting m_perspective_bias1; CachedVertexShaderSetting m_perspective_zbias; + CachedVertexShaderSetting m_cam_pos_setting; }; -- cgit v1.2.3 From 5683bb76cc3a60d952c9f58c41adaa5f195dd3f4 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 1 Dec 2021 18:30:40 -0500 Subject: Fix compiler warnings --- src/CMakeLists.txt | 6 ++++-- src/client/clientlauncher.cpp | 2 ++ src/client/shader.cpp | 10 ++++----- src/serialization.cpp | 14 ------------ src/server/player_sao.h | 48 ++++++++++++++++++++--------------------- src/terminal_chat_console.cpp | 3 ++- src/unittest/test_irrptr.cpp | 4 +++- src/unittest/test_voxelarea.cpp | 4 ++-- src/util/srp.cpp | 4 ++-- 9 files changed, 44 insertions(+), 51 deletions(-) (limited to 'src/client/shader.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ac4c1de73..2de68a8f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -470,6 +470,9 @@ endif() include_directories( ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/script +) +include_directories(SYSTEM ${ZLIB_INCLUDE_DIR} ${ZSTD_INCLUDE_DIR} ${SQLITE3_INCLUDE_DIR} @@ -477,7 +480,6 @@ include_directories( ${GMP_INCLUDE_DIR} ${JSON_INCLUDE_DIR} ${LUA_BIT_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/script ) if(USE_GETTEXT) @@ -485,7 +487,7 @@ if(USE_GETTEXT) endif() if(BUILD_CLIENT) - include_directories( + include_directories(SYSTEM ${FREETYPE_INCLUDE_DIRS} ${SOUND_INCLUDE_DIRS} ${X11_INCLUDE_DIR} diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 063154316..54c561d11 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -564,6 +564,8 @@ void ClientLauncher::speed_tests() // volatile to avoid some potential compiler optimisations volatile static s16 temp16; volatile static f32 tempf; + // Silence compiler warning + (void)temp16; static v3f tempv3f1; static v3f tempv3f2; static std::string tempstring; diff --git a/src/client/shader.cpp b/src/client/shader.cpp index 1be9ef128..bbb872761 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -242,11 +242,6 @@ public: MainShaderConstantSetter() : m_world_view_proj("mWorldViewProj") , m_world("mWorld") -#if ENABLE_GLES - , m_world_view("mWorldView") - , m_texture("mTexture") - , m_normal("mNormal") -#endif , m_shadow_view_proj("m_ShadowViewProj") , m_light_direction("v_LightDirection") , m_texture_res("f_textureresolution") @@ -261,6 +256,11 @@ public: , m_perspective_bias1_pixel("xyPerspectiveBias1") , m_perspective_zbias_vertex("zPerspectiveBias") , m_perspective_zbias_pixel("zPerspectiveBias") +#if ENABLE_GLES + , m_world_view("mWorldView") + , m_texture("mTexture") + , m_normal("mNormal") +#endif {} ~MainShaderConstantSetter() = default; diff --git a/src/serialization.cpp b/src/serialization.cpp index d3009bc83..11164a0ed 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -108,7 +108,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) char output_buffer[bufsize]; int status = 0; int ret; - int bytes_read = 0; int bytes_written = 0; int input_buffer_len = 0; @@ -122,8 +121,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) z.avail_in = 0; - //dstream<<"initial fail="< &privs); diff --git a/src/terminal_chat_console.cpp b/src/terminal_chat_console.cpp index 9e3d33736..b12261c3b 100644 --- a/src/terminal_chat_console.cpp +++ b/src/terminal_chat_console.cpp @@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include "config.h" #if USE_CURSES #include "version.h" @@ -398,7 +399,7 @@ void TerminalChatConsole::step(int ch) minutes = (float)minutes / 1000 * 60; if (m_game_time) - printw(" | Game %d Time of day %02d:%02d ", + printw(" | Game %" PRIu64 " Time of day %02d:%02d ", m_game_time, hours, minutes); // draw text diff --git a/src/unittest/test_irrptr.cpp b/src/unittest/test_irrptr.cpp index 3484f1514..2fb7cfcd6 100644 --- a/src/unittest/test_irrptr.cpp +++ b/src/unittest/test_irrptr.cpp @@ -93,7 +93,9 @@ void TestIrrPtr::testRefCounting() #if defined(__clang__) #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wself-assign-overloaded" + #if __clang_major__ >= 7 + #pragma GCC diagnostic ignored "-Wself-assign-overloaded" + #endif #pragma GCC diagnostic ignored "-Wself-move" #endif diff --git a/src/unittest/test_voxelarea.cpp b/src/unittest/test_voxelarea.cpp index 9826d2ee7..1d72650d7 100644 --- a/src/unittest/test_voxelarea.cpp +++ b/src/unittest/test_voxelarea.cpp @@ -120,7 +120,7 @@ void TestVoxelArea::test_extent() VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669)); UASSERT(v1.getExtent() == v3s16(1191, 995, 1459)); - VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768)); + VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, -32768)); UASSERT(v2.getExtent() == v3s16(16, 16, 16)); } @@ -129,7 +129,7 @@ void TestVoxelArea::test_volume() VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669)); UASSERTEQ(s32, v1.getVolume(), 1728980655); - VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768)); + VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, -32768)); UASSERTEQ(s32, v2.getVolume(), 4096); } diff --git a/src/util/srp.cpp b/src/util/srp.cpp index ceb2fef9e..daa7f332b 100644 --- a/src/util/srp.cpp +++ b/src/util/srp.cpp @@ -354,7 +354,7 @@ static size_t hash_length(SRP_HashAlgorithm alg) case SRP_SHA384: return SHA384_DIGEST_LENGTH; case SRP_SHA512: return SHA512_DIGEST_LENGTH; */ - default: return -1; + default: return 0; }; } // clang-format on @@ -422,7 +422,7 @@ static SRP_Result H_nn( } static SRP_Result H_ns(mpz_t result, SRP_HashAlgorithm alg, const unsigned char *n, - size_t len_n, const unsigned char *bytes, uint32_t len_bytes) + size_t len_n, const unsigned char *bytes, size_t len_bytes) { unsigned char buff[SHA512_DIGEST_LENGTH]; size_t nbytes = len_n + len_bytes; -- cgit v1.2.3