From de1c5dcb3c8f412314023c6f6afe83cd955e3462 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Sun, 24 Sep 2023 18:28:46 +0200 Subject: [PATCH] background for the main menu made with GLSL shaders! --- scenes/main_menu/MainMenu.tscn | 7 +- .../backgrounds/home_screen_dots.gdshader | 83 ++++++------------- 2 files changed, 30 insertions(+), 60 deletions(-) diff --git a/scenes/main_menu/MainMenu.tscn b/scenes/main_menu/MainMenu.tscn index 45c4096..6729b09 100644 --- a/scenes/main_menu/MainMenu.tscn +++ b/scenes/main_menu/MainMenu.tscn @@ -11,8 +11,9 @@ shader = ExtResource("6_xkkpt") shader_parameter/dots_color = Vector4(1, 0.86, 0.83, 1) shader_parameter/bg_color = Vector4(1, 0.95, 0.91, 1) -shader_parameter/grid_size = 50.0 -shader_parameter/dot_size = 0.1 +shader_parameter/radius = 0.09 +shader_parameter/grid_size = 6.0 +shader_parameter/speed = 0.1 [node name="MainMenu" type="Control"] layout_mode = 3 @@ -31,6 +32,8 @@ layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +offset_left = 1.0 +offset_right = 1.0 grow_horizontal = 2 grow_vertical = 2 mouse_filter = 2 diff --git a/themes/default/backgrounds/home_screen_dots.gdshader b/themes/default/backgrounds/home_screen_dots.gdshader index 2f51100..578368d 100644 --- a/themes/default/backgrounds/home_screen_dots.gdshader +++ b/themes/default/backgrounds/home_screen_dots.gdshader @@ -1,65 +1,32 @@ shader_type canvas_item; -uniform vec4 dots_color = vec4(1, 0.86, 0.83, 10); -uniform vec4 bg_color = vec4(0, 0, 0, 0); -uniform float grid_size: hint_range(0.0, 200, 0.1) = 100; -uniform float dot_size: hint_range(0.0, 1.0, 0.01) = 500; - -const float angle = 45.0; -const float RADIANS = angle * 0.0174532; -const ivec2 reps = ivec2(2, 2); -const vec2 mid = vec2(0.5); -const float rad = 0.25; +uniform vec4 dots_color = vec4(1, 0.86, 0.83, 1); +uniform vec4 bg_color = vec4(1, 0.95, 0.91, 1); +uniform float radius: hint_range(0.0, 1.0, 0.01) = .07; +uniform float grid_size: hint_range(1.0, 200.0, 1.00) = 7.; +uniform float speed: hint_range(0.0, 1.0, 0.01) = .2; void fragment() { - vec2 tile_coord = mod(FRAGCOORD.xy * SCREEN_PIXEL_SIZE.x, vec2(1.0 / grid_size)); - - vec2 uv = tile_coord * grid_size - mid; - float len = clamp(length(uv) / dot_size, 0, 1); - + vec2 uv = (FRAGCOORD.xy - (1.0 / SCREEN_PIXEL_SIZE).xy) / min((1.0 / SCREEN_PIXEL_SIZE).x,(1.0 / SCREEN_PIXEL_SIZE).y); + uv *= grid_size; + + // movement + uv.x -= TIME * speed; + uv.y += TIME * speed; + + // Here is where the offset is happening + uv.x += step(1., mod(uv.y,2.0)) * .5; + + // circle + vec2 fractal = fract(uv); + float c = length(.5 - fractal); + float min_dist = min(c, 1.); + // anti-aliased - float sharpness = 50.; - float circ = dot_size * sharpness - length(uv) * sharpness; - - if (abs(circ - 50.) > 50.) { - COLOR = bg_color; - } else { - COLOR = dots_color; - } + float d = length(uv); + float wd = fwidth(d); + float circle = smoothstep(radius + wd, radius - wd, min_dist); - -// // the uv.. we are calling it p for pixel -// vec2 p = FRAGCOORD.xy / SCREEN_PIXEL_SIZE.xy; -// // account for non square image aspect -// p.y *= float(SCREEN_PIXEL_SIZE.y)/ float(SCREEN_PIXEL_SIZE.x); -// //rotating the whole scene -// mat2 rot = mat2(vec2(cos(RADIANS), -sin(RADIANS)), vec2(sin(RADIANS), cos(RADIANS))); -// p *= rot; -// -// -// // q is just an offset - .5 -// vec2 q = p - vec2(0.5, 0.5); -// -// // creates a repeating 0-1 range -// vec2 repeat = vec2(fract(q.x * float(reps.x)), fract(q.y * float(reps.y)) ); -// -// vec2 distFromMid = repeat - mid; -// -// // drawing circles based on distance from center of each cell -// float dist = length(distFromMid); -// -// // anti-aliased -// float sharpness = 50.; -// float circ = rad * sharpness - dist * sharpness; -// // for black on white, subtract rad from dist -// -// // holds the color -// vec3 col; -// if (abs(circ - 50.) > 50.) { -// col = bg_color; -// } else { -// col = dots_color; -// } -// -// COLOR = vec4(col, 1); + // colors + COLOR = mix(bg_color, dots_color, circle); } \ No newline at end of file -- 2.30.2