I'm trying to use a fullscreen triangle to draw menu backgrounds now, for this I use the following shader:
Texture2D Texture;
SamplerState textureSampler;
struct VSQuadOut{
float4 position : SV_Position;
float2 texcoord: TexCoord;
};
VSQuadOut VertexShaderFunction(uint VertexID: SV_VertexID)
{
VSQuadOut Out;
Out.texcoord = float2((VertexID << 1) & 2, VertexID & 2);
Out.position = float4(Out.texcoord * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
return Out;
}
float4 PixelShaderFunction(VSQuadOut input) : SV_TARGET
{
float4 textureColor = Texture.Sample(textureSampler, input.texcoord);
textureColor.a = 1;
return textureColor;
}
technique fsQuad
{
pass Pass1
{
VertexShader = compile vs_4_0 VertexShaderFunction();
PixelShader = compile ps_4_0 PixelShaderFunction();
}
};
However, the background is totally black. When debugging the shader it shows that Out.position returns NaN on all 4 components. From googling around I know that several people use this shader and it's working for them, so what could cause this?