diff --git a/Shader/bump.fs b/Shader/bump.fs index 046d1fd..1d8d309 100644 --- a/Shader/bump.fs +++ b/Shader/bump.fs @@ -82,6 +82,7 @@ float get_shadow(vec4 fragPosLightSpace, vec3 normal) { mediump float currentDepth = projCoords.z; // check whether current frag pos is in shadow float p = step(projCoords.z, moments.x); + // We divide by this later, so make sure it's not exactly 0 // It seems like it should always be 0.0, but due to interpolation it's not -- it increases with the deviation! // A larger second parameter to max() means more blur (but also more light bleeding) diff --git a/Shader/shadow.fs b/Shader/shadow.fs index 4019afe..4bb749a 100644 --- a/Shader/shadow.fs +++ b/Shader/shadow.fs @@ -1,7 +1,9 @@ #version 430 +out vec4 FragColor; + void main() { // The mean and the mean squared, which we need to calculate the variance - gl_FragColor = vec4(gl_FragCoord.z, gl_FragCoord.z * gl_FragCoord.z, 0.0, 0.0); + FragColor = vec4(gl_FragCoord.z, gl_FragCoord.z * gl_FragCoord.z, 0.0, 0.0); } \ No newline at end of file diff --git a/include/Gedeng/DirectionalLight.h b/include/Gedeng/DirectionalLight.h index 1cfdb02..468f5c6 100644 --- a/include/Gedeng/DirectionalLight.h +++ b/include/Gedeng/DirectionalLight.h @@ -19,8 +19,7 @@ class DirectionalLight { // Create depth texture glGenTextures(1, &depth_map); glBindTexture(GL_TEXTURE_2D, depth_map); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, - NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_RGB, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -28,9 +27,7 @@ class DirectionalLight { // Attach depth texture as FBO's depth buffer glBindFramebuffer(GL_FRAMEBUFFER, depth_map_fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_map, 0); - glDrawBuffer(GL_NONE); - glReadBuffer(GL_NONE); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, depth_map, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); } diff --git a/test/shadow-demo/main.cpp b/test/shadow-demo/main.cpp index ccae6da..855acbf 100644 --- a/test/shadow-demo/main.cpp +++ b/test/shadow-demo/main.cpp @@ -92,10 +92,10 @@ class ShadowDemo : public Gedeng::Application { void dynamic_update(double delta) override { // Shadows light.clear_shadows(); + light.render_shadow(quad_mesh); light.render_shadow(mesh1); light.render_shadow(mesh2); light.render_shadow(mesh3); - light.render_shadow(quad_mesh); glViewport(0, 0, 1920, 1080); glClearColor(0.1, 0.1f, 0.1, 1.0f);