Search code examples
2dshaderpixelgeometryhlsl

HLSL: Keep Getting An Oval When I Want a Circle! (Pixel Shader)


I'm trying to tint a circle around the player in my 2D side scroller but I keep getting an oval! Here's the part of the code I'm using that matters:

    if(length(abs(coords - playerCoords)) < .1)
    {
        color = color *float4(1,0,1,1);
    }

  return color;

My screen size is 1280 wide x 720 tall. I know that this is the reason for the distortion, but I don't know enough about my issue in order to come up with or find a solution. Can someone explain to me how to compensate for the screen stretch?

Thanks!

-ATD


Solution

  • multiply the "abs()" term by "float2((720./1280.),1.0)" -- or whatever your y/x aspect ration might be

    The coords you are using are normalized in 0-1 space, so just correct them