Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Apr 2013
Offline Last Active Apr 26 2013 11:26 PM

Topics I've Started

Need some help with shadow mapping

08 April 2013 - 11:48 PM

I'm new to shadow mapping.  I've followed some tutes on the net, but can't get this working.

I've created a terrain using a heightmap and textured it comparing slope and height.  All that's working.

Then I tried getting shadows to work.  I've created a shadow map by using the orthographic projection (for the sun) - projection matrix and view matrix from the light.  I've translated the current vertex/pixel to light-space.  I then used a texture sampler to lookup depth value from the shadow map texture.  At the moment I'm just testing if a pixel is in shadow or not.  If it's in shadow I add the shadow by darkening the pixel.  I've checked the tutes and my code "seems" OK, but no shadows show up.  I've attached the shadow map the was generated and some HLSL code.


Vertex Shader:


output.LightPosition = mul(input.Position, lightWorldViewProj);

output.LightPosition /= output.LightPosition.w;


return output;



Pixel Shader:






projectedTexCoords[0] = input.LightPosition.x / 2.0f + 0.5f;



projectedTexCoords[1] = input.LightPosition.y / -2.0f + 0.5f;



float depthStoredInShadowMap = shadowMap.Sample(shadowMapSampler, projectedTexCoords).r;


float realDistance = input.LightPosition.z;


if ((realDistance - 1.0f / 100.0f) <= depthStoredInShadowMap)


colour.xyz *= 0.25f;



return colour;




edit:  It seems that the line float depthStoredInShadowMap = shadowMap.Sample(shadowMapSampler, projectedTexCoords).r; is always returning zero??

What is happening??