So I am going mental trying to sort this out
Lights work, shadows don’t
I have gone through the code line by line and cannot see anything wrong, so there must be something fundamentally wrong with my technique
My approach is this
- Create a rendertarget for each object instance
- for each light
Create a rendertarget of type single
Render scene into rendertarget using a depth only shader - for each object
Render into the objects rendertarget using additive blending
Calculate the lighting contribution from the light
Check the depth buffer for shadowing
after a lot of testing I know this function does not work
float CalcShadowTermPCF(float light_space_depth, float ndotl, float2 shadow_coord)
{
float variableBias = clamp(0.001 * tan(acos(ndotl)), 0, DepthBias);
light_space_depth -= variableBias;
float size = 1.0 / 1024.0;
float samples = 0;
if (light_space_depth < tex2D(ShadowSampler, shadow_coord).r)
{
samples = 0.25;
}
if (light_space_depth < tex2D(ShadowSampler, shadow_coord + float2(size, 0)).r)
{
samples += 0.25;
}
if (light_space_depth < tex2D(ShadowSampler, shadow_coord + float2(0, size)).r)
{
samples += 0.25;
}
if (light_space_depth < tex2D(ShadowSampler, shadow_coord + float2(size, size)).r)
{
samples += 0.25;
}
return samples;
}
But I have no idea why
I know the depth buffer is good, I have saved them to disk to check.
I am using linear depth and in the code to save a depth buffer I print the value range for the depth values , which is correct
I have checked all parameters are getting set correctly, the light view projection matrix is correct
I have made sure all the cone angles are correct and fit within the depth buffers field of view
I am out of ideas
Anyone see anything stupid I am doing?