Solid square
vec4 square(vec2 uv, float width)
{
uv = uv * 2.0 - 1.0;
vec2 abs_uv = abs(uv.xy);
float square = step(width, max(abs_uv.x, abs_uv.y));
return vec4(vec3(square), 1.0);
}
Outline square
vec4 square_stroke(vec2 uv, float width, float stroke_width)
{
uv = uv * 2.0 - 1.0;
vec2 abs_uv = abs(uv.xy);
float dist = max(abs_uv.x, abs_uv.y);
vec3 stroke = 1.0 - vec3( step(width, dist) - step(width + stroke_width, dist) );
return vec4(vec3(stroke), 1.0);
}
Rounded square
vec4 square_rounded(vec2 uv, float width, float radius){
uv = uv * 2.0 - 1.0;
radius *= width; // make radius go from 0-1 instead of 0-width
vec2 abs_uv = abs(uv.xy) - radius;
vec2 dist = vec2(max(abs_uv.xy, 0.0));
float square = step(width - radius, length(dist));
return vec4(vec3(square), 1.0);
}