Spatial 2D sound w/ reverb, first attempt

This commit is contained in:
ChaoticByte 2024-10-05 09:50:03 +02:00
parent 7833a1c756
commit 3ec5a9edf7
No known key found for this signature in database
17 changed files with 192 additions and 13 deletions

6
main/main.gd Normal file
View file

@ -0,0 +1,6 @@
extends Node
func _ready() -> void:
NodeRegistry.player = %Player
NodeRegistry.level_root_container = %LevelRootContainer
Levels.load_menu()

67
main/main.tscn Normal file
View file

@ -0,0 +1,67 @@
[gd_scene load_steps=6 format=3 uid="uid://c13h0uf5fgx60"]
[ext_resource type="Script" path="res://main/main.gd" id="1_m407c"]
[ext_resource type="PackedScene" uid="uid://dxp3dru2lrv6h" path="res://core/shaders/outline/outline_canvas_layer.tscn" id="2_ta1pa"]
[ext_resource type="PackedScene" uid="uid://jmy11lqcs4c" path="res://core/shaders/distortion/distortion_canvas_layer.tscn" id="3_emkei"]
[ext_resource type="Script" path="res://main/text_viewport.gd" id="4_hxymt"]
[ext_resource type="PackedScene" uid="uid://ebb4pfxklatj" path="res://player/player.tscn" id="5_0agpg"]
[node name="Main" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_m407c")
[node name="MainViewportContainer" type="SubViewportContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stretch = true
[node name="MainViewport" type="SubViewport" parent="MainViewportContainer"]
handle_input_locally = false
canvas_item_default_texture_filter = 0
audio_listener_enable_2d = true
size = Vector2i(800, 450)
render_target_update_mode = 4
[node name="LevelRootContainer" type="Node2D" parent="MainViewportContainer/MainViewport"]
unique_name_in_owner = true
[node name="Player" parent="MainViewportContainer/MainViewport" instance=ExtResource("5_0agpg")]
unique_name_in_owner = true
[node name="OutlineShader" parent="MainViewportContainer/MainViewport" instance=ExtResource("2_ta1pa")]
[node name="TextViewportContainer" type="SubViewportContainer" parent="."]
editor_description = "All nodes in the text_viewport group will be rendered in this viewport instead."
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stretch = true
[node name="TextViewport" type="SubViewport" parent="TextViewportContainer"]
transparent_bg = true
handle_input_locally = false
canvas_item_default_texture_filter = 0
size = Vector2i(800, 450)
render_target_update_mode = 4
script = ExtResource("4_hxymt")
[node name="LevelTextRootContainer" type="Node2D" parent="TextViewportContainer/TextViewport"]
unique_name_in_owner = true
[node name="Camera2D" type="Camera2D" parent="TextViewportContainer/TextViewport"]
editor_description = "Shadows the camera in MainViewportContainer"
anchor_mode = 0
[node name="DistortionShader" parent="." instance=ExtResource("3_emkei")]

36
main/text_viewport.gd Normal file
View file

@ -0,0 +1,36 @@
extends SubViewport
# All nodes from the MainViewport that are in the text_viewport group
# are shadowed in this SubViewport
@onready var camera: Camera2D = $Camera2D
@onready var container: Node2D = %LevelTextRootContainer
# map nodes to its shadowed nodes
var mapping: Dictionary = {}
func update_mapping():
var nodes = get_tree().get_nodes_in_group("text_viewport")
for k in mapping.keys():
if not is_instance_valid(k): # check if node is gone
container.remove_child(mapping[k])
mapping.erase(k)
for n in nodes:
if not n in mapping.keys():
var dup = n.duplicate()
dup.remove_from_group("text_viewport")
mapping[n] = dup
container.add_child(dup)
func _process(_delta: float) -> void:
update_mapping()
# update shadowed nodes
for k in mapping:
var v = mapping[k]
if k is Label and k.text != v.text:
v.text = k.text
if (k is Label or k is Node2D):
mapping[k].global_position = k.global_position
# camera position
var orig_camera: Camera2D = NodeRegistry.player.camera
camera.global_position = -orig_camera.get_viewport_transform().origin