Corner radius
I couldn’t find a good simple and working shader for corner-radius anywhere so here’s what I came up with. You need to set the radius in range 0 – 1, not in pixels.
- 0 = no radius
- 1 = full circle / ellipse
Shader code
shader_type canvas_item;
uniform float corner_scale: hint_range(0., 1.) = 0.;
bool isOut(float x, float y) {
return pow(x, 2.) + pow(y, 2.) > pow(corner_scale * .5, 2.);
}
void fragment() {
float s = corner_scale * .5;
if (
(UV.x < s && UV.y < s && isOut(UV.x - s, UV.y - s)) ||
(UV.x < s && UV.y > 1. - s && isOut(UV.x - s, UV.y - 1. + s)) ||
(UV.x > 1. - s && UV.y < s && isOut(UV.x - 1. + s, UV.y - s)) ||
(UV.x > 1. - s && UV.y > 1. - s && isOut(UV.x - 1. + s, UV.y - 1. + s))
) {
COLOR.a = 0.;
}
}