Jump to content
  • Advertisement
Sign in to follow this  

deferred shadow mapping problem

This topic is 2094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!