阴影贴图:将世界空间像素投影到光空间 [英] Shadow mapping: project world-space pixel to light-space

查看:118
本文介绍了阴影贴图:将世界空间像素投影到光空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用延迟着色编写阴影映射.

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

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

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?

推荐答案

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

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

这篇关于阴影贴图:将世界空间像素投影到光空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆