Original Post
I'm very new to graphics programming/HLSL and I'm trying to implement shadow mapping into my engine. I am trying to follow this article but it's very hard without a sample to help. I understand the idea of comparing the depth of the pixel being rendered and the depth on the shadow map, but something is going wrong somewhere. I can render a shadow map:

But this is the final render I get:

I think something is going wrong when I transform the pixel location to a position relative to the light source, I still haven't really got my head around world view and projection matricies so I think I'm going wrong there somewhere. Here is the shader code:
Where lightViewMatrix is the view matrix of the light where the shadow depth is rendered from.
Any tips would be greatly appreciated!

But this is the final render I get:

I think something is going wrong when I transform the pixel location to a position relative to the light source, I still haven't really got my head around world view and projection matricies so I think I'm going wrong there somewhere. Here is the shader code:
float4 shadowWVP;
shadowWVP = mul(input.position, worldMatrix);
shadowWVP = mul(shadowWVP, lightViewMatrix);
shadowWVP = mul(shadowWVP, projectionMatrix);
output.ShadowSamplePos = mul( float4(input.position*100), shadowWVP);
output.RealDist = output.ShadowSamplePos.z / 100.0f;
output.Pos3D = input.position;
Where lightViewMatrix is the view matrix of the light where the shadow depth is rendered from.
float4 Shadow = 1.0f;
float2 screencoords = ( ( input.screenPos.xy / input.screenPos.w ) + 1.0f ) * 0.5f;
screencoords.y = 1.0f - screencoords.y;
//Sample the shadow-space depth from the scene rendered
// in shadow space:
float currentDepth = ShadowDepthTexture.Sample(ShadowSampler, screencoords);
//We apply a little bias to the depth values so that our geometry
// doesn't, for the most part, shadow itself.
if (!((input.RealDist -1.0f/100.0f) <= currentDepth))
{
Shadow.rgb *= 0.2f;
}
Colour *= Shadow;
Colour = saturate(Colour);
return Colour;
Any tips would be greatly appreciated!

