I’m trying to figure out, why SV_POSITION and POSITION1 are not calculated and interpolated the same way between Vertex- and PixelShader.
I’ve been looking for hours now and I guess, it’ll be pretty easy, if you know it already :D. I understand that SV_POSITION is given as normalized coordinates between {-1,-1} and {1,1}. What would I have to do, to get the same for both semantics?
struct VIn
{
float4 position : POSITION0;
}
struct VOut
{
float4 positionA : SV_POSITION;
float4 positionB : POSITION1;
}
VOut VS( in VIn input )
{
// Do usual calculations like World, View, Projection
...
VOut output;
output.positionA = input.position;
output.positionB = input.position;
}
float4 PS( VOut input ) : COLOR
{
// Here input.positionA and input.positionB differ
// What do I have to do, to get the same values?
}
If however you mean to do something like you need extra vertex coordinates per vertex passed in like your doing something really complicated, you must create a vertex definition and then the struct must match on the shader im guessing however you aren’t and the above is what you need.
Hi @willmotil,
unfortunately that’s not what I was looking for. I need something that’s transformed exactly the same way like the 3D position. I want to change the vertex in the vertex shader but carry the orignal vertex and its transformation with me, because I need the depth value at the position of the original value.
Please have a look into the code example given above.
brings me almost there. It converts my coordinates to texture coordinates, which seems to be pretty much the same like what happens to positionA between vertex and pixel shader.
Normal vertex shader outputs like texcoords just get interpolated in the pixel shader and nothing else is happening to them. SV_POSITION is special. It’s used to calculate screenspace positions, that’s why it goes through one extra processing step that’s happening automatically. To get screenspace positions you have to divide by what’s in the w-coponent. In your case to take PositionB to screen space you have to do the same thing