Cascaded shadow problem

Started by
3 comments, last by idreamlovey 13 years, 11 months ago
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;
	}

Advertisement
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.
Its ati radeon 8400 gs card where its working and its not working in the nvidia 8400 gs card.
Yeah i have changed it to R32F but no luck :(
Does the sample from shaderx 7 work on your Nvidia 8400 gs video card ?
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!

This topic is closed to new replies.

Advertisement