Jump to content
  • Advertisement
Sign in to follow this  
supagu

[cg/hlsl] projective tex + shadow check

This topic is 4629 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

i'm writting a basic shadow map shader, i've got the projective texturing part working, but having problems with the depth checking parting. In particular getting the depth current pixels depth.

//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------

struct VS_INPUT
{
    float3 position 	: POSITION;	
    float2 uvCoord 		: TEXCOORD0;
};

struct VS_OUTPUT
{
	float4 position : POSITION;
	float4 uvCoord 	: TEXCOORD0; // should projectors use 0 - n? and lights?
	float4 zDepth	: TEXCOORD1;
};

struct PS_OUTPUT
{
	float4 colour	: COLOR;
};

//-----------------------------------------------------------------------------
// Vertex Shader
//-----------------------------------------------------------------------------

VS_OUTPUT myvs( const VS_INPUT IN,
			uniform float4x4 modelViewProjection,
			uniform float4x4 projection,
			uniform float4x4 projectionTexture)
{
    VS_OUTPUT OUT;
    
   	OUT.position = mul(modelViewProjection, float4(IN.position, 1.0));
							 
	float4 projSpacePos = mul(projectionTexture, float4(IN.position, 1.0));
	OUT.uvCoord = projSpacePos;
	
	float4 sceneDepth = mul(projectionTexture, float4(IN.position, 1.0));
	OUT.zDepth = sceneDepth; //.z;
	
	return OUT;
}

//-----------------------------------------------------------------------------
// Pixel Shader
//-----------------------------------------------------------------------------


PS_OUTPUT myps( VS_OUTPUT IN, uniform sampler2D shadow)
{
	PS_OUTPUT OUT;

	float4 depth = tex2Dproj(shadow, IN.uvCoord);	
	OUT.colour = depth;// (IN.zDepth - 0.1f) < depth.r ? float4(1.0, 1.0, 1.0, 1.0) : float4(0.0, 0.0, 0.0, 0.0);

	OUT.colour = float4(IN.zDepth.z, IN.zDepth.z, IN.zDepth.z, 0.0f);
	
	return OUT;
}
all i get out is black! should i not expect something similar the shadow map texture? even moving the light further or closer has no effect :-/

Share this post


Link to post
Share on other sites
Advertisement
Have you tried copying the shadow map to a texture and rendering it, to see if it actually does contain the correct depth values?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!