From fd3facb076eacdec50d5d1703bc2022dca3231ef Mon Sep 17 00:00:00 2001 From: Haze Weathers Date: Thu, 27 Feb 2025 03:38:07 -0500 Subject: [PATCH] winning confetti --- assets/shaders/confetti_spin.gdshader | 15 ++++++++ objects/goal_post.gd | 4 ++ objects/goal_post.tscn | 54 ++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 assets/shaders/confetti_spin.gdshader diff --git a/assets/shaders/confetti_spin.gdshader b/assets/shaders/confetti_spin.gdshader new file mode 100644 index 0000000..7c8d095 --- /dev/null +++ b/assets/shaders/confetti_spin.gdshader @@ -0,0 +1,15 @@ +shader_type spatial; +render_mode unshaded, cull_disabled; + +uniform float spin_speed = 2.0; + +void vertex() { + float angle = TIME * spin_speed; + vec4 q = vec4(sin(angle), 0.0, 0.0, cos(angle)); + vec3 temp = cross(q.xyz, VERTEX) + q.w * VERTEX; + VERTEX = VERTEX + 2.0 * cross(q.xyz, temp); +} + +void fragment() { + ALBEDO = COLOR.rgb; +} \ No newline at end of file diff --git a/objects/goal_post.gd b/objects/goal_post.gd index 21c8819..3c79219 100644 --- a/objects/goal_post.gd +++ b/objects/goal_post.gd @@ -2,6 +2,10 @@ class_name GoalPost extends Node3D +@export var win_confetti: GPUParticles3D + + func _on_player_detector_body_entered(body: Node3D) -> void: if body is Player: body.enter_goal(self) + win_confetti.emitting = true diff --git a/objects/goal_post.tscn b/objects/goal_post.tscn index 880dbcf..d82a81e 100644 --- a/objects/goal_post.tscn +++ b/objects/goal_post.tscn @@ -1,8 +1,48 @@ -[gd_scene load_steps=9 format=3 uid="uid://cdpgby3r6xe4n"] +[gd_scene load_steps=17 format=3 uid="uid://cdpgby3r6xe4n"] [ext_resource type="Script" path="res://objects/goal_post.gd" id="1_08x2x"] [ext_resource type="Shader" path="res://assets/shaders/flag.gdshader" id="2_xbid5"] [ext_resource type="Texture2D" uid="uid://cyxkbck2gs2wt" path="res://assets/textures/objects/goal_hole.png" id="3_yg6kd"] +[ext_resource type="Shader" path="res://assets/shaders/confetti_spin.gdshader" id="4_2tajh"] + +[sub_resource type="Gradient" id="Gradient_lo531"] +interpolation_mode = 1 +offsets = PackedFloat32Array(0, 0.167, 0.333, 0.5, 0.667, 0.833) +colors = PackedColorArray(0.146381, 0.624043, 1, 1, 0.15, 1, 0.390833, 1, 1, 0.15, 0.15, 1, 1, 0.15, 0.915, 1, 0.971667, 1, 0.15, 1, 1, 0.64, 0.2, 1) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_gj1wn"] +gradient = SubResource("Gradient_lo531") +width = 32 + +[sub_resource type="Curve" id="Curve_7j88s"] +_data = [Vector2(0, 0), 0.0, 11.4029, 0, 0, Vector2(0.218593, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), -4.44921, 0.0, 0, 0] +point_count = 3 + +[sub_resource type="CurveTexture" id="CurveTexture_pewo3"] +width = 32 +curve = SubResource("Curve_7j88s") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_afbs2"] +particle_flag_rotate_y = true +angle_min = -720.0 +angle_max = 720.0 +direction = Vector3(0, 1, 0) +spread = 15.0 +initial_velocity_min = 2.0 +initial_velocity_max = 5.0 +gravity = Vector3(0, -2, 0) +scale_curve = SubResource("CurveTexture_pewo3") +color_initial_ramp = SubResource("GradientTexture1D_gj1wn") + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_ctg8p"] +render_priority = 0 +shader = ExtResource("4_2tajh") +shader_parameter/spin_speed = 5.0 + +[sub_resource type="PlaneMesh" id="PlaneMesh_phfae"] +material = SubResource("ShaderMaterial_ctg8p") +size = Vector2(0.2, 0.2) +orientation = 2 [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_e2vbu"] shading_mode = 2 @@ -37,11 +77,21 @@ center_offset = Vector3(1, 0, 0) [sub_resource type="CylinderShape3D" id="CylinderShape3D_eshe3"] height = 0.5 -[node name="GoalPost" type="Node3D"] +[node name="GoalPost" type="Node3D" node_paths=PackedStringArray("win_confetti")] script = ExtResource("1_08x2x") +win_confetti = NodePath("Graphics/WinConfetti") [node name="Graphics" type="Node3D" parent="."] +[node name="WinConfetti" type="GPUParticles3D" parent="Graphics"] +emitting = false +amount = 32 +lifetime = 2.0 +one_shot = true +explosiveness = 0.8 +process_material = SubResource("ParticleProcessMaterial_afbs2") +draw_pass_1 = SubResource("PlaneMesh_phfae") + [node name="Pole" type="MeshInstance3D" parent="Graphics"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) mesh = SubResource("CylinderMesh_i27ie")