Adds drop shadow shader to sprites

master
TechieDamien 2025-08-02 15:09:35 +01:00
parent 9a97a0cc9e
commit 2ca1b6aa44
Signed by: TechieDamien
GPG Key ID: 2ACE3574E164B780
7 changed files with 67 additions and 4 deletions

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://bldekmt1rakjl"]
[gd_scene load_steps=5 format=3 uid="uid://bldekmt1rakjl"]
[ext_resource type="Script" uid="uid://dcdogfvb8xjod" path="res://Scripts/fruit.gd" id="1_o20pv"]
[ext_resource type="Material" uid="uid://b3rufg8frc82r" path="res://Shaders/drop_shadow.tres" id="1_t6yr1"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hf2pu"]
size = Vector2(18, 18)
@ -15,6 +16,7 @@ script = ExtResource("1_o20pv")
shape = SubResource("RectangleShape2D_hf2pu")
[node name="Sprite2D" type="Sprite2D" parent="."]
material = ExtResource("1_t6yr1")
texture = SubResource("PlaceholderTexture2D_kum7e")
[node name="Label" type="Label" parent="."]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=4 uid="uid://bs6an72avch86"]
[gd_scene load_steps=19 format=4 uid="uid://bs6an72avch86"]
[ext_resource type="Texture2D" uid="uid://dxdtqv4do4x31" path="res://Sprites/background.png" id="1_6bp64"]
[ext_resource type="PackedScene" uid="uid://gkqku38yb2ng" path="res://Scenes/level.tscn" id="1_bo1nx"]
@ -7,6 +7,7 @@
[ext_resource type="PackedScene" uid="uid://mp03fsd536be" path="res://Scenes/score_display.tscn" id="4_jjvhh"]
[ext_resource type="PackedScene" uid="uid://bqg3ohs1gwofr" path="res://Scenes/game_over_menu.tscn" id="5_kry3j"]
[ext_resource type="Texture2D" uid="uid://dr54j1cutgpf2" path="res://Sprites/tile.png" id="6_21xkr"]
[ext_resource type="Material" uid="uid://b3rufg8frc82r" path="res://Shaders/drop_shadow.tres" id="7_wsu2k"]
[ext_resource type="Texture2D" uid="uid://c6kno4vjbvu28" path="res://Sprites/ouroboros.png" id="8_ynf5e"]
[ext_resource type="Script" uid="uid://8jbramxjbw1w" path="res://Scripts/ouroboros.gd" id="9_hptm8"]
[ext_resource type="Texture2D" uid="uid://bbutodjdye61j" path="res://Sprites/cherry.png" id="10_fdnlq"]
@ -78,6 +79,7 @@ offset_right = 812.0
offset_bottom = 475.0
[node name="Ouroboros2" type="Sprite2D" parent="GameOverMenu"]
material = ExtResource("7_wsu2k")
position = Vector2(237, 118)
scale = Vector2(0.5, 0.5)
texture = ExtResource("8_ynf5e")
@ -89,6 +91,7 @@ tile_map_data = PackedByteArray("AAADAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAFAAAAAAAAAAA
tile_set = SubResource("TileSet_344ge")
[node name="Ouroboros" type="Sprite2D" parent="."]
material = ExtResource("7_wsu2k")
position = Vector2(84, 90)
scale = Vector2(0.5, 0.5)
texture = ExtResource("8_ynf5e")
@ -98,18 +101,22 @@ script = ExtResource("9_hptm8")
position = Vector2(-1, 56)
[node name="Cherry" type="Sprite2D" parent="FruitExamples"]
material = ExtResource("7_wsu2k")
position = Vector2(39, 503)
texture = ExtResource("10_fdnlq")
[node name="Lemon" type="Sprite2D" parent="FruitExamples"]
material = ExtResource("7_wsu2k")
position = Vector2(38, 542)
texture = ExtResource("11_jkdf5")
[node name="Apple" type="Sprite2D" parent="FruitExamples"]
material = ExtResource("7_wsu2k")
position = Vector2(93, 509)
texture = ExtResource("12_wsu2k")
[node name="Watermelon" type="Sprite2D" parent="FruitExamples"]
material = ExtResource("7_wsu2k")
position = Vector2(92, 541)
texture = ExtResource("13_k12tt")

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=20 format=3 uid="uid://bu5cwjawsnb1q"]
[gd_scene load_steps=21 format=3 uid="uid://bu5cwjawsnb1q"]
[ext_resource type="Script" uid="uid://bomw4j2mmerry" path="res://Scripts/main_menu.gd" id="1_28flt"]
[ext_resource type="Texture2D" uid="uid://dxdtqv4do4x31" path="res://Sprites/background.png" id="2_48xlc"]
[ext_resource type="Texture2D" uid="uid://c6kno4vjbvu28" path="res://Sprites/ouroboros.png" id="3_ce3w2"]
[ext_resource type="Material" uid="uid://b3rufg8frc82r" path="res://Shaders/drop_shadow.tres" id="3_t1dhk"]
[ext_resource type="Script" uid="uid://dp3dc6g76g8wq" path="res://Scripts/menu_ouroboros.gd" id="4_n45e2"]
[ext_resource type="Texture2D" uid="uid://bbutodjdye61j" path="res://Sprites/cherry.png" id="5_trj04"]
[ext_resource type="Script" uid="uid://ctoqmgqe06xjw" path="res://Scripts/instruction_label.gd" id="5_vr1f0"]
@ -111,12 +112,14 @@ offset_bottom = 38.0
[node name="Ouroboros" type="Sprite2D" parent="Title"]
modulate = Color(0.545, 0, 0, 1)
material = ExtResource("3_t1dhk")
position = Vector2(241, 130)
texture = ExtResource("3_ce3w2")
script = ExtResource("4_n45e2")
[node name="Ouroboros2" type="Sprite2D" parent="Title"]
modulate = Color(0, 0.502, 0, 1)
material = ExtResource("3_t1dhk")
position = Vector2(574, 176)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_ce3w2")
@ -124,6 +127,7 @@ script = ExtResource("4_n45e2")
[node name="Ouroboros3" type="Sprite2D" parent="Title"]
modulate = Color(0.4, 0.2, 0.6, 1)
material = ExtResource("3_t1dhk")
position = Vector2(776, 178)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_ce3w2")
@ -131,6 +135,7 @@ script = ExtResource("4_n45e2")
[node name="Ouroboros4" type="Sprite2D" parent="Title"]
modulate = Color(1, 0.270588, 0, 1)
material = ExtResource("3_t1dhk")
position = Vector2(947, 181)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_ce3w2")

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://d0okbjqyaoe0w"]
[gd_scene load_steps=5 format=3 uid="uid://d0okbjqyaoe0w"]
[ext_resource type="Script" uid="uid://cn4hlmm4qa8fg" path="res://Scripts/snake_part.gd" id="1_iuiyg"]
[ext_resource type="Texture2D" uid="uid://b0can5myhke8s" path="res://Sprites/snake_straight.png" id="2_hf2pu"]
[ext_resource type="Material" uid="uid://b3rufg8frc82r" path="res://Shaders/drop_shadow.tres" id="2_kum7e"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hf2pu"]
size = Vector2(18, 18)
@ -13,6 +14,7 @@ script = ExtResource("1_iuiyg")
shape = SubResource("RectangleShape2D_hf2pu")
[node name="Sprite2D" type="Sprite2D" parent="."]
material = ExtResource("2_kum7e")
texture = ExtResource("2_hf2pu")
[node name="DownRayCast2D" type="RayCast2D" parent="."]

View File

@ -0,0 +1,38 @@
shader_type canvas_item;
uniform vec4 drop_shadow_color : source_color = vec4(vec3(0), float(0.5));
uniform vec2 shadow_offset = vec2(float(0), float(0.1));
varying vec4 modulate;
void vertex() {
modulate = COLOR;
float max_offset = abs(shadow_offset.x);
if (abs(shadow_offset.y) > abs(shadow_offset.x)) {
max_offset = abs(shadow_offset.y);
}
VERTEX *= float(1) + float(2) * max_offset;
}
vec4 sample_texture(sampler2D texture, vec2 uv) {
if ((uv.x < 0.0 || uv.x > 1.0) || (uv.y < 0.0 || uv.y > 1.0)) {
return vec4(0.0);
} else {
return texture(texture, uv);
}
}
vec4 mixcolor(vec4 colA, vec4 colB) {
return vec4((colA.rgb + colB.a * (colB.rgb - colA.rgb)), colA.a + colB.a);
}
void fragment() {
float max_offset = abs(shadow_offset.x);
if (abs(shadow_offset.y) > abs(shadow_offset.x)) {
max_offset = abs(shadow_offset.y);
}
vec2 uv = UV * float(float(1) + float(2) * max_offset) - vec2(max_offset);
vec4 original_color = sample_texture(TEXTURE, uv) * modulate;
vec4 shadow_color = vec4(drop_shadow_color.rgb, sample_texture(TEXTURE, uv - shadow_offset).a * drop_shadow_color.a);
if (shadow_color.a > float(0)) {
COLOR = mixcolor(shadow_color, original_color);
} else {
COLOR = original_color;
}
}

View File

@ -0,0 +1 @@
uid://dh2ljlr3vprkh

8
Shaders/drop_shadow.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://b3rufg8frc82r"]
[ext_resource type="Shader" uid="uid://dh2ljlr3vprkh" path="res://Shaders/drop_shadow.gdshader" id="1_kutx4"]
[resource]
shader = ExtResource("1_kutx4")
shader_parameter/drop_shadow_color = Color(0, 0, 0, 0.5)
shader_parameter/shadow_offset = Vector2(0.05, 0.05)