0

I'm writing shadow mapping in deferred shading.

Here is my depth map for directional light (orthogonal projection):

depth map

Below is my full-screen quad shader to render pixel's depth in light view space:

#version 330

in vec2 texCoord;
out vec3 fragColor;

uniform mat4 lightViewProjMat; // lightView * lightProj

uniform sampler2D sceneTexture;
uniform sampler2D shadowMapTexture;
uniform sampler2D scenePosTexture;

void main() {
    vec4 fragPos = texture(scenePosTexture, texCoord);
    vec4 fragPosLightSpace = lightViewProjMat * fragPos;

    vec3 coord = fragPosLightSpace.xyz / fragPosLightSpace.w;
    coord = coord * 0.5 + 0.5;

    float lightViewDepth = texture(shadowMapTexture, coord.xy).x;
    fragColor = vec3(lightViewDepth);
}

Render size is 1280x720, depth map's size is 512x512 and look like it is repeating the depth map in my scene. I think my projection for coord isn't right. I want to see if the depth from pixel to light is correct. Could someone give me some suggestions?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • In which space did you store the values in the `scenePosTexture`? Did you check that the problem isn't that you are repeating the `scenePosTexture` because `texCoord` is wrong? – BDL May 24 '18 at 11:08
  • I stored scenePosTexture with world-space positions. I think the coord is wrong somehow. – Manh Nguyen Tien May 24 '18 at 11:18
  • This could be relevant to my problem, testing it: https://stackoverflow.com/questions/22880206/deferred-shadow-mapping-glsl – Manh Nguyen Tien May 24 '18 at 11:34

1 Answers1

0

Solved myself, the problem is depth saving. I saved wrong depth value, should have used gl_FragCoord.z instead.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174