Skip to content

Instantly share code, notes, and snippets.

@Lightnet
Created July 11, 2025 16:16
Show Gist options
  • Save Lightnet/c3472b7943ba29bf153d730e887129a5 to your computer and use it in GitHub Desktop.
Save Lightnet/c3472b7943ba29bf153d730e887129a5 to your computer and use it in GitHub Desktop.
Using the shader for circle menu godot 4
shader_type canvas_item;
uniform float segment_width = 0.2; // Angular width of each segment (radians)
uniform float inner_radius = 0.1; // Inner radius of segments (UV space, 0.0–0.5)
uniform float outer_radius = 0.5; // Outer radius of segments (UV space, 0.0–0.5)
uniform float rotation_offset = 0.0; // Rotation offset in radians
uniform int segments = 8; // Number of segments (menu items)
uniform int selected_index = 0; // Selected segment (0–7)
uniform vec4 line_color = vec4(1.0, 1.0, 1.0, 1.0); // Non-selected segment color
uniform vec4 selected_color = vec4(1.0, 0.5, 0.5, 1.0); // Selected segment color
uniform float background_opacity = 0.3; // Background circle opacity
void fragment() {
vec2 uv = UV - 0.5; // Center UV (0.5, 0.5 is center)
float dist = length(uv); // Distance from center
float angle = atan(uv.y, uv.x); // Pixel angle
// Apply rotation offset
angle = mod(angle + rotation_offset + 2.0 * 3.14159265, 2.0 * 3.14159265);
float segment_angle = 2.0 * 3.14159265 / float(segments); // Angle per segment
// Calculate segment index for the pixel
int pixel_segment = int(angle / segment_angle) % segments;
// Check if pixel is within a segment's angular width
float angle_diff = mod(angle, segment_angle);
float center_angle = segment_angle * 0.5;
bool is_segment = abs(angle_diff - center_angle) < segment_width * 0.5 && dist >= inner_radius && dist <= outer_radius;
// Check if pixel is in the selected segment
bool is_selected = (pixel_segment == selected_index) && is_segment;
// Draw background circle
vec4 color = vec4(0.0); // Transparent default
if (dist >= inner_radius && dist <= outer_radius) {
color = vec4(0.2, 0.2, 0.2, background_opacity); // Background
}
// Draw segments
if (is_segment) {
color = is_selected ? selected_color : line_color;
}
COLOR = color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment