Skip to content

Commit 3c874d6

Browse files
authored
Add gradient shader and apply it to piano scene background (#20)
1 parent 6e21eba commit 3c874d6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

app/gradient_shader.gdshader

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
shader_type canvas_item;
2+
3+
// These uniform variables let us control the colors from GDScript if needed
4+
uniform vec4 top_color : source_color = vec4(0.95, 0.95, 0.98, 1.0); // Light blue-gray
5+
uniform vec4 bottom_color : source_color = vec4(0.90, 0.90, 0.95, 1.0); // Slightly darker blue-gray
6+
7+
void fragment() {
8+
// UV.y gives us the vertical position (0 at top, 1 at bottom)
9+
// We use mix() to smoothly blend between the two colors
10+
vec4 gradient_color = mix(top_color, bottom_color, UV.y);
11+
12+
// Apply the color to this pixel
13+
COLOR = gradient_color;
14+
}

app/scenes/piano.tscn

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
[gd_scene load_steps=6 format=3 uid="uid://deocrbvduwvbf"]
1+
[gd_scene load_steps=8 format=3 uid="uid://deocrbvduwvbf"]
22

33
[ext_resource type="Script" path="res://scripts/piano.gd" id="1_16djv"]
44
[ext_resource type="Script" path="res://scripts/note_display.gd" id="2_4lvi2"]
55
[ext_resource type="Script" path="res://scripts/piano_keys.gd" id="3_33fs1"]
66
[ext_resource type="PackedScene" uid="uid://qnn08ykran7h" path="res://scenes/metronome.tscn" id="3_m4k2l"]
77
[ext_resource type="Script" path="res://scripts/exercise_manager.gd" id="5_r2n4b"]
8+
[ext_resource type="Shader" path="res://gradient_shader.gdshader" id="6_v0a7s"]
9+
10+
[sub_resource type="ShaderMaterial" id="ShaderMaterial_s2q7l"]
11+
shader = ExtResource("6_v0a7s")
12+
shader_parameter/top_color = Color(0.241298, 0.45667, 0.596276, 1)
13+
shader_parameter/bottom_color = Color(0.428372, 0.418785, 0.605246, 1)
814

915
[node name="Piano" type="Control"]
1016
layout_mode = 3
@@ -15,6 +21,16 @@ grow_horizontal = 2
1521
grow_vertical = 2
1622
script = ExtResource("1_16djv")
1723

24+
[node name="Background" type="ColorRect" parent="."]
25+
material = SubResource("ShaderMaterial_s2q7l")
26+
layout_mode = 1
27+
anchors_preset = 15
28+
anchor_right = 1.0
29+
anchor_bottom = 1.0
30+
grow_horizontal = 2
31+
grow_vertical = 2
32+
mouse_filter = 2
33+
1834
[node name="NoteDisplay" type="RichTextLabel" parent="."]
1935
layout_mode = 1
2036
anchors_preset = 10

0 commit comments

Comments
 (0)