Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by sas_x86 May 8, 2012 at 3:13 PM 2 replies 1.7k views
Original Post
sas_x86
sas_x86
Hello.
There is a shader which implements shadow map technique
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);
}


I run this code in PIX in Debugger window and for some pixel i have

ShadowMapPixelShader | ( 0.161, 0.000, 0.000, 1.000 ) | float4

but in Render window all pixels are black.
If i change code

float4 ShadowMapPixelShader(SMapVertexToPixel PSIn) : COLOR
{
return float4(0.5f, 0, 0, 1);
}

all pixels will be little bit red.
Why?
NickUdell
NickUdell
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...
Sole Creator of Pigment - a procedural, block-base space trading sim.

PhD student working on medical imaging at the University of Southampton.

Enjoyer of games, films, books and cider.
sas_x86
sas_x86

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...

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.
NickUdell
NickUdell
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?
Sole Creator of Pigment - a procedural, block-base space trading sim.

PhD student working on medical imaging at the University of Southampton.

Enjoyer of games, films, books and cider.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.