Don't know, but maybe this doesn't seem to work. I am trying to do shadow mapping and I checked shadow map is getting rendered correctly but all I see is everything is unlit. That means shadow factor is zero. The Shadowmap is ok (I checked). So now, I suspect it's the SamplerComparisonState not getting correctly uploaded or projective texture coordinates not getting correctly or Shadow map not getting correctly uploaded (although I checked this).
This doesn't seem to work
ShadowFactor[0] is always zero.
float ShadowFactor[MAX_DIR_LIGHTS] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
if (NumDirLights > 0)
{
float4 ambient = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 spec = float4(0.0f, 0.0f, 0.0f, 0.0f);
ShadowFactor[0] = CalculateShadowFactor(SamShadow, ShadowMap, pin.ShadowPosH);
[unroll]
for (int i = 0; i < NumDirLights; ++i)
{
float4 A, D, S;
ComputeDirectionalLight(ObjectMaterial, DirLights[i], pin.NormalW, toEye, A, D, S);
ambient += A;
diffuse += D * ShadowFactor[i];
spec += S * ShadowFactor[i];
}
FinalColor = TexColor * (ambient + diffuse) + spec;
FinalColor.a = ObjectMaterial.Diffuse.a * TexColor.a;
}
EDIT: I confirmed and I am 200% sure that the issue is related to SamplerComparisonState (SamShadow). Cause I declared a undefined SamplerComparisonState and passed it in CalculateShadowFactor() instead of SamShadow and I got the same result.
EDIT: GOT THE ISSUE!
I used D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT instead of D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT while declaring SamplerComparisonState in D3D11 API. Just one typo made me work all day long on this