Circle Shader
Shader code
shader_type canvas_item;
uniform float amt : hint_range(0.0, 1.0);
uniform vec4 color : hint_color;
void fragment()
{
if (distance(UV, vec2(0.5,0.5)) > amt/2.0)
{
COLOR = vec4(0.0);
}
else
{
COLOR = vec4(color);
}
}
Evaluating an if statement on every fragment is generally bad practice. Try to stay away from if statements in shaders unless absolutely necessary.
For applying “boolean” operations in a shader, use the step, smoothstep, and mix functions. Here’s a more optimized version of this shader:
I also added an “edge_softness” value if you want to anti-alias the edges of the circle a bit
Awesome work, thanks for your input Nekoto!