I'm trying to get my cascaded shadow maps implementation working and I'm facing a problem that I'm stuck on.
This is the intended shadow for the car:
http://www.steik.org/dump/Cosmopolis2010-04-1100-20-55-11.png
This is however what I will see with a slightly different item-to-split population:
http://www.steik.org/dump/Cosmopolis2010-04-1100-21-28-51.png
During my debugging I came up with a dirty hack in the PCF function to at least make the wrong areas not black (shadowed)
(see the first if statement)
if (vTexCoord.z >= 0.999)
{
ret = 1;
}
else
{
// 2x2 PCF Filtering
float fShadow[4];
fShadow[0] = (vTexCoord.z - DepthBias[split] < tex2D(sam, vTexCoord + float2(0, 0)).r);
fShadow[1] = (vTexCoord.z - DepthBias[split] < tex2D(sam, vTexCoord + float2(TexelSize, 0)).r);
fShadow[2] = (vTexCoord.z - DepthBias[split] < tex2D(sam, vTexCoord + float2(0, TexelSize)).r);
fShadow[3] = (vTexCoord.z - DepthBias[split] < tex2D(sam, vTexCoord + float2(TexelSize, TexelSize)).r);
float2 vLerpFactor = frac(ShadowMapSize * vTexCoord.xy);
ret = lerp(lerp(fShadow[0], fShadow[1], vLerpFactor.x), lerp(fShadow[2], fShadow[3], vLerpFactor.x), vLerpFactor.y);
}
This is what happens with the hack:
http://www.steik.org/dump/Cosmopolis2010-04-1100-20-51-76.png
As you can see this is also a problem with the first split in all pictures.
In all cases the geometry IS clearly being written in the depth map (see frames 1 and 2 on the top from the left), so I think it is just some stupid texture coordinate problem.
I however have no idea pretty much why or how to fix this.
I am basing my code on "Chapter 10: Parallel-Split Shadow Maps on Programmable GPUs" from GPU Gems 3.
Clearly the LightViewProjection is correct since the depth maps are being drawn correctly, and the only thing I do extra when I sample it later is this:
LightViewProjectionCropped * shadowMapTextureScale
where the scaling matrix is a relatively standard matrix:
float shadowMapTexOffset = 0.5f + (0.5f / (float)shadowMapSize);
return new Matrix(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, -0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
shadowMapTexOffset, shadowMapTexOffset, 0.0f, 1.0f);
So yeah.. This error doesn't really make sense to me since the depth maps are being drawn right. Any ideas?