Some bugfixes for the shadows

They work well now!
This commit is contained in:
karl 2021-05-21 20:22:20 +02:00
parent 3c35a730f5
commit 88611815e1
3 changed files with 6 additions and 5 deletions

View File

@ -117,6 +117,6 @@ void main() {
float shadow = get_shadow(fs_in.FragPosLightSpace, normal); float shadow = get_shadow(fs_in.FragPosLightSpace, normal);
// Apply // Apply
FragColor = vec4(ambient + albedo + specular - shadow * 4.0, 1.0); FragColor = vec4(ambient + albedo + specular - shadow * 0.25, 1.0);
} }

View File

@ -77,8 +77,8 @@ class DirectionalLight {
glm::mat4 get_light_space_matrix() { glm::mat4 get_light_space_matrix() {
// TODO: Make the values here configurable // TODO: Make the values here configurable
float near_plane = 1.0f, far_plane = 100.0f; 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 lightProjection = glm::ortho(-20.0f, 20.0f, -20.0f, 20.0f, near_plane, far_plane);
glm::mat4 lightView = glm::lookAt(-direction * 40.0f, direction, glm::vec3(0.0, 1.0, 0.0)); glm::mat4 lightView = glm::lookAt(-direction * 10.0f, direction, glm::vec3(0.0, 1.0, 0.0));
return lightProjection * lightView; return lightProjection * lightView;
} }
@ -96,8 +96,8 @@ class DirectionalLight {
unsigned int depth_map; unsigned int depth_map;
unsigned int depth_map_fbo; unsigned int depth_map_fbo;
const unsigned int SHADOW_WIDTH = 1024; const unsigned int SHADOW_WIDTH = 4096;
const unsigned int SHADOW_HEIGHT = 1024; const unsigned int SHADOW_HEIGHT = 4096;
Gedeng::Shader shadow_shader; Gedeng::Shader shadow_shader;
}; };

View File

@ -90,6 +90,7 @@ class ShadowApp : public Gedeng::Application {
light.render_shadow(monkey_mesh); light.render_shadow(monkey_mesh);
light.render_shadow(quad_mesh); light.render_shadow(quad_mesh);
glViewport(0, 0, 1920, 1080);
glClearColor(0.1, 0.1f, 0.1, 1.0f); glClearColor(0.1, 0.1f, 0.1, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);