Sign in to follow this  

Trouble with my shadow map

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am trying to use shadow maps, but am having a few issues. My shadow map was always empty. At first I thought it was the projection and view of the light, but now I find out it is simply the pixel shader, which is supposed to be converting the depth info into colour. When I use my pixel shader, the shadow map is blank, it works a bit if I set it to NULL. Heres the result with the pixelshader set to NULL: My problem stems from the way I am trying to store the depth info. Heres my shader code:
//--------------------------------------------
// Global variables
//--------------------------------------------

float4x4	g_matLightWVP		: WORLVIEWPROJECTION;
float4x4	g_matLightViewProj	: VIEWPROJECTION;
float4x4	g_matWorld			: WORLD;


//--------------------------------------------
// Vertex shaders
//--------------------------------------------
struct VSOUTPUT_SHADOW
{
	float4 vPosition	: POSITION;
	float  fDepth		: TEXCOORD0;
};

// Shadow generation vertex shader
VSOUTPUT_SHADOW VS_Shadow( float4 inPosition : POSITION )
{
	// Output struct
	VSOUTPUT_SHADOW OUT = (VSOUTPUT_SHADOW)0;

	g_matLightWVP = mul( g_matWorld, g_matLightViewProj );
	// Output the transformed position
	OUT.vPosition  = mul( inPosition, g_matLightWVP );

	// Output the scene depth
	OUT.fDepth = OUT.vPosition.z;

	return OUT;
}


//--------------------------------------------
// Pixel shaders
//--------------------------------------------
float4  PS_Shadow( VSOUTPUT_SHADOW IN ) : COLOR0
{
	return float4( IN.fDepth,IN.fDepth,IN.fDepth,1.0f );
}


Why does this pixel shader produce a blank shadow map render target? Thanks for any help you can give Simon [Edited by - sipickles on June 12, 2006 3:50:24 PM]

Share this post


Link to post
Share on other sites
Okay, so I thought that maybe my projection matrix was bad, since I was lazy and just had the near plane at 100.0f, and the far plane at 5000000.0f.

This might reduce the resolution of the shadow map to such a point that all the pixels within my scene, which are fairly close, were within the same range.

I reduced the far clipping range to 5000.0f, but its exactly the same result, a blank shadow map.

:(

[Edited by - sipickles on June 12, 2006 3:57:20 PM]

Share this post


Link to post
Share on other sites
Yeah, I actually just encountered this issue yesterday, when working on something completely different.

The output of the transformation, namely:
OUT.vPosition = mul( inPosition, g_matLightWVP );
returns a z value in the range of [0..ZFar], not [0..1].

I'll let someone explain this better than I ever could.. Here's a page on Robert Dunlop's great website.

Hope this helps.

Share this post


Link to post
Share on other sites

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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