In HLSL pixel shader , why is SV_POSITION different to other semantics?
Posted
by
tina nyaa
on Game Development
See other posts from Game Development
or by tina nyaa
Published on 2012-11-25T12:09:44Z
Indexed on
2012/11/25
17:21 UTC
Read the original article
Hit count: 1177
In my HLSL pixel shader, SV_POSITION seems to have different values to any other semantic I use. I don't understand why this is. Can you please explain it?
For example, I am using a triangle with the following coordinates:
(0.0f, 0.5f)
(0.5f, -0.5f)
(-0.5f, -0.5f)
The w and z values are 0 and 1, respectively.
This is the pixel shader.
struct VS_IN
{
float4 pos : POSITION;
};
struct PS_IN
{
float4 pos : SV_POSITION;
float4 k : LOLIMASEMANTIC;
};
PS_IN VS( VS_IN input )
{
PS_IN output = (PS_IN)0;
output.pos = input.pos;
output.k = input.pos;
return output;
}
float4 PS( PS_IN input ) : SV_Target
{
// screenshot 1
return input.pos;
// screenshot 2
return input.k;
}
technique10 Render
{
pass P0
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}
Screenshot 1: http://i.stack.imgur.com/rutGU.png
Screenshot 2: http://i.stack.imgur.com/NStug.png
(Sorry, I'm not allowed to post images until I have a lot of 'reputation')
When I use the first statement (result is first screenshot), the one that uses the SV_POSITION
semantic, the result is completely unexpected and is yellow, whereas using any other semantic will produce the expected result. Why is this?
© Game Development or respective owner