Jump to content

  • Log In with Google      Sign In   
  • Create Account


deferred shadow mapping problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 virtual_bug   Members   -  Reputation: 108

Like
0Likes
Like

Posted 21 October 2013 - 05:53 AM

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.



Sponsor:

#2 michalferko   Members   -  Reputation: 546

Like
0Likes
Like

Posted 21 October 2013 - 02:12 PM

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, 21 October 2013 - 02:12 PM.


#3 virtual_bug   Members   -  Reputation: 108

Like
0Likes
Like

Posted 22 October 2013 - 10:08 AM

Thanks for your answer, the problem is fixed now, I just compared wrong things.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS