Shadow mapping: project world-space pixel to light-space

喜欢而已 提交于 2019-12-11 16:15:29

问题


I'm writing shadow mapping in deferred shading.

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

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?


回答1:


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



来源:https://stackoverflow.com/questions/50507646/shadow-mapping-project-world-space-pixel-to-light-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!