Skip to content

Instantly share code, notes, and snippets.

@Shilo
Last active December 24, 2024 10:58
Show Gist options
  • Save Shilo/aeadccfaf26d4a31160291ba553b7a2e to your computer and use it in GitHub Desktop.
Save Shilo/aeadccfaf26d4a31160291ba553b7a2e to your computer and use it in GitHub Desktop.
Godot 4 simple canvas item shader to create a circle mask.
shader_type canvas_item;
uniform vec4 border_color: source_color = vec4(1.0);
uniform float border_width: hint_range(0, 10) = 0;
void fragment() {
float alpha = step(length(UV - vec2(0.5, 0.5)), 0.5);
if (alpha > 0.0) {
float border_width_uv = border_width * max(TEXTURE_PIXEL_SIZE.x, TEXTURE_PIXEL_SIZE.y);
if (step(0.5 - border_width_uv, length(UV - vec2(0.5, 0.5))) == 1.0) {
COLOR = border_color;
}
} else {
COLOR.a = 0.0;
}
}
shader_type canvas_item;
void fragment() {
COLOR.a *= step(length(UV - vec2(0.5, 0.5)), 0.5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment