Last active
December 24, 2024 11:49
-
-
Save Shilo/5bc4cfa9b8910fdec4e6c773704a8c3b to your computer and use it in GitHub Desktop.
Godot 4 shader to create icon decorations (bordered and optional circle).
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 vec3 border_color: source_color = vec3(0); | |
uniform float border_width: hint_range(0, 10) = 0; | |
uniform bool circle = false; | |
void fragment() { | |
float center = 0.5; | |
float border_width_uv = border_width * min(TEXTURE_PIXEL_SIZE.x, TEXTURE_PIXEL_SIZE.y); | |
float border_start = center - border_width_uv; | |
if (circle) { | |
if (step(border_start, length(UV - vec2(center, center))) == 1.0) { | |
COLOR.rgb = border_color; | |
} | |
COLOR.a *= step(length(UV - vec2(center, center)), center); | |
} else { | |
if (step(border_start, abs(UV.x - center)) == 1.0 || | |
step(border_start, abs(UV.y - center)) == 1.0) { | |
COLOR.rgb = border_color; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment