0
votes

For whatever reason, the renderer seems to ignore the semantics for the first argument, and always passes the pixel position. Even if a different argument has the SV_POSITION semantic, the position still gets passed as the first argument. Is there a reason for this?

Vertex shader:

cbuffer transforms
{
    float4x4 view, projection;
};

void main(
    in float4 inPos : POSITION, in float3 inNorm : NORMAL,
    out float4 outPos : SV_POSITION, out float3 outNorm : TEXCOORD0
    )
{
    outPos = mul(projection, mul(view, inPos));
    outNorm = inNorm;
}

Pixel shader:

void main(
    float4 inPos : SV_POSITION, in float3 inNorm : TEXCOORD0,
    out float4 outClr : SV_TARGET
    )
{
    outClr.xyz = inNorm * 0.5 + 0.5;
    outClr.w = 1.0;
}
1

1 Answers

0
votes

That is because POSITION and SV_Position mean basically the same thing. POSITION is the Direct3D 9 era semantic for vertex position. SV_Position is the Direct3D 10+ era semantic for vertex position.

You can use a number of different patterns here, but to go with your pattern, you should use an inout for the position:

void main(
    inout float4 pos : SV_Position, in float3 inNorm : NORMAL,
    out float3 outNorm : TEXCOORD0
    )
{
    pos = mul(projection, mul(view, pos));
    outNorm = inNorm;
}

Also, you need to be consistent with your HLSL usage of POSITION vs. SV_Position in your vertex shader and how you declare your Direct3D 10.x/11.x input layouts, as well as your VS vs. PS for them to bind properly.