Last active
December 24, 2024 10:58
-
-
Save Shilo/aeadccfaf26d4a31160291ba553b7a2e to your computer and use it in GitHub Desktop.
Godot 4 simple canvas item shader to create a circle mask.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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