diff --git a/data/shaders/fs_deferred_lighting.glsl b/data/shaders/fs_deferred_lighting.glsl index b66a5bf..0cc8e32 100644 --- a/data/shaders/fs_deferred_lighting.glsl +++ b/data/shaders/fs_deferred_lighting.glsl @@ -18,6 +18,7 @@ uniform sampler2D uPosition; uniform vec3 uLightDirection; uniform mat4 uLightSpaceMatrix; uniform mat4 uViewToLightSpaceMatrix; +uniform float uShadowBias; in vec2 ioFragTexCoords; @@ -30,7 +31,7 @@ float ShadowCalculationPCF(vec4 frag_pos_light_space, vec3 frag_normal_light_spa float current_depth = projected_coordinates.z; float bias = 0.00; - bias = max(0.02 * (1.0 - dot(frag_normal_light_space, uLightDirection)), 0.003); + bias = max(0.01 * (1.0 - dot(frag_normal_light_space, uLightDirection)), uShadowBias); float shadow = 0.0; vec2 texel_size = 1.0 / textureSize(uShadowMap, 0); diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index 9616ab5..f4fecb1 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -208,6 +208,7 @@ void Light::DrawGui() { ImGui::SliderFloat("Volume Size", &mBBoxSize, 1.0f, 50.0f); ImGui::SliderFloat("Near", &mNear, -10.0f, 50.0f); ImGui::SliderFloat("Far", &mFar, -10.0f, 50.0f); + ImGui::SliderFloat("Shadow Bias", &mShadowBias, 0.0f, 0.01f, "%.5f", 1.0f); ImVec2 content_avail = ImGui::GetContentRegionAvail(); @@ -699,6 +700,7 @@ void Renderer::RenderGl() { Vector3f light_direction = view_mat_rot * mLight.mDirection.normalized(); mDeferredLighting.SetVec3("uLightDirection", light_direction.normalized()); + mDeferredLighting.SetFloat("uShadowBias", mLight.mShadowBias); gVertexArray.Bind(); gScreenQuad.Draw(GL_TRIANGLES); diff --git a/src/modules/RenderModule.h b/src/modules/RenderModule.h index 3064115..3aca00b 100644 --- a/src/modules/RenderModule.h +++ b/src/modules/RenderModule.h @@ -29,6 +29,7 @@ struct Light { float mNear; float mFar; float mBBoxSize; + float mShadowBias = 0.003; Matrix44f mLightSpaceMatrix;