Sign in to follow this  
virtual_bug

deferred shadow mapping problem

Recommended Posts

Hi everybody, I'm trying to set up a shadow map into a deferred rendering process. Here is my fragment shader :

//vec4 vPositionPXWorldSpace is the world space coord of current pixel, from a g-buffer texture
//mat4 matLightView/ matLightProj  my view & proj light matrix
//sampler2D tShadowMap the depth map from light point of view
//mat4 biasMatrix the standard biasmatrix to convert from screenspace to texturespace


vec4 FragCoordLightViewSpace = matLightView * vPositionPXWorldSpace;
vec4 FragCoordLightProjSpace = matLightProj * FragCoordLightViewSpace;

FragCoordLightProjSpace /= FragCoordLightProjSpace.w;
vec4 FragCoordShadowTexCoord =  biasMatrix * FragCoordLightProjSpace;

float fShadowFactor = texture2D( tShadowMap, FragCoordShadowTexCoord.st).x;
if(fShadowFactor < FragCoordLightProjSpace.z) fShadowFactor = 0.5;
else fShadowFactor = 1;

FragColor = lightResult * fShadowFactor ;
gl_FragData[1] = vec4(fShadowFactor, fShadowFactor, fShadowFactor, 1.0);

but i obtain a full white result, fShadowFactor is everytime = 1. What do I wrong ? Tell me if you need something more. Thanks.

Share this post


Link to post
Share on other sites

There are lots of things that can go wrong.

 

Make sure:

1. The shadow map is bound correctly and you can read values from it using texture2D in the shader. The uniform value of tShadowMap might be setup wrong, the shadow map might be bound to the wrong unit, it is highly possible the sampler state is the culprit (expecting mip-maps that are not present for the generated shadow map).

2. The matrices are correct. Test in on the CPU with a few points and then make sure the results are correct. You might test setting the output color to the computed frag coords to make sure those are correct.

3. gl_FragData[1] writes to the second bound MRT buffer. Don't you want to write to the first?

 

These are probably the most common mistakes, but it could still be something different. Like a wrong format or errors when rendering the shadow map. Try to debug it and make sure which steps are correct and you will quickly identify the problem.

Edited by michalferko

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this