Pixel Shader never gets called, but is set?

Started by
6 comments, last by haansn08 10 years, 8 months ago

Hello there,

I'm trying to draw some "terrain" (when you can call a displaced grid without color a terrain ^^),

and (again) nothing is shown on the screen.

With the graphics debugging tools of VS2012 I found out that there is no pixel shader stage similiar to this problem:

http://msdn.microsoft.com/en-us/library/vstudio/jj191650.aspx

Altough I do set a pixel shader:

missing-pixel-shader.png

The code of my pixel shader:


struct VertexOut
{
	float4 pos : POSITION;
	float4 col : COLOR;
};
float4 main(VertexOut input) : SV_TARGET
{
	return input.col;
}
Advertisement
Not sure if this is directly related to your pixel shader problem, but looking at your VertexOut struct I'm concerned about the semantics. If this is all what your vertex shader spits out (and you don't have any other stages between vertex and pixel shader) this can't work. You need the SV_Position system value semantic. The debug runtime should complain about this.

Is VertexOut the data you're returning in your vertex shader? If you're passing in the projected vertices i think you need to set the semantic for your pos as SV_Position(or SV_POSITION?); not just POSITION. Oops unbird already said this...

As an addition though... if the clip space vertices are also not in the viewport, your pixel shader won't get called too. So once you've get the semantics fixed and your pixel shader still isn't running, double check your view proj matrices and make sure you're passing these matrices to your shaders. Or just hard code the clip space values and pass these to your pixel shader.

MS says that it is ok to use non SV_ Semantics. In that current case POSITION semantic is unrealted. The error could be anywere. Try something like this :

float4 ps_main(): SV_TARGET

{

return float4(1.f, 1.f, 0.f, 1.f);//or other ugly color
}

That code will eventually prove that the problem is not in the PS.

After that try this:

float4 ps_main(float col : COLOR): SV_TARGET

{

return col;//or other ugly color
}

Double check your projection view matrices!!!!

Hm changing the VertexOut structure to:


struct VertexOut
{
	float4 pos : SV_POSITION;
	float4 col : COLOR;
};

didn't help much.

Returning any color in the pixel shader neither did.

But I'm pretty sure that the matrices are correct since the image under "Vertex Shader" looks like this:

Vertex-Shader(PID%204156).png

The very least, your view matrix looks correct. Can we see your entire shader code? Also are you setting your viewport?

Yes. This code creates the viewport:


//Set the viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(viewport));
viewport.Width = float(width);
viewport.Height = float(height);
viewport.MaxDepth = 1.0f;
_devcon->RSSetViewports(1, &viewport);

And my vertex shader code:


cbuffer perObject
{
	float4x4 worldViewProj;
};
struct VertexOut
{
	float4 pos : SV_POSITION;
	float4 col : COLOR; 
};
VertexOut main( float4 pos : POSITION)
{
	VertexOut ret;
	ret.pos = mul(pos, worldViewProj);

	ret.col = float4(1.0f,1.0f,1.0f,1.0f);

	return ret;
}

Hm. Probably the bug is somewhere else.

I have attached the source code of the whole project now.

This topic is closed to new replies.

Advertisement