Skip to content

Instantly share code, notes, and snippets.

@rohanrhu
Created February 14, 2021 20:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohanrhu/11ffd387e1cc228d15bcea56fad4f593 to your computer and use it in GitHub Desktop.
Save rohanrhu/11ffd387e1cc228d15bcea56fad4f593 to your computer and use it in GitHub Desktop.
Godot Engine (GLSL) Border Radius Shader
shader_type canvas_item;
uniform float radius: hint_range(0., 1.) = 1;
uniform bool animate = false;
uniform float square_scale: hint_range(0., 1.) = 0.1;
void fragment() {
float sc = square_scale + square_scale/2.;
float r = square_scale + (1. - radius) * (square_scale/2.);
float scax = 1. - square_scale;
float dx;
float dy;
float d;
float a;
COLOR = texture(TEXTURE, UV);
if (UV.x < square_scale && UV.y > scax) {
dx = square_scale - UV.x;
dy = scax - UV.y;
d = sqrt(pow(dx, 2.) + pow(dy, 2.));
a = asin(d);
if (a > r) {
if (!animate) {
COLOR.a = 0.;
} else if (a > sc * sin(3.14 * fract(TIME))) {
COLOR.a = 0.;
}
}
}
if (UV.x < square_scale && UV.y < square_scale) {
dx = square_scale - UV.x;
dy = square_scale - UV.y;
d = sqrt(pow(dx, 2.) + pow(dy, 2.));
a = asin(d);
if (a > r) {
if (!animate) {
COLOR.a = 0.;
} else if (a > sc * sin(3.14 * fract(TIME))) {
COLOR.a = 0.;
}
}
}
if (UV.x > scax && UV.y < square_scale) {
dx = scax - UV.x;
dy = square_scale - UV.y;
d = sqrt(pow(dx, 2.) + pow(dy, 2.));
a = asin(d);
if (a > r) {
if (!animate) {
COLOR.a = 0.;
} else if (a > sc * sin(3.14 * fract(TIME))) {
COLOR.a = 0.;
}
}
}
if (UV.x > scax && UV.y > scax) {
dx = scax - UV.x;
dy = scax - UV.y;
d = sqrt(pow(dx, 2.) + pow(dy, 2.));
a = asin(d);
if (a > r) {
if (!animate) {
COLOR.a = 0.;
} else if (a > sc * sin(3.14 * fract(TIME))) {
COLOR.a = 0.;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment