Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created December 24, 2024 11:09
Show Gist options
  • Save Shilo/46711a5807e9b28cac2a2029665cd299 to your computer and use it in GitHub Desktop.
Save Shilo/46711a5807e9b28cac2a2029665cd299 to your computer and use it in GitHub Desktop.
Godot 4 simple canvas item shader to add inner border.
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 border_width_uv = border_width * max(TEXTURE_PIXEL_SIZE.x, TEXTURE_PIXEL_SIZE.y);
if (step(0.5 - border_width_uv, abs(UV.x - 0.5)) == 1.0 ||
step(0.5 - border_width_uv, abs(UV.y - 0.5)) == 1.0) {
COLOR = border_color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment