I am trying to apply a post processing effect to all pixels outside of a certain range of my character.
This is the shader code I have so far for converting my players position into screenspace and testing each fragment against it.
//Worldspace Player Pos
float4 _PlayerPosition;
float4 Frag(VaryingsDefault i) : SV_Target
{
float4 playerPositionClipSpace = mul(unity_MatrixVP,_PlayerPosition);
float3 playerPositionScreenSpace = playerPositionClipSpace.xyz / playerPositionClipSpace.w;
playerPositionScreenSpace = playerPositionScreenSpace * 0.5 + 0.5;
float4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
if (length(playerPositionScreenSpace.xy - i.texcoord) >= 0.1f)
{
color.rgb = float3(0,0,0);
}
return color;
}
My problem is, that the resulting circle is somehow not centered on the given character position.
Would appreciate if someone has an idea for why that may be the case