Basically what I did was delete everything and start from the basics.
I've (for now) manually defined my view and orthographic projection and been trying to project this onto my scene.
The shadow map works fine. My problem (still) seems to be with the actual projection.
What I do is pretty simple:
VSO VS(VSI input)
{
VSO output = (VSO)0;
output.Position = float4(input.Position.xyz, 1.0f);
output.UV = input.UV;
output.PositionVS = mul(input.Position, InverseProjection).xyz;
return output;
}
float4 PS(VSO input) : SV_TARGET0
{
float4 output = float4(0.0f, 0.0f, 0.0f, 1.0f);
float depth = DepthTarget.Sample(PointSampler, input.UV).r;
float3 viewRay = input.ViewRay.xyz;
float4 PositionVS = float4(viewRay * depth, 1.0f);
float4x4 ViewToLightViewProj = mul(InverseView, LightViewProjection);
float4 PositionLS = mul(PositionVS, ViewToLightViewProj);
float LightDepth = PositionLS.z / PositionLS.w;
float2 ShadowUV = PositionLS.xy / PositionLS.w;
ShadowUV.x = ShadowUV.x / 2.0f + 0.5f;
ShadowUV.y = ShadowUV.y / -2.0f + 0.5f;
float ShadowTerm = 0;
float sample0 = ShadowMap.Sample(PointSampler, ShadowUV).x;
if(sample0 < LightDepth)
{
ShadowTerm = 0.0f;
}
else
{
ShadowTerm = 1.0f;
}
return ShadowTerm;
}
Can someone tell me what I'm fundamentally doing wrong ?