阴影贴图:将世界空间像素投影到光照空间

时间:2018-05-24 10:59:57

标签: opengl projection opengl-3 deferred-rendering deferred-shading

我在延迟着色中编写阴影贴图。

这是我的定向光(正交投影)深度图:

depth map

下面是我的全屏四边形着色器,用于在光线视图空间中渲染像素的深度:

#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);
}

渲染尺寸为1280x720,深度贴图的尺寸为512x512,看起来它在我的场景中重复深度贴图。我认为我对coord的投射是不对的。我想看看从像素到光的深度是否正确。有人可以给我一些建议吗?

1 个答案:

答案 0 :(得分:0)

解决了自己,问题是深度节省。我保存了错误的深度值,应该使用gl_FragCoord.z代替。

相关问题