My shadow mapping is not correct : with some scenes i get the shadow somewhere but not at the right place no matter what is the value of the epsilon, and with some others a big part of the scene is in the dark and the other not...
I have only one spot light in my scene.
here is my code which does it (with explanations below) :
float shadowing(psIn IN)
{
float4 texCoord = mul( tex2D(positionMap, IN.texCoord), shadowWarpMatrix );
texCoord.xyz /= texCoord.w ;
float shadowed = (tex2D( shadowMap, texCoord ).r) > (IN.lightSpacePosition + epsilon ) ? 0.20 : 1.0 ;
return shadowed;
}
shadowWarpMatrix variable is lightViewProjMatrix * texMatrix:
float textureOffsetX = 0.5f + (0.5f / SHADOW_MAP_SIZE_X);
float textureOffsetY = 0.5f + (0.5f / SHADOW_MAP_SIZE_Y);
D3DXMATRIX texMatrix( 0.5f, 0.0f, 0.0f, 0.0f,
0.0f, -0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f
textureOffsetX, textureOffsetY, 0.0f, 1.0f );
And the lightSpacePosition variable is (in the vertex shader) :
OUT.lightSpacePosition = mul( position, lightViewProj ).z ;
[attachment=4911:bug.png]