I am trying to implement the cascaded shadow map as given in the shaderx7 book. My issue is that i have the code written
that works fine in ATI 8400 gs card but its not working in Nvidia 8400 gs card.
How can i resolve this issue of hardware problem? Is this the hardware problem or something we should take care for different cards i mean in the codings?
Here is the screenshot that is being shown in nvidia card where you can clearly see the shadow depth that has been generated well and stored in the atlas. But i am not getting shadow in the scene which is actually working fine in the ATI card and i can see there.
http://www.postimage.org/image.php?v=PqsLuQ9
[img=http://s3.postimage.org/sLuQ9.jpg]
This is how i am generating four matrices for picking the right shadow depth from the shadow depth texture atlas map.
D3DXMATRIX textureMatrix[4];
//set special texture matrix for shadow mapping
float fOffsetX = 0.25f + (0.5f / (float)m_dShadowMapSize);
float fOffsetY = 0.25f + (0.5f / (float)m_dShadowMapSize);
for(int i=0; i<4; i++)
{
D3DXMATRIX texScaleBiasMat( 0.25f, 0.0f, 0.0f, 0.0f,
0.0f, -0.25f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
fOffsetX+0.5f * (i % 2), fOffsetY+0.5f * (i / 2), 0.5f, 1.0f );
D3DXMatrixMultiply(&textureMatrix, &m_mLightViewProj, &texScaleBiasMat);
}
Here is the part of the shader's code that is generating the shadow in the scene
Vertex Shader Part:
// Output the screen-space texture coordinates
OUT.ScreenProjection1 = mul(TransformPos, matLightViewProjection[0]);
OUT.ScreenProjection2 = mul(TransformPos, matLightViewProjection[1]);
OUT.ScreenProjection3 = mul(TransformPos, matLightViewProjection[2]);
OUT.ScreenProjection4 = mul(TransformPos, matLightViewProjection[3]);
Pixel Shader Part:
float shadow = 0.0f;
float depth = 0.0f;
float2 sample_texcoord = IN.ScreenProjection1.xy / IN.ScreenProjection1.w;
if(max(abs(sample_texcoord.x - 0.25),abs(sample_texcoord.y - 0.25)) < 0.24)
{
depth = IN.ScreenProjection1.z/IN.ScreenProjection1.w;
}
else
{
sample_texcoord = IN.ScreenProjection2.xy / IN.ScreenProjection2.w;
if(max(abs(sample_texcoord.x - 0.75),abs(sample_texcoord.y - 0.25)) < 0.24)
{
depth = IN.ScreenProjection2.z/IN.ScreenProjection2.w;
}
else
{
sample_texcoord = IN.ScreenProjection3.xy / IN.ScreenProjection3.w;
if(max(abs(sample_texcoord.x - 0.25),abs(sample_texcoord.y - 0.75)) < 0.24)
{
depth = IN.ScreenProjection3.z/IN.ScreenProjection3.w;
}
else
{
sample_texcoord = IN.ScreenProjection4.xy / IN.ScreenProjection4.w;
if(max(abs(sample_texcoord.x - 0.75),abs(sample_texcoord.y - 0.75)) < 0.24)
{
depth = IN.ScreenProjection4.z/IN.ScreenProjection4.w;
}
else
{
shadow = 1.0f;
}
}
}
}
// calculate shadow
if(shadow == 0.0f)
{
shadow = (tex2D(ShadowSampler, sample_texcoord.xy).r + SHADOW_EPSILON < depth) ? 0.0f : 1.0f;
}