Jump to content
  • Advertisement
Sign in to follow this  
free27

Shader ignoring depth buffer

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


float4x4 worldViewProj : WorldViewProjection;

texture theTexture

sampler2D sampTexture =
sampler_state
{
Texture = <theTexture>;
AddressU = Wrap;
AddressV = Wrap;
MinFilter = Point;
MagFilter = Linear;
MipFilter = Linear;
};

float3 LightDirView = float3( 1.0f, 0.3f, 1.0f );

struct VS_INPUT
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 Tex : TEXCOORD0;
};

struct VS_OUTPUT
{
float4 hposition : POSITION;
float4 Diffuse : COLOR;
float3 normal : TEXCOORD1;
float2 Tex : TEXCOORD0;
};

struct PS_OUTPUT
{
float4 color : COLOR;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
VS_OUTPUT OUT;

OUT.normal = mul( IN.normal, (float3x3)worldViewProj );

OUT.hposition = mul( worldViewProj, float4(IN.position, 1) );

OUT.Diffuse = dot( LightDirView , IN.normal);

OUT.Tex = IN.Tex;

return OUT;
}

PS_OUTPUT myps( VS_OUTPUT IN )
{
PS_OUTPUT OUT;

OUT.color = tex2D( sampTexture , IN.Tex ) * IN.Diffuse;

return OUT;
}

technique Technique0
{
pass Pass0
{
Lighting = TRUE;
ZEnable = TRUE;

VertexShader = compile vs_2_0 myvs();
PixelShader = compile ps_2_0 myps();
}
}





Hi, will writing my shader in run into a problem, the shader is ignoring the depth buffer.
backface culling is working and everything renders fine without shader.
does anyone have a advise how to fix this?

[Edited by - free27 on July 11, 2010 1:26:16 PM]

Share this post


Link to post
Share on other sites
Advertisement
Do you compile this as effect and use the effect framework?
Have you create your device with a depth buffer?

Share this post


Link to post
Share on other sites
I'm not sure if this is related to your problem but

OUT.hposition = mul( worldViewProj, float4(IN.position, 1) );


isn't that supposed to be

OUT.hposition = mul( float4(IN.position, 1), worldViewProj );


Try changing this, and as Demirug mentionned, make sure you've actually created a depth buffer.

Share this post


Link to post
Share on other sites
switching it around gives the same results

and yes i have a depth buffer, without the shader the rendering works fine.

Share this post


Link to post
Share on other sites
found out what I did wrong.
during some copying around a SetDepthStencilSurface went to the wrong place.
so the StencilSurface was set to 0 instead of the StencilSurface buffer.

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!