Sign in to follow this  
idreamlovey

Cascaded shadow problem

Recommended Posts

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 [url=http://www.postimage.org/image.php?v=PqsLuQ9][img=http://s3.postimage.org/sLuQ9.jpg][/url] 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[i], &m_mLightViewProj[i], &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;
	}

Share this post


Link to post
Share on other sites
Code looks fine to me. Not sure what kind of card is that "ATI 8400 gs" but try setting different render formats of your shadow maps, like R32F or R16B16G16F and so on, maybe some of them will work on Nvidia.

You don't using hardware shadow maps as I see, because they do need to be implemented differently for some older ATI cards.

Share this post


Link to post
Share on other sites
Thanx for your concern.

Problem is solved. The cause is astonishing and never had encountered with it.

I was using vertex shader 2.0 and pixel shader 3.0

pass P0

{
// shaders
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_3_0 PS();

}


After changing the vertex shader version from 2.0 to 3.0. It is solved.
Now i8 can see my demo in both cards.

Thnx again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this