Firstly, the cast to int
is counter productive. You have float
values and don't want to loose precision by casting to int
, which will always be one of {0, 1 ... 4 * radius^2}
.
Furthermore, the comparison to == 0
needs some luck to be hit. If you want to fill the circle, use <= 0
or if you want to draw a line try something like abs(...) <= epsilon
where epsilon is some small number that describes the line's thickness.
Be aware that you just set the r-component of the returned color of 1. This does not need to result in a red circle (e.g. if you already have a white texture).
I would do something like the following:
float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
{
float dx = coords.x - 0.5f;
float dy = coords.y - 0.5f;
if(dx * dx + dy * dy <= 0.25f)
return float4(1.0f, 0.0f, 0.0f, 1.0f);
else
return float4(0.0f, 0.0f, 0.0f, 0.0f);
}
Notice that you don't need an explicit radius or center because the texture coordinates are normalized.