uniform float amt : hint_range(0.0, 1.0);
uniform vec4 color : hint_color;
if (distance(UV, vec2(0.5,0.5)) > amt/2.0)
COLOR = vec4(0.0);
COLOR = vec4(color);
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.
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!