Deferred Shadow Mapping GLSL

北城以北 提交于 2019-12-11 03:04:03

问题


Im currently implementing a deferred rendering pipeline and im stuck with shadow mapping. Ive already implemented it succesfully into a forward pipeline.

The Steps i do are:

  1. Get Position in Light View
  2. Convert to light view clip space
  3. Get shadow tex coords with * 0.5 + 0.5;
  4. check depth

Edit: Updated code with new result image:

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:


回答1:


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;


来源:https://stackoverflow.com/questions/22880206/deferred-shadow-mapping-glsl

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