Sign in to follow this  

HLSL Pixel Shader returns (0,0,0,0)

This topic is 2040 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.
There is a shader which implements shadow map technique
[code]struct VS_INPUT { float4 Pos : POSITION0; float4 Normal: NORMAL; float4 Color : COLOR; float2 TexCoords : TEXCOORD0; float4 TexWeights : TEXCOORD1; };

float4x4 xLightWorld;
float4x4 xLightView;
float4x4 xLightProjection;

struct SMapVertexToPixel { float4 Position : POSITION0; float4 Position2D : POSITION1; };

SMapVertexToPixel ShadowMapVertexShader(VS_INPUT In)
{ SMapVertexToPixel Output = (SMapVertexToPixel)0;
Output.Position = mul(In.Pos, xLightWorld);
Output.Position = mul(Output.Position, xLightView);
Output.Position = mul(Output.Position, xLightProjection);
Output.Position2D = Output.Position; return Output; }

float4 ShadowMapPixelShader(SMapVertexToPixel PSIn) : COLOR
{
return float4(PSIn.Position2D.z/PSIn.Position2D.w, 0, 0, 1);
}[/code]

I run this code in PIX in Debugger window and for some pixel i have
[code]
ShadowMapPixelShader | ( 0.161, 0.000, 0.000, 1.000 ) | float4
[/code]
but in Render window all pixels are black.
If i change code
[code]
float4 ShadowMapPixelShader(SMapVertexToPixel PSIn) : COLOR
{
return float4(0.5f, 0, 0, 1);
}
[/code]
all pixels will be little bit red.
Why?

Share this post


Link to post
Share on other sites
Can you check in pix that your matrices are definitely being set?

May I also ask why Output.Position and Output.Position2D are identical? Seems a bit of a waste of space and resources...

Share this post


Link to post
Share on other sites
[quote name='NickUdell' timestamp='1336736804' post='4939270']
Can you check in pix that your matrices are definitely being set?

May I also ask why Output.Position and Output.Position2D are identical? Seems a bit of a waste of space and resources...
[/quote]
Hello.
My matrices are set. I can see it in Mesh window of Pix (Pre-vertex shader, Post-Vertex shader and Viewport is correct).
Output.Position and Output.Position2D are identical because i thought that after vertex shader i can't use a Position field in the Pixel Shader.

Share this post


Link to post
Share on other sites
You can use the position value in the pixel shader, it'll be interpolated between the vertices so it will be the position at that pixel.

Looks to me like you're outputting depth at that point. What are you near and far plane values? If you have a really large range then the object might appear with a very dark colour due to how far away it is. Could you set it to return 1 - depth to make sure it's definitely setting the pixel colour there?

Share this post


Link to post
Share on other sites

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