Question

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:

position shadow depth

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top