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.
output.LightPosition = mul(input.Position, lightWorldViewProj);
output.LightPosition /= output.LightPosition.w;
projectedTexCoords = input.LightPosition.x / 2.0f + 0.5f;
projectedTexCoords = 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;
edit: It seems that the line float depthStoredInShadowMap = shadowMap.Sample(shadowMapSampler, projectedTexCoords).r; is always returning zero??
What is happening??