2
votes

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.

enter image description here

As requested, here are the position and sun depth texture:

positionshadow depth

1
some images to show?? what syncronicity..:-)j-p
at first sight, it's strange that you use eye vector to compute shadowTexCoord. it's should be computed with translate(0.5,0.5) * scale(0.5,0.5) * lightProj * lightView * vertexPos - ( modelTransformations * vertexPos)j-p
the image you see is the result of NOT using the eye vector. i used only the position from the position texture. Is the objects model matrix needed? isnt that what the gbuffer position texture is for?Raphael Mayer
vec4 ModWorldPos = inverse(gl_ModelViewMatrix) * gl_Vertex - inverse(modelView) * gl_Vertex ; ShadowCoord= gl_TextureMatrix[7] * (gl_Vertex - ModWorldPos); here is mine, texture matrix is translate(0.5,0.5) * scale(0.5,0.5) * lightProj * lightViewj-p
are you sure you use deferred rendering? i dont know how i should pass each model matrix to the deferred pass, as this is only a shaded quad. And you use deprecated glsl functions like glTextureMatrix. i use 4.2 core.Raphael Mayer

1 Answers

4
votes

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;