延迟阴影映射GLSL [英] Deferred Shadow Mapping GLSL
问题描述
我目前正在实施延迟的渲染管道,并且一直陷于阴影映射中. 我已经成功地将其实现到转发管道中.
Im currently implementing a deferred rendering pipeline and im stuck with shadow mapping. Ive already implemented it succesfully into a forward pipeline.
我要做的步骤是:
- 在Light View中获取位置
- 转换为浅色视图片段空间
- 使用* 0.5 + 0.5获取阴影tex坐标;
- 检查深度
使用新的结果图像更新代码:
float checkShadow(vec3 position) {
// get position in light view
mat4 invView = inverse(cameraView);
vec4 pEyeDir = sunBias * sunProjection * sunView * invView * vec4(position, 1.0);
// light view clip space
pEyeDir = pEyeDir / pEyeDir.w;
// get uv coordinates
vec2 sTexCoords = pEyeDir.xy * 0.5 + 0.5;
float bias = 0.0001;
float depth = texture(sunDepthTex, sTexCoords).r - bias;
float shadow = 1.0f;
if(pEyeDir.z * 0.5 + 0.5 > depth)
{
shadow = 0.3f;
}
return shadow;
}
这里有一些对于上面的代码很重要的变量:
here some variables important for the code above:
vec3 position = texture(positionTex, uv).rgb;
在某些相机位置,我也会得到深色背景(网格保持不变),仅当我将阴影值乘以最终颜色时才会发生.
Also i get a dark background( meshes stay the same) at some camera positions, only happens when i multiply the shadow value to the final color.
根据要求,以下是位置和太阳深度纹理:
As requested, here are the position and sun depth texture:
推荐答案
好,我修复了它.问题在于,光深度的大小与gbuffer纹理的大小不同.
Ok i fixed it. The problem was because the light depth had a different size than the gbuffer textures.
要使用不同的纹理大小,我必须使用它们进行归一化
To use different texture sizes i had to normalize them with
coords = (coords / imageSize ) * windowSize;
这篇关于延迟阴影映射GLSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!