I am new to HLSL and Directx. I was trying to write a simple gradient Shader by modifying one of Microsoft samples.
1.I can not understand why SV_POSITION is float4? If it is pixel coordinates shouldn't it have only x and y ? What are the 4 parts? I think SV_POSITION is not between 0,1 and the maximum val is bufferWidth,bufferHeight ... then how can I get the position between 0,1?
- The first code does not work because distance between float2 and float4 is impossible. While the second one works I get a warning. How can I avoid the warning message because I believe something is wrong!
Fist code (Of course it should not work):
float4 VS( float4 Pos : POSITION ) : SV_POSITION
{
return Pos;
}
float4 PS( float4 Pos : SV_POSITION) : SV_Target
{
float distfromcenter=distance(float2(0.5f, 0.5f), Pos);
float4 rColor = lerp(float4(0,0,0,1),float4(1,1,1,1), saturate(distfromcenter));
return rColor;
}
The second one :
float4 VS( float4 Pos : POSITION ) : SV_POSITION
{
return Pos;
}
float4 PS( float2 Pos : TEXTCOORD ) : SV_Target
{
float distfromcenter=distance(float2(0.5f, 0.5f), Pos);
float4 rColor = lerp(float4(0,0,0,1),float4(1,1,1,1), saturate(distfromcenter));
return rColor;
}
Why do I get this warning ? How can I compile this Shader using SV_POSITION to avoid the warning message ?
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (TEXTCOORD,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
TEXTCOORD
and the vertex shader does not provide that (which is exactly what the warning is telling you). But that has nothing to do withSV_POSITION
. \$\endgroup\$ – Nathan Reed Jan 2 '14 at 16:54