SV_POSITION Output Doesn't Work in Pixel Shader

sample s0;
float4 BackgroundShift(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_POSITION0
{ return pos; }
technique Technique1 { pass Pass1 { PixelShader = compile ps_5_0 BackgroundShift(); } }
I get an error: “invalid ps_5_0 output semantic ‘SV_POSITION0’”.
SV_TARGET0 works for color modifications so why can’t I modify position?

The entire idea of the pixel shader is to modify the color of pixels it returns a color to the current pixel position.

Like the idea of the vertex shader is to modify … ? …

you cannot modify the position of something in the pixel shader, that can only be done before, in the vertex shader.

So in your case you would need to add something like this:

technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_5_0 VertexShaderFunction();
        PixelShader = compile ps_5_0 BackgroundShift();
    }
}

The pixel shader can only work on a pixel with a set position.

However, what you can do in the pixel shader is to read the pixels of an image but with an offset to the left for example, this would look like a texture shift.

An example would be

float4 PixelshaderFunc(float4 pos : SV_POSITION, float2 texCoord : TEXCOORD0) : SV_TARGET0
{
    float4 pixelShift = ScreenTexture.Sample(LinearSampler, texCoord.xy + float2(0.1f, 0.0f));
    return pixelShift; 
}
1 Like

Thank you! This is what I was looking for.

@Dom_DiMaggio In the future, please wrap your code in triple backticks (just once at the start and finish, not every line). It will get formatted way better.