From 88611815e14d71e44c5a3859a0711c1a0ffd1692 Mon Sep 17 00:00:00 2001 From: karl Date: Fri, 21 May 2021 20:22:20 +0200 Subject: [PATCH] Some bugfixes for the shadows They work well now! --- Shader/bump.fs | 2 +- include/Gedeng/DirectionalLight.h | 8 ++++---- test/shadow-demo/main.cpp | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Shader/bump.fs b/Shader/bump.fs index 7ba6d4d..e733523 100644 --- a/Shader/bump.fs +++ b/Shader/bump.fs @@ -117,6 +117,6 @@ void main() { float shadow = get_shadow(fs_in.FragPosLightSpace, normal); // Apply - FragColor = vec4(ambient + albedo + specular - shadow * 4.0, 1.0); + FragColor = vec4(ambient + albedo + specular - shadow * 0.25, 1.0); } diff --git a/include/Gedeng/DirectionalLight.h b/include/Gedeng/DirectionalLight.h index 3fffc7f..8ad2241 100644 --- a/include/Gedeng/DirectionalLight.h +++ b/include/Gedeng/DirectionalLight.h @@ -77,8 +77,8 @@ class DirectionalLight { glm::mat4 get_light_space_matrix() { // TODO: Make the values here configurable float near_plane = 1.0f, far_plane = 100.0f; - glm::mat4 lightProjection = glm::ortho(-40.0f, 40.0f, -40.0f, 40.0f, near_plane, far_plane); - glm::mat4 lightView = glm::lookAt(-direction * 40.0f, direction, glm::vec3(0.0, 1.0, 0.0)); + glm::mat4 lightProjection = glm::ortho(-20.0f, 20.0f, -20.0f, 20.0f, near_plane, far_plane); + glm::mat4 lightView = glm::lookAt(-direction * 10.0f, direction, glm::vec3(0.0, 1.0, 0.0)); return lightProjection * lightView; } @@ -96,8 +96,8 @@ class DirectionalLight { unsigned int depth_map; unsigned int depth_map_fbo; - const unsigned int SHADOW_WIDTH = 1024; - const unsigned int SHADOW_HEIGHT = 1024; + const unsigned int SHADOW_WIDTH = 4096; + const unsigned int SHADOW_HEIGHT = 4096; Gedeng::Shader shadow_shader; }; diff --git a/test/shadow-demo/main.cpp b/test/shadow-demo/main.cpp index 862050e..c125fac 100644 --- a/test/shadow-demo/main.cpp +++ b/test/shadow-demo/main.cpp @@ -90,6 +90,7 @@ class ShadowApp : public Gedeng::Application { light.render_shadow(monkey_mesh); light.render_shadow(quad_mesh); + glViewport(0, 0, 1920, 1080); glClearColor(0.1, 0.1f, 0.1, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);