Fix bug in VSM texture
This commit is contained in:
parent
8c5b04ad97
commit
da460af0b1
@ -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)
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user