exchanged the raytracing system entirely

now the changer works, might be an inferior raytracer addon tho, will have to test it out more
This commit is contained in:
Balogh Krisztián 2026-08-17 00:13:14 +02:00
parent 18d9a149a3
commit e9ed6cae42
59 changed files with 1003 additions and 120 deletions

View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2025 Tienne_k
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,42 @@
# raytraced-audio
Adds procedural audio effects to Godot like echo, ambient outdoor sounds, and muffle.
Check out [this amazing video](https://youtu.be/u6EuAUjq92k?si=6W-sGozYBQITEgQo) by **Vercidium** for insights on how this works!
No need to create and maintain zones while creating levels, just put the `RaytracedAudioListener` node in your scene and most features will be available for you to use!
Additionally, by using `RaytracedAudioPlayer3D`s instead of regular `AudioPlayer3D`s, sounds will get automatically muffled behind walls.
### Audio buses
Right off the bat, this plugin creates 2 new audio buses for you to use across your project:
a *"Reverb"* bus, and an *"Ambient"* bus.
Note: both buses' names can be changed under `Project Settings > Raytraced Audio`.
The reverb bus controls echo / reverb.
For example, there will be a much bigger reverb in large enclosed rooms compared to small ones, or outside in the open.
The ambient bus controls the strength and pan of sounds coming from outside.
For example, in a room with a single opening leading outisde, sounds in this bus will appear to come from that opening, and will fade based on the player's distance to it.
### Performace
Because the rays need to gather different informations about the environment, the actual number of processed rays can go up to:
`rays_count * (2 + n)` where `n` is the number of enabled `RaytracedAudioPlayer3D`s in the scene.
That is:
`(rays_count: configurable) * (1 ray that bounces around + 1 echo ray + (1 muffle ray per enabled RaytracedAudioPlayer3D))`
Raytraced Audio also adds 2 performance monitors:
- `raytraced_audio/raycast_updates`: How many raycast updates happened in the update tick
- `raytraced_audio/enabled_players_count`: How many `RaytracedAudioPlayer3D`s are currently enabled in the scene
### Installation
#### Manual installation
- Download or clone this repository
- Copy the `addons/raytraced_audio` folder into your project's `addons/` folder
- Enable the plugin in `Project Settings > Plugins > Raytraced Audio`

View file

@ -0,0 +1,138 @@
extends RayCast3D
# dont you worry about this class, habibi
# shhhhhh its okay
# ( - ͜ʖ -)☞(ʘ_ʘ; )
var cast_dist: float = 0.0
var max_bounces: int = 1
var ray_scatter: Callable
var echo_dist: float = 0.0
var echo_count: int = 0
var bounces: int = 0
var has_bounced_this_tick: bool = false
var ray_casts_this_tick: int = 0
var escaped: bool = false
var escape_dir: Vector3 = Vector3.ZERO
var _space_state: PhysicsDirectSpaceState3D
func _init(raycast_dist: float, max_bounce_count: int) -> void:
top_level = true
enabled = false
cast_dist = raycast_dist
max_bounces = max_bounce_count
func _enter_tree() -> void:
owner = get_parent()
assert(owner is RaytracedAudioListener)
func _ready() -> void:
_space_state = get_world_3d().direct_space_state
reset()
# TODO: optimize
func update():
# Reset if needed
if escaped or bounces > max_bounces:
reset()
force_raycast_update()
ray_casts_this_tick += 1
bounces += 1
# Escaped outside
if !is_colliding():
escaped = true
global_position += target_position
# Muffle ray: Check for line of sight with audio players
for player: RaytracedAudioPlayer3D in get_tree().get_nodes_in_group(RaytracedAudioPlayer3D.ENABLED_GROUP_NAME):
var has_line_of_sight: bool = _cast_ray(player.global_position).is_empty()
player._lowpass_rays_count += int(has_line_of_sight)
return
# Bounce
var hit_pos: Vector3 = get_collision_point()
var normal: Vector3 = get_collision_normal()
global_position = hit_pos + normal * 0.1
target_position = target_position.bounce(normal)
has_bounced_this_tick = true
# Muffle ray: Check for line of sight with audio players
for player: RaytracedAudioPlayer3D in get_tree().get_nodes_in_group(RaytracedAudioPlayer3D.ENABLED_GROUP_NAME):
var has_line_of_sight: bool = _cast_ray(player.global_position).is_empty()
player._lowpass_rays_count += int(has_line_of_sight)
# Same as:
# if has_line_of_sight:
# player.lowpass_rays_count += 1
# Echo ray: Check for line of light with listener
# Optimization: no need to raycast for first echo bounce
if bounces == 1:
echo_dist = hit_pos.distance_to(owner.global_position)
echo_count += 1
escape_dir = target_position.normalized()
elif _cast_ray(owner.global_position).is_empty():
# The way is clear -> echo
echo_dist = hit_pos.distance_to(owner.global_position)
echo_count += 1
escape_dir = owner.global_position.direction_to(hit_pos)
# Return to the listener with a random direction
func reset():
var dir: Vector3 = ray_scatter.call()
global_position = owner.global_position
target_position = dir * cast_dist
bounces = 0
escaped = false
escape_dir = dir
reset_tick_stats()
# Called after this ray is done ticking, in RaytracedAudioListener
func reset_tick_stats() -> void:
has_bounced_this_tick = false
ray_casts_this_tick = 0
echo_dist = 0.0
echo_count = 0
func set_scatter_model(model: RaytracedAudioListener.RayScatterModel) -> void:
match model:
RaytracedAudioListener.RayScatterModel.RANDOM:
ray_scatter = _random_dir
RaytracedAudioListener.RayScatterModel.XZ:
ray_scatter = _random_dir_xz_plane
_:
push_error("Unknown ray scatter model: '", model, "'")
ray_scatter = _random_dir
func _cast_ray(to: Vector3) -> Dictionary:
var params: PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.create(
global_position,
to,
0b01
)
ray_casts_this_tick += 1
return _space_state.intersect_ray(params)
func _random_dir_xz_plane() -> Vector3:
var yaw = randf_range(0.0, TAU)
return Vector3(-sin(yaw), 0.0, -cos(yaw))
func _random_dir() -> Vector3:
var theta: float = randf_range(0.0, TAU)
var y: float = randf_range(-1.0, 1.0)
var k: float = sqrt(1.0 - y*y)
return Vector3(k * cos(theta), k * sin(theta), y)

View file

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

View file

@ -0,0 +1,7 @@
[plugin]
name="Raytraced Audio"
description="Adds procedural audio effects to Godot like echo, ambient outdoor sounds, and muffle"
author="Tienne_k"
version="1.0"
script="plugin.gd"

View file

@ -0,0 +1,83 @@
@tool
extends EditorPlugin
func _enter_tree() -> void:
_setup_settings()
# For some reason, adding custom types like this fails to generate documentation sometimes??
# add_custom_type(
# "RaytracedAudioListener",
# "AudioListener3D",
# load("res://addons/raytraced_audio/raytraced_audio_listener.gd"),
# null
# )
# add_custom_type(
# "RaytracedAudioPlayer3D",
# "AudioStreamPlayer3D",
# load("res://addons/raytraced_audio/raytraced_audio_player_3d.gd"),
# null
# )
_setup_audio_buses()
func _exit_tree() -> void:
# remove_custom_type("RaytracedAudioListener")
# remove_custom_type("RaytracedAudioPlayer3D")
_clean_up_settings()
_clean_up_audio_buses()
func _setup_settings() -> void:
ProjectSettings.set_setting("raytraced_audio/reverb_bus", &"RaytracedReverb")
ProjectSettings.set_setting("raytraced_audio/ambient_bus", &"RaytracedAmbient")
if ProjectSettings.get_setting("audio/general/3d_panning_strength") < 1.0:
print("[INFO] RaytracedAudio: I recommend setting Audio/General/3d_panning_strength in Project Settings to 1.0 or above")
func _clean_up_settings() -> void:
ProjectSettings.set_setting("raytraced_audio/reverb_bus", null)
ProjectSettings.set_setting("raytraced_audio/ambient_bus", null)
func _setup_audio_buses() -> void:
print("[INFO] Raytraced Audio: setting up audio buses")
_clean_up_audio_buses()
# Reverb
var i: int = AudioServer.bus_count
AudioServer.add_bus()
AudioServer.set_bus_name(i, ProjectSettings.get_setting("raytraced_audio/reverb_bus", &"RaytracedReverb"))
AudioServer.set_bus_send(i, &"Master")
var reverb: AudioEffectReverb = AudioEffectReverb.new()
reverb.hipass = 1.0
reverb.resource_name = "reverb"
AudioServer.add_bus_effect(i, reverb)
# Ambient
i = AudioServer.bus_count
AudioServer.add_bus()
AudioServer.set_bus_name(i, ProjectSettings.get_setting("raytraced_audio/ambient_bus", &"RaytracedAmbient"))
AudioServer.set_bus_send(i, &"Master")
var panner: AudioEffectPanner = AudioEffectPanner.new()
panner.resource_name = "pan"
AudioServer.add_bus_effect(i, panner)
# There's a bug in Godot that makes it so the ambient bus doesnt show properly in the editor
# This is "fixable" by adding a temporary bus afterwards and deleting it immediately because ofc.
# fuck you (respectfully)
i = AudioServer.bus_count
AudioServer.add_bus()
AudioServer.remove_bus(i)
func _clean_up_audio_buses() -> void:
var i: int = AudioServer.get_bus_index(ProjectSettings.get_setting("raytraced_audio/reverb_bus", &"RaytracedReverb"))
if i != -1:
AudioServer.remove_bus(i)
i = AudioServer.get_bus_index(ProjectSettings.get_setting("raytraced_audio/ambient_bus", &"RaytracedAmbient"))
if i != -1:
AudioServer.remove_bus(i)

View file

@ -0,0 +1 @@
uid://8y7slc7nck0o

View file

@ -0,0 +1,342 @@
class_name RaytracedAudioListener extends AudioListener3D
## 3D audio listener for raytraced audio
##
## [b]Audio buses[/b]
## [br]This plugin creates 2 new audio buses for you to use across your project:
## a [i]"Reverb"[/i] bus, and an [i]"Ambient"[/i] bus.
## [br]Note: both buses' names can be changed under [code]Project Settings > Raytraced Audio[/code].
## [br]
## [br]The reverb bus controls echo / reverb.
## [br]For example, there will be a much bigger reverb in large enclosed rooms compared to small ones, or outside in the open
## [br]
## [br]The ambient bus controls the strength and pan of sounds coming from outside.
## [br]For example, in a room with a single opening leading outisde, sounds in this bus will appear to come from that opening, and will fade based on the player's distance to it
## [br]
## [br][b]Performace[/b]
## [br]Raytraced Audio adds 2 performance monitors:
## [br] - [code]raytraced_audio/raycast_updates[/code]: How many raycast updates happened in one update tick
## [br] - [code]raytraced_audio/enabled_players_count[/code]: How many [RaytracedAudioPlayer3D]s are enabled in the scene
## [br]
## [br]Note: There should be only one [RaytracedAudioListener] in a given scene, just like how there should be only one AudioListener3D in a scene.
## [br]See also [RaytracedAudioPlayer3D]
## Speed of sound in m/s
const SPEED_OF_SOUND: float = 343.0
## All [RaytracedAudioListener]s will be in this group
const GROUP_NAME: StringName = &"raytraced_audio_listener"
const AudioRay: Script = preload("res://addons/raytraced_audio/audio_ray.gd")
enum RayScatterModel {
## Rays will be shot out in a random 3d direction
RANDOM,
## Rays will be shot out on the listener's XZ plane (i.e. [code]Vector3(random, 0, random)[/code])
XZ,
}
## Emitted when this node is enabled
signal enabled
## Emitted when this node is disabled
signal disabled
## Emitted when any configuration for the rays are changed
## [br]This includes: [member rays_count], [member max_raycast_dist], [member max_bounces], and [member ray_scatter_model]
signal ray_configuration_changed
## List of rays instanced by this node
var rays: Array[AudioRay] = []
## Enable or disable raycasting
## [br]Disabled nodes can't be updated (see [method update]) even if [member auto_update] is set to [code]true[/code]
@export var is_enabled: bool = true:
set(v):
if is_enabled == v:
return
is_enabled = v
if is_enabled:
if is_node_ready():
setup()
enabled.emit()
else:
disabled.emit()
if is_node_ready():
clear()
## Whether to update automatically
## [br]If set to [code]true[/code], this [RaytracedAudioListener] will update every [i]process[/i] frame
@export var auto_update: bool = true:
set(v):
auto_update = v
set_process(auto_update)
## Number of rays to use
## [br]More rays and more bounces mean a more accurate model of the environment can be made
## [br] See also [member max_bounces]
## [br]
## [br][i]Technical note[/i]:
## [br] Because the rays need to gather different informations about the environment,
## the actual number of processed rays can go up to:
## [br] [code]rays_count * (2 + n)[/code] where [code]n[/code] is the number of enabled [RaytracedAudioPlayer3D]s in the scene
## [br] ([code]rays_count * (1 ray that bounces around + 1 echo ray + 1 muffle ray per enabled RaytracedAudioPlayer3D[/code])
@export var rays_count: int = 4:
set(v):
if v == rays_count:
return
rays_count = maxi(v, 1)
clear()
setup()
ray_configuration_changed.emit()
## The maximum distance which any given ray instanced by this node will cast
@export var max_raycast_dist: float = SPEED_OF_SOUND:
set(v):
max_raycast_dist = v
_update_ray_configuration()
ray_configuration_changed.emit()
## [br]More rays and more bounces mean a more accurate model of the environment can be made
## [br] See also [member rays_count]
@export var max_bounces: int = 3:
set(v):
max_bounces = v
_update_ray_configuration()
ray_configuration_changed.emit()
## Controls how rays will be instanced
@export var ray_scatter_model: RayScatterModel = RayScatterModel.RANDOM:
set(v):
ray_scatter_model = v
_update_ray_configuration()
ray_configuration_changed.emit()
@export_category("Muffle")
## Enables [RaytracedAudioPlayer3D]s muffling behind walls
@export var muffle_enabled: bool = true
## The interpolation strength of the muffle
## [br]See [member muffle_enabled]
@export_range(0.0, 1.0, 0.01) var muffle_interpolation: float = 0.01
@export_category("Echo")
## Enables updates to the reverb audio bus
## [br]See [code]Project Settings > Raytraced Audio > Reverb Bus[/code]
@export var echo_enabled: bool = true
## The "intensity" of the reverb
## [br]More specifically, multiplies the reverb's room size by this amount
## [br]The default is [code]2.0[/code] to account for sound waves coming back to the listener after hitting a wall
@export var echo_room_size_multiplier: float = 2.0
## The interpolation strength of the echo
## [br]See [member echo_enabled]
@export_range(0.0, 1.0, 0.01) var echo_interpolation: float = 0.01
@export_category("Ambient")
## Enables updates to the ambient audio bus
## [br]See [code]Project Settings > Raytraced Audio > Ambient Bus[/code]
@export var ambient_enabled: bool = true
## The interpolation strength of ambient sounds' direction (pan)
## [br]See [member ambient_enabled], [member ambient_pan_strength]
@export_range(0.0, 1.0, 0.01) var ambient_pan_interpolation: float = 0.02
## How strong the pan between right and left ear will be
## Setting this to 0 disables panning completely
## [br]See [member ambient_enabled], [member ambient_pan_interpolation]
@export_range(0.0, 1.0, 0.01) var ambient_pan_strength: float = 1.0
## The interpolation strength of ambient sounds' volume
## [br]See [member ambient_enabled]
@export var ambient_volume_interpolation: float = 0.01
## How smoothly the ambient sounds will fade away when the [AudioListener3D] is no longer "outside"
## Values close to 1 will make sounds linger for longer, while values close to 0 will make them drop suddenly
## [br]See [member ambient_enabled]
@export_range(0.0, 1.0, 0.001) var ambient_volume_attenuation: float = 0.998
## The size of the room based on data gathered from rays, in world units
## [br]Used in reverb calculation
var room_size: float = 0.0
## How "outside" this [RaytracedAudioListener] is based on data gathered from rays, between 0 and 1
var ambience: float = 0.0
## The direction to "outside" based on data gathered from rays
## [br]Should average out to 0 when this [RaytracedAudioListener] is completely outside
var ambient_dir: Vector3 = Vector3.ZERO
## For debugging purposes
## [br]See the [code]raytraced_audio/raycast_updates[/code] performance monitor
var ray_casts_this_tick: int = 0
var _reverb_effect: AudioEffectReverb
var _pan_effect: AudioEffectPanner
# Keep track of whether we've set up debug monitors
var _debug_monitors_setup: bool = false
func _enter_tree() -> void:
add_to_group(GROUP_NAME)
func _ready() -> void:
# Reverb effect
var i: int = AudioServer.get_bus_index(ProjectSettings.get_setting("raytraced_audio/reverb_bus"))
if i == -1:
push_error("Failed to get reverb bus for raytraced audio. Disabling echo...")
echo_enabled = false
else:
_reverb_effect = AudioServer.get_bus_effect(i, 0)
# Pan effect
i = AudioServer.get_bus_index(ProjectSettings.get_setting("raytraced_audio/ambient_bus"))
if i == -1:
push_error("Failed to get ambient bus for raytraced audio. Disabling ambience...")
ambient_enabled = false
else:
_pan_effect = AudioServer.get_bus_effect(i, 0)
if is_enabled:
setup()
set_process(auto_update)
if is_enabled:
make_current()
_setup_debug()
func _exit_tree() -> void:
_cleanup_debug()
func _setup_debug() -> void:
if _debug_monitors_setup:
return
_debug_monitors_setup = true
Performance.add_custom_monitor(&"raytraced_audio/raycast_updates", func():
# Check if this instance is still valid
if not is_instance_valid(self):
return 0
return ray_casts_this_tick
)
Performance.add_custom_monitor(&"raytraced_audio/enabled_players_count", func():
# Check if this instance is still valid and if we're in a scene tree
if not is_instance_valid(self) or not is_inside_tree():
return 0
return get_tree().get_node_count_in_group(RaytracedAudioPlayer3D.ENABLED_GROUP_NAME)
)
func _cleanup_debug() -> void:
if not _debug_monitors_setup:
return
_debug_monitors_setup = false
# Remove the custom monitors
Performance.remove_custom_monitor(&"raytraced_audio/raycast_updates")
Performance.remove_custom_monitor(&"raytraced_audio/enabled_players_count")
## Initiates this [RaytracedAudioListener]'s rays
func setup() -> void:
for __ in rays_count:
var rc: AudioRay = AudioRay.new(max_raycast_dist, max_bounces)
rc.set_scatter_model(ray_scatter_model)
add_child(rc, INTERNAL_MODE_BACK)
rays.push_back(rc)
## Clears all created rays
func clear():
for ray: AudioRay in rays:
remove_child(ray)
ray.queue_free()
rays.clear()
func _process(delta: float) -> void:
if !auto_update:
set_process(false)
return
update()
## Updates this [RaytracedAudioListener]
## [br]If you are updating this node manually (i.e. [member auto_update] is [code]false[/code]), this is the method to call
func update():
ray_casts_this_tick = 0
if !is_enabled:
return
var echo: float = 0.0 # Avg echo from all rays
var echo_count: int = 0 # Number of echo rays that came back
var bounces_this_tick: int = 0
var escaped_count: int = 0
var escaped_dir: Vector3 = Vector3.ZERO # Avg escape direction
var escaped_strength: float = 0.0
# Gather data
for ray: AudioRay in rays:
ray.update()
ray_casts_this_tick += ray.ray_casts_this_tick
echo += ray.echo_dist
echo_count += ray.echo_count
bounces_this_tick += int(ray.has_bounced_this_tick)
if ray.escaped:
escaped_count += 1
escaped_strength += 1.0 / ray.bounces
escaped_dir += ray.escape_dir
ray.reset_tick_stats()
echo = 0.0 if echo_count == 0 else (echo / float(echo_count))
escaped_dir = Vector3.ZERO if escaped_count == 0 else (escaped_dir / float(escaped_count))
if muffle_enabled:
_update_muffle()
if echo_enabled:
_update_echo(echo, echo_count, bounces_this_tick)
if ambient_enabled:
_update_ambient(escaped_strength, escaped_dir)
func _update_muffle() -> void:
for player: RaytracedAudioPlayer3D in get_tree().get_nodes_in_group(RaytracedAudioPlayer3D.GROUP_NAME):
player.update(self)
func _update_echo(echo: float, echo_count: int, bounces: int) -> void:
# Length -> echo delay
room_size = lerpf(room_size, echo, echo_interpolation)
var e: float = (room_size * echo_room_size_multiplier) / SPEED_OF_SOUND
# print("e = ", e)
_reverb_effect.room_size = lerpf(_reverb_effect.room_size, clampf(e, 0.0, 1.0), echo_interpolation)
_reverb_effect.predelay_msec = lerpf(_reverb_effect.predelay_msec, e * 1000, echo_interpolation)
_reverb_effect.predelay_feedback = lerpf(_reverb_effect.predelay_feedback, clampf(e, 0.0, 0.98), echo_interpolation)
# More rays % -> echo strength
var return_ratio: float = 0.0 if bounces == 0 else float(echo_count) / float(bounces)
_reverb_effect.hipass = lerpf(_reverb_effect.hipass, 1.0 - return_ratio, echo_interpolation)
func _update_ambient(escaped_strength: float, escaped_dir: Vector3) -> void:
var ambience_ratio: float = float(escaped_strength) / float(rays_count)
# More rays % -> louder
if escaped_strength > 0:
ambience = lerpf(ambience, 1.0, ambience_ratio)
else:
ambience *= ambient_volume_attenuation
var ambient_bus_idx: int = AudioServer.get_bus_index(ProjectSettings.get_setting("raytraced_audio/ambient_bus"))
var volume: float = AudioServer.get_bus_volume_linear(ambient_bus_idx)
AudioServer.set_bus_volume_linear(ambient_bus_idx, lerpf(volume, ambience, ambient_volume_interpolation))
# Avg escape direction -> pan
ambient_dir = ambient_dir.lerp(escaped_dir, ambient_pan_interpolation)
var target_pan: float = 0.0 if ambient_dir.is_zero_approx() else owner.transform.basis.x.dot(ambient_dir.normalized())
_pan_effect.pan = target_pan * ambient_pan_strength
# ✨ the name says it all ✨
func _update_ray_configuration() -> void:
for ray: AudioRay in rays:
ray.cast_dist = max_raycast_dist
ray.max_bounces = max_bounces
ray.set_scatter_model(ray_scatter_model)

View file

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

View file

@ -0,0 +1,223 @@
class_name RaytracedAudioPlayer3D extends AudioStreamPlayer3D
## Audio stream player that allows for audio muffling
##
## You can already use the reverb and ambient audio buses (see the documentation for [RaytracedAudioListener] for more details)
## to make use of raytraced audio effects, but using [RaytracedAudioPlayer3D]s allows you to use more capabilities.
## Namely, muffling sounds behind walls.
## [br]
## [br][b][color=yellow]Warning[/color][/b]: [RaytracedAudioPlayer3D]s will default to using the reverb audio bus
## [br]If you wish to use another bus instead, please set it after this node has been added to the scene tree (i.e. after [code]_enter_tree()[/code])
## [br]
## [br][i]Technical note[/i]:
## [br]Currently, there is no way to muffle only one audio player (or apply any effect for that matter).
## [br]So we create a new bus for every audio player that is audible from the [RaytracedAudioListener]
## [br]Godot doesn't provide methods to calculate the volume of an audio at certain distances, so we calculate
## that ourselves (see [method calculate_audible_distance_threshold()])
## All [RaytracedAudioPlayer3D]s (regardless of state) will be in this group
const GROUP_NAME: StringName = &"raytraced_audio_player_3d"
## All [b]enabled[/b] [RaytracedAudioPlayer3D]s will be in this group
const ENABLED_GROUP_NAME: StringName = &"enabled_raytraced_audio_player_3d"
## The lowpass frequency when completely muffled
const LOWPASS_MIN_HZ: float = 250.0
## The lowpass frequency when completely not-muffled (?)
const LOWPASS_MAX_HZ: float = 20000.0
## Used in internal calculations
const LOG2: float = log(2.0)
## Used in internal calculations
const LOG_MIN_HZ: float = log(LOWPASS_MIN_HZ) / LOG2
## Used in internal calculations
const LOG_MAX_HZ: float = log(LOWPASS_MAX_HZ) / LOG2
## Emitted when this node is enabled
## [br]See also [constant ENABLED_GROUP_NAME]
signal enabled
## Emitted when this node is disabled
signal disabled
## Emitted when the maximum audible distance for this node is changed
## [br]See also [member AudioStreamPlayer3D.max_distance] and [member audibility_threshold_db]
signal audible_distance_updated(distance: float)
## The threshold (in decibels) at which sounds will be considered inaudible
## [br]This is used to enable / disable this node when it's not audible to save resources
## [br]The distance at which this node is no longer considered audible is automatically stored inside [member AudioStreamPlayer3D.max_distance]
## (if not already set), also to save resources
## [br]Though, setting [member AudioStreamPlayer3D.max_distance] doesn't update this field automatically
## [br]See also [method get_volume_db_from_pos] and [method calculate_audible_distance_threshold]
@export var audibility_threshold_db: float = -30.0:
set(v):
audibility_threshold_db = v
# Max distance not configured
if is_node_ready() and max_distance == 0.0:
max_distance = calculate_audible_distance_threshold()
audible_distance_updated.emit(max_distance)
var _lowpass_rays_count: int = 0
var _is_enabled: bool = false
func _enter_tree() -> void:
add_to_group(GROUP_NAME)
bus = ProjectSettings.get_setting("raytraced_audio/reverb_bus") # Fallback
func _ready() -> void:
# Max distance not configured
if max_distance == 0.0:
max_distance = calculate_audible_distance_threshold()
audible_distance_updated.emit(max_distance)
## Enables this node
## [br]Note: you should almost never have to worry about enabling / disabling [RaytracedAudioPlayer3D]s manually
## [br]See [method update]
func enable():
if _is_enabled:
return
_is_enabled = true
var i: int = _create_bus()
bus = AudioServer.get_bus_name(i)
add_to_group(ENABLED_GROUP_NAME)
enabled.emit()
## Enables this node
## [br]Note: you should almost never have to worry about enabling / disabling [RaytracedAudioPlayer3D]s manually
## [br]See [method update]
func disable():
if !_is_enabled:
return
# Don't remove the fallback bus lol
if bus == ProjectSettings.get_setting("raytraced_audio/reverb_bus"):
_disable()
return
# Remove this node's specific bus
var idx: int = AudioServer.get_bus_index(bus)
if idx == -1:
push_warning("audio bus ", bus, " not found")
_disable()
return
_disable()
AudioServer.remove_bus(idx)
func _disable():
_is_enabled = false
bus = ProjectSettings.get_setting("raytraced_audio/reverb_bus") # Fallback
remove_from_group(ENABLED_GROUP_NAME)
_lowpass_rays_count = 0
disabled.emit()
# Returns the index of the created bus
func _create_bus() -> int:
var i: int = AudioServer.bus_count
AudioServer.add_bus()
AudioServer.set_bus_name(i, generate_bus_name())
AudioServer.set_bus_send(i, ProjectSettings.get_setting("raytraced_audio/reverb_bus"))
AudioServer.add_bus_effect(i, AudioEffectLowPassFilter.new())
return i
## Returns a name for the audio bus created for this node
func generate_bus_name() -> String:
return str("RTAudioPlayer3D_", name, randi())
## ✨ the name says it all ✨
func is_enabled() -> bool:
return _is_enabled
## Updates this [RaytracedAudioPlayer3D]
## [br]This method will adjust the muffle of the played stream, as well as enable or disable it
## based on whether it's audible from the given [RaytracedAudioListener]
## [br]If you are updating this node manually, this is the method to call
func update(listener: RaytracedAudioListener) -> void:
if _is_enabled:
_update(listener.rays_count, listener.muffle_interpolation)
_lowpass_rays_count = 0
# Enable based on position
var dist_sq: float = global_position.distance_squared_to(listener.global_position)
if dist_sq > max_distance*max_distance or !playing:
disable()
else:
enable()
func _update(rays_count: int, interpolation: float):
if bus == ProjectSettings.get_setting("raytraced_audio/reverb_bus"):
_disable()
return
var idx: int = AudioServer.get_bus_index(bus)
if idx == -1:
push_error("audio bus ", bus, " not found")
_disable()
else:
var ratio: float = float(_lowpass_rays_count) / float(rays_count)
var lowpass: AudioEffectLowPassFilter = AudioServer.get_bus_effect(idx, 0)
# Frequencies aren't linear, they scale logarithmically (log2 space) +1 octave = 2x the frequency
# So we scale frequencies down before lerping, then scale them back up
var log_t: float = lerpf(LOG_MIN_HZ, LOG_MAX_HZ, ratio)
var log_hz: float = log(lowpass.cutoff_hz) / LOG2 # Scale current frequency down: log2(x) = ln(x) / ln(2)
log_hz = lerpf(log_hz, log_t, interpolation) # Lerp in scaled down space
lowpass.cutoff_hz = pow(2, log_hz) # Scale back up
# Translated from the godot repo
## Calculates the volume (in decibels) of the audio stream from the given position
## [br]Please note that the final volume will vary depending on the stream that is being played
func get_volume_db_from_pos(from_pos: Vector3) -> float:
const CMP_EPSILON: float = 0.0001
var dist: float = from_pos.distance_to(global_position)
var vol: float = 0.0
match attenuation_model:
ATTENUATION_INVERSE_DISTANCE:
vol = linear_to_db(1.0 / ((dist / unit_size) + CMP_EPSILON))
ATTENUATION_INVERSE_SQUARE_DISTANCE:
var d: float = (dist / unit_size)
vol = linear_to_db(1.0 / (d*d + CMP_EPSILON))
ATTENUATION_LOGARITHMIC:
vol = -20.0 * log(dist / unit_size + CMP_EPSILON)
ATTENUATION_DISABLED:
pass
_:
push_error("Unknown attenuation type: '", attenuation_model, "'")
vol = minf(vol + volume_db, max_db)
return vol
## Calculates the distance at which this [RaytracedAudioPlayer3D] is no longer considered audible
## [br]See also [member audibility_threshold_db]
func calculate_audible_distance_threshold() -> float:
if max_distance > 0.0:
return max_distance
match attenuation_model:
ATTENUATION_INVERSE_DISTANCE:
var t_lin: float = db_to_linear(audibility_threshold_db - volume_db)
# Unit_size / dist < T_lin
return unit_size / t_lin
ATTENUATION_INVERSE_SQUARE_DISTANCE:
var t_lin: float = db_to_linear(audibility_threshold_db - volume_db)
# (Unit_size / dist)^2 < T_lin
return sqrt(unit_size*unit_size / t_lin)
ATTENUATION_LOGARITHMIC:
var t_db: float = audibility_threshold_db - volume_db
# -20 * log(dist / Unit_size) > T_db
return exp(t_db / -20.0) * unit_size
ATTENUATION_DISABLED:
return 0.0
_:
push_error("Unknown attenuation model: '", attenuation_model, "'")
return 0.0
## Checks wheter this [RaytracedAudioPlayer3D] is considered audible from the given position
## [br]See also [member audibility_threshold_db]
func is_audible(from_pos: Vector3) -> bool:
return get_volume_db_from_pos(from_pos) >= audibility_threshold_db

View file

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

View file

@ -25,6 +25,13 @@ predelay_feedback = 0.0
hipass = 0.42
wet = 0.24
[sub_resource type="AudioEffectReverb" id="AudioEffectReverb_g28q7"]
resource_name = "reverb"
hipass = 1.0
[sub_resource type="AudioEffectPanner" id="AudioEffectPanner_n8wo2"]
resource_name = "pan"
[resource]
bus/1/name = &"wind"
bus/1/solo = false
@ -50,3 +57,19 @@ bus/2/effect/0/effect = SubResource("AudioEffectDelay_j3pel")
bus/2/effect/0/enabled = false
bus/2/effect/1/effect = SubResource("AudioEffectReverb_j3pel")
bus/2/effect/1/enabled = false
bus/3/name = &"RaytracedReverb"
bus/3/solo = false
bus/3/mute = false
bus/3/bypass_fx = false
bus/3/volume_db = 0.0
bus/3/send = &"Master"
bus/3/effect/0/effect = SubResource("AudioEffectReverb_g28q7")
bus/3/effect/0/enabled = true
bus/4/name = &"RaytracedAmbient"
bus/4/solo = false
bus/4/mute = false
bus/4/bypass_fx = false
bus/4/volume_db = 0.0
bus/4/send = &"Master"
bus/4/effect/0/effect = SubResource("AudioEffectPanner_n8wo2")
bus/4/effect/0/enabled = true

View file

@ -12,6 +12,7 @@
[ext_resource type="Script" uid="uid://v7j6ovrub5cp" path="res://scenes/changable_sound_emitter.gd" id="13_we0b7"]
[ext_resource type="PackedScene" uid="uid://blh2biuk44qqj" path="res://entities/player/cursor.tscn" id="14_fcs02"]
[ext_resource type="AudioStream" uid="uid://0q6nhlhgnxu2" path="res://assets/sounds/whitenoise.mp3" id="14_ugbui"]
[ext_resource type="Script" uid="uid://bjpmu5sklv5h8" path="res://addons/raytraced_audio/raytraced_audio_listener.gd" id="14_we0b7"]
[ext_resource type="Script" uid="uid://dr2lwciaohf6f" path="res://entities/player/movement_component.gd" id="60_s3g0c"]
[ext_resource type="Script" uid="uid://cjk6a0da11ge6" path="res://entities/player/procedural_animator.gd" id="61_hggc2"]
[ext_resource type="Script" uid="uid://v8er7yn0hdh8" path="res://entities/player/sound_controller_component.gd" id="62_b2j0d"]
@ -127,14 +128,17 @@ unique_name_in_owner = true
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6971706, -0.42015946)
panning_strength = 0.0
area_mask = 1
script = ExtResource("13_we0b7")
easy_audio = false
metadata/_custom_type_script = "uid://v7j6ovrub5cp"
[node name="HeadTexture" type="AudioStreamPlayer3D" parent="CameraPivot/Head" unique_id=2073564595]
unique_name_in_owner = true
panning_strength = 0.0
area_mask = 1
script = ExtResource("13_we0b7")
reverb_enabled = false
easy_audio = false
metadata/_custom_type_script = "uid://v7j6ovrub5cp"
[node name="PlayerCamera" type="Camera3D" parent="CameraPivot" unique_id=303347613]
@ -177,7 +181,16 @@ omni_attenuation = 0.5
[node name="PlayerListener" type="AudioListener3D" parent="CameraPivot" unique_id=1468948553]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.7621309, 0)
doppler_tracking = 2
[node name="RaytracedAudioListener" type="AudioListener3D" parent="CameraPivot/PlayerListener" unique_id=154629324]
doppler_tracking = 2
current = true
script = ExtResource("14_we0b7")
ray_scatter_model = 1
muffle_interpolation = 0.02
echo_room_size_multiplier = 5.0
echo_interpolation = 0.0
metadata/_custom_type_script = "uid://bjpmu5sklv5h8"
[node name="MeshInstance3D" type="MeshInstance3D" parent="CameraPivot" unique_id=539906244]
mesh = SubResource("CapsuleMesh_b5l5s")
@ -238,24 +251,32 @@ one_shot = true
[node name="LeftFoot" type="AudioStreamPlayer3D" parent="SoundEmitters" unique_id=166056711]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.43042383, -0.90646136, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.8749303, 0.24958718, 0)
area_mask = 1
script = ExtResource("13_we0b7")
easy_audio = false
metadata/_custom_type_script = "uid://v7j6ovrub5cp"
[node name="LeftFootTexture" type="AudioStreamPlayer3D" parent="SoundEmitters/LeftFoot" unique_id=412267863]
unique_name_in_owner = true
area_mask = 1
script = ExtResource("13_we0b7")
easy_audio = false
metadata/_custom_type_script = "uid://v7j6ovrub5cp"
[node name="RightFoot" type="AudioStreamPlayer3D" parent="SoundEmitters" unique_id=1825432395]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.3428033, -0.8860581, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.7457278, 0.24676013, 0)
area_mask = 1
script = ExtResource("13_we0b7")
easy_audio = false
metadata/_custom_type_script = "uid://v7j6ovrub5cp"
[node name="RightFootTexture" type="AudioStreamPlayer3D" parent="SoundEmitters/RightFoot" unique_id=332096966]
unique_name_in_owner = true
area_mask = 1
script = ExtResource("13_we0b7")
easy_audio = false
metadata/_custom_type_script = "uid://v7j6ovrub5cp"
[node name="Wind" type="AudioStreamPlayer3D" parent="SoundEmitters" unique_id=1950929206]

View file

@ -68,7 +68,7 @@ var cur_priorities: Dictionary = {
#"head_texture": 0
#}
var get_player_str = func (player:SpatialAudio3D):
var get_player_str = func (player:ChangableAudioStreamPlayer3D):
match player:
left_foot: return "left_foot"
right_foot: return "right_foot"
@ -92,8 +92,8 @@ func _ready() -> void:
var sound_players:Array[ChangableAudioStreamPlayer3D] = [left_foot, left_foot_texture, right_foot, right_foot_texture, head, head_texture]
for i in sound_players:
i.debug = debug
i.reverb_enabled = reverb
#i.debug = debug
#i.reverb_enabled = reverb
cur_priorities.get_or_add(i, -1)
get_tree().create_timer(1).timeout.connect(init_wind)
@ -117,7 +117,7 @@ var is_right_leg := func () -> ChangableAudioStreamPlayer3D:
##only use for sparse effects
func create_spatial_audio_sphere(pos:Vector3, audio:AudioStream, pitch:float = 1.0):
var spatial_audio = SpatialAudio3D.new()
var spatial_audio = ChangableAudioStreamPlayer3D.new()
spatial_audio.collision_mask = 1
spatial_audio.stream = audio

View file

@ -4,7 +4,6 @@
[ext_resource type="PackedScene" uid="uid://cbpl3s326ok8d" path="res://entities/usable/button/button.tscn" id="1_t1vpp"]
[ext_resource type="Script" uid="uid://v7j6ovrub5cp" path="res://scenes/changable_sound_emitter.gd" id="3_johh1"]
[ext_resource type="AudioStream" uid="uid://b14wn4nntykxv" path="res://assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3" id="3_rf3au"]
[ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="5_pd776"]
[sub_resource type="CylinderMesh" id="CylinderMesh_b5l5s"]
top_radius = 0.025390625
@ -37,14 +36,8 @@ mesh = SubResource("TubeTrailMesh_b5l5s")
[node name="ChangableAudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="." unique_id=2198078 groups=["sound_player"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.9425293, 0.23302945)
stream = ExtResource("3_rf3au")
attenuation_model = 3
unit_size = 32.04
script = ExtResource("3_johh1")
easy_audio = false
metadata/_custom_type_script = "uid://v7j6ovrub5cp"
[node name="SpatialAudio3D" type="AudioStreamPlayer3D" parent="." unique_id=384959870]
unique_name_in_owner = true
stream = ExtResource("3_rf3au")
script = ExtResource("5_pd776")
collision_mask = 17
debug = true
metadata/_custom_type_script = "uid://y8x4svl5kej2"

View file

@ -51,6 +51,10 @@ window/max_fps=60
version_control/plugin_name="GitPlugin"
version_control/autoload_on_startup=true
[editor_plugins]
enabled=PackedStringArray("res://addons/raytraced_audio/plugin.cfg")
[file_customization]
folder_colors={
@ -58,9 +62,9 @@ folder_colors={
"res://assets/": "red",
"res://classes/": "pink",
"res://concept/": "purple",
"res://maps/": "orange",
"res://resources/shaders/": "pink",
"res://scenes/": "blue",
"res://scenes/maps/": "orange",
"res://scripts/": "gray"
}
@ -303,6 +307,11 @@ common/physics_jitter_fix=0.8
3d/physics_engine="Jolt Physics"
common/physics_interpolation=true
[raytraced_audio]
reverb_bus=&"RaytracedReverb"
ambient_bus=&"RaytracedAmbient"
[rendering]
rendering_device/driver.windows="d3d12"

View file

@ -9,49 +9,40 @@ class_name ChangableAudioStreamPlayer3D extends AudioStreamPlayer3D
else:
set_to_raytraced_audio()
@export_group("SpatialAudio3D properties")
@export_subgroup("Sound Properties")
@export var reverb_enabled: bool = true ## Enable reverb-effects with all its computations.[br][br]Disable if you just need it for occlusion detection, for example fading ambient rain when entering a house.
@export_range(-81, +80, 3.0, "suffix:dB") var reverb_volume_db: float = -6 ## Maximum volume of the reverbs.
@export_range(-1, 5, 0.05, "or_greater", "suffix:s") var reverb_fadeintime: float = 2.0 ## Fade-in time when a reverb is added at a wall.[br][br]The default of 2s is a good value where changes in environment merge well into the overall sound mix.[br]If you have small areas with little changes of distances, set this value to low (0.2s) so that repositioned reverbs don't get stuck for too long in a position. In a large area, when the raycast suddenly hits a close wall, the sudden appearing reverb can sound unnatural.[br][br]Set to -1 for dynamic fade time (based on wetness).
@export_range(-1, 8, 0.05, "or_greater", "suffix:s") var reverb_fadeouttime: float = 2.0 ## Fade-out time when a reverb is removed.[br][br]The default of 2s is a good value where changes in environment merge well into the overall sound mix.[br]If you have small areas with little changes of distances, set this value to low (0.2s) so that repositioned reverbs don't get stuck for too long in a position.[br][br]Set to -1 for dynamic fade time (based on wetness).
@export_range(1, 20_000, 0.1, "suffix:Hz") var occlusion_lp_cutoff: int = 600 ## Frequency when soundsource is occluded behind walls.
@export_range(0, 5, 0.05, "or_greater", "suffix:s") var occlusion_fadetime: float = 0.5 ## Fadetime when occlusion changes.
@export_range(0, 100, 0.1, "or_greater", "suffix:m") var bass_proximity: int = 50 ## The closer you are to a wall, the more bass you will hear.[br][br]The effect starts at this value (distance to the wall).[br][br]0 to disable.
@export_subgroup("Physics")
@export_range(1, 100, 1, "or_greater", "suffix:m") var max_raycast_distance: int = 100 ## Maximum distance for the reverb raycasts.
@export_flags_3d_physics var collision_mask: int = 1 ## Mask for the raycast where to add reverb.
@export var roomsize_multiplicator: float = 6.0 ## How much hall to add compared to room size.[br]Sometimes you have a small room but you need a long reverb.
@export_range(1, 340, 1, "or_greater", "suffix:m/s") var speed_of_sound: int = 340 ## How fast sound travels through the air.
@export var prox_reduction: float = 24.0 ## How much proximity reduces the reverb
@export_range(4,32,1) var reverb_raycast_count: int = 4 ##how many reverb raycasts to shoot out horizontally
@export_subgroup("System")
@export_range(1, 60, 0.1, "or_greater", "suffix:per second") var audiophysics_ticks: int = 10 ## The number of audio physics calculations per second.[br]Tied to _physics_process().[br][br]Use 30-60 for fast moving sounds like a motorcycle passing by.[br][br]Default: 10.
@export var loop: bool = false ## Loop audio indefinitely.
@export var shut_up: bool = false ## Mute output.
@export var debug: bool = false ## Visualize raycasts, measurement rays and reverb-audioplayers.
#@export_group("SpatialAudio3D properties")
#@export_subgroup("Sound Properties")
#@export var reverb_enabled: bool = true ## Enable reverb-effects with all its computations.[br][br]Disable if you just need it for occlusion detection, for example fading ambient rain when entering a house.
#@export_range(-81, +80, 3.0, "suffix:dB") var reverb_volume_db: float = -6 ## Maximum volume of the reverbs.
#@export_range(-1, 5, 0.05, "or_greater", "suffix:s") var reverb_fadeintime: float = 2.0 ## Fade-in time when a reverb is added at a wall.[br][br]The default of 2s is a good value where changes in environment merge well into the overall sound mix.[br]If you have small areas with little changes of distances, set this value to low (0.2s) so that repositioned reverbs don't get stuck for too long in a position. In a large area, when the raycast suddenly hits a close wall, the sudden appearing reverb can sound unnatural.[br][br]Set to -1 for dynamic fade time (based on wetness).
#@export_range(-1, 8, 0.05, "or_greater", "suffix:s") var reverb_fadeouttime: float = 2.0 ## Fade-out time when a reverb is removed.[br][br]The default of 2s is a good value where changes in environment merge well into the overall sound mix.[br]If you have small areas with little changes of distances, set this value to low (0.2s) so that repositioned reverbs don't get stuck for too long in a position.[br][br]Set to -1 for dynamic fade time (based on wetness).
#@export_range(1, 20_000, 0.1, "suffix:Hz") var occlusion_lp_cutoff: int = 600 ## Frequency when soundsource is occluded behind walls.
#@export_range(0, 5, 0.05, "or_greater", "suffix:s") var occlusion_fadetime: float = 0.5 ## Fadetime when occlusion changes.
#@export_range(0, 100, 0.1, "or_greater", "suffix:m") var bass_proximity: int = 50 ## The closer you are to a wall, the more bass you will hear.[br][br]The effect starts at this value (distance to the wall).[br][br]0 to disable.
#
#@export_subgroup("Physics")
#@export_range(1, 100, 1, "or_greater", "suffix:m") var max_raycast_distance: int = 100 ## Maximum distance for the reverb raycasts.
#@export_flags_3d_physics var collision_mask: int = 1 ## Mask for the raycast where to add reverb.
#@export var roomsize_multiplicator: float = 6.0 ## How much hall to add compared to room size.[br]Sometimes you have a small room but you need a long reverb.
#@export_range(1, 340, 1, "or_greater", "suffix:m/s") var speed_of_sound: int = 340 ## How fast sound travels through the air.
#@export var prox_reduction: float = 24.0 ## How much proximity reduces the reverb
#@export_range(4,32,1) var reverb_raycast_count: int = 4 ##how many reverb raycasts to shoot out horizontally
#
#@export_subgroup("System")
#@export_range(1, 60, 0.1, "or_greater", "suffix:per second") var audiophysics_ticks: int = 10 ## The number of audio physics calculations per second.[br]Tied to _physics_process().[br][br]Use 30-60 for fast moving sounds like a motorcycle passing by.[br][br]Default: 10.
#@export var loop: bool = false ## Loop audio indefinitely.
#@export var shut_up: bool = false ## Mute output.
#@export var debug: bool = false ## Visualize raycasts, measurement rays and reverb-audioplayers.
var audio_player: AudioStreamPlayer3D = null
func do_set_stream(new_stream:AudioStream):
stream = new_stream
if easy_audio:
audio_player.stream = new_stream
else:
audio_player.do_set_stream(new_stream)
stream = new_stream
func do_play(start_position: float = 0.0) -> void:
if audio_player is SpatialAudio3D:
audio_player.do_play(start_position)
else:
audio_player.play(start_position)
func do_stop() -> void:
if audio_player is SpatialAudio3D:
audio_player.do_stop()
else:
audio_player.stop()
func set_to_easy_audio():
@ -64,29 +55,27 @@ func set_to_raytraced_audio() -> void:
if audio_player != null:
audio_player.queue_free()
audio_player = SpatialAudio3D.new()
audio_player = RaytracedAudioPlayer3D.new()
audio_player.reverb_enabled = reverb_enabled
audio_player.reverb_volume_db = reverb_volume_db
audio_player.reverb_fadeintime = reverb_fadeintime
audio_player.reverb_fadeouttime = reverb_fadeouttime
audio_player.occlusion_lp_cutoff = occlusion_lp_cutoff
audio_player.occlusion_fadetime = occlusion_fadetime
audio_player.bass_proximity = bass_proximity
audio_player.max_raycast_distance = max_raycast_distance
audio_player.collision_mask = collision_mask
audio_player.roomsize_multiplicator = roomsize_multiplicator
audio_player.speed_of_sound = speed_of_sound
audio_player.prox_reduction = prox_reduction
audio_player.reverb_raycast_count = reverb_raycast_count
#audio_player.reverb_enabled = reverb_enabled
#audio_player.reverb_volume_db = reverb_volume_db
#audio_player.reverb_fadeintime = reverb_fadeintime
#audio_player.reverb_fadeouttime = reverb_fadeouttime
#audio_player.occlusion_lp_cutoff = occlusion_lp_cutoff
#audio_player.occlusion_fadetime = occlusion_fadetime
#audio_player.bass_proximity = bass_proximity
#
#audio_player.max_raycast_distance = max_raycast_distance
#audio_player.collision_mask = collision_mask
#audio_player.roomsize_multiplicator = roomsize_multiplicator
#audio_player.speed_of_sound = speed_of_sound
#audio_player.prox_reduction = prox_reduction
#audio_player.reverb_raycast_count = reverb_raycast_count
audio_player.name = "music player"
audio_player.audiophysics_ticks = 10
audio_player.loop = loop
audio_player.shut_up = shut_up
audio_player.debug = debug
#audio_player.loop = loop
#audio_player.shut_up = shut_up
#audio_player.debug = debug
add_child(audio_player)
@ -97,6 +86,5 @@ func _ready() -> void:
else:
set_to_raytraced_audio()
audio_player.stream = stream
audio_player.do_set_stream(stream)
audio_player.global_position = global_position

View file

@ -12,11 +12,11 @@ func _process(delta: float) -> void:
func _on_button_pressed() -> void:
UiManager.toggle_self()
get_tree().change_scene_to_file("res://maps/procedural_map_parts_ver_premade/map_generator.tscn")
get_tree().change_scene_to_file("uid://c5p2fbgi8co1c")
func _on_button_2_pressed() -> void:
UiManager.toggle_self()
get_tree().change_scene_to_file("res://maps/dev/dev_map.tscn")
get_tree().change_scene_to_file("uid://chykk2a3opu0d")
func _on_button_3_pressed() -> void:
print("options")

View file

@ -18,6 +18,7 @@ func _exit_tree() -> void:
pass
func _input_event(_camera: Camera3D, event: InputEvent, event_position: Vector3, _normal: Vector3, _shape_idx: int) -> void:
if is_inside_tree():
if not (event is InputEventMouse or event is InputEventScreenTouch):
return

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://bqi71jcv228ha"]
[ext_resource type="Script" uid="uid://cufnrtuy8ihp8" path="res://maps/procedural_map_parts_ver_premade/blocks/corridor_base.gd" id="1_xccyg"]
[ext_resource type="Script" uid="uid://cufnrtuy8ihp8" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/corridor_base.gd" id="1_xccyg"]
[sub_resource type="BoxShape3D" id="BoxShape3D_2uy16"]
size = Vector3(3, 3, 0.2)

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://bv6nflwc0fial"]
[ext_resource type="Script" uid="uid://cbpmudbod58kd" path="res://maps/procedural_map_parts_ver_premade/blocks/corridor_turn_base.gd" id="1_6u82c"]
[ext_resource type="Script" uid="uid://cbpmudbod58kd" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/corridor_turn_base.gd" id="1_6u82c"]
[sub_resource type="BoxShape3D" id="BoxShape3D_wc7xr"]
size = Vector3(2, 5.0625, 0.2)

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://72meffei7m1x"]
[ext_resource type="Script" uid="uid://cbpmudbod58kd" path="res://maps/procedural_map_parts_ver_premade/blocks/corridor_turn_base.gd" id="1_8qdpf"]
[ext_resource type="Script" uid="uid://cbpmudbod58kd" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/corridor_turn_base.gd" id="1_8qdpf"]
[sub_resource type="BoxShape3D" id="BoxShape3D_wc7xr"]
size = Vector3(2, 5.0625, 0.2)

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://dpipi1pttxrcp"]
[ext_resource type="Script" uid="uid://0iyg3xfklibl" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_base.gd" id="1_0vkv4"]
[ext_resource type="Script" uid="uid://0iyg3xfklibl" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_base.gd" id="1_0vkv4"]
[sub_resource type="BoxShape3D" id="BoxShape3D_pxn7n"]
size = Vector3(3, 3, 0.5260132)

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://dyh7k0iqmoa1s"]
[ext_resource type="Script" uid="uid://dca56unue57vt" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.gd" id="1_iomhl"]
[ext_resource type="Script" uid="uid://dca56unue57vt" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.gd" id="1_iomhl"]
[sub_resource type="BoxShape3D" id="BoxShape3D_y77ur"]
size = Vector3(0.5, 3, 0.2)

View file

@ -1,13 +1,13 @@
[gd_scene format=3 uid="uid://c5p2fbgi8co1c"]
[ext_resource type="Script" uid="uid://dqddq642yha0o" path="res://maps/procedural_map_parts_ver_premade/map_generator.gd" id="1_oa821"]
[ext_resource type="PackedScene" uid="uid://cm24rsfnjw4ok" path="res://maps/procedural_map_parts_ver_premade/parts/big_part.tscn" id="1_ywphk"]
[ext_resource type="Script" uid="uid://dqddq642yha0o" path="res://scenes/maps/procedural_map_parts_ver_premade/map_generator.gd" id="1_oa821"]
[ext_resource type="PackedScene" uid="uid://cm24rsfnjw4ok" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/big_part.tscn" id="1_ywphk"]
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://entities/player/player.tscn" id="2_hajlu"]
[ext_resource type="PackedScene" uid="uid://doddrjiew6eov" path="res://maps/procedural_map_parts_ver_premade/parts/end_part.tscn" id="3_dpdkl"]
[ext_resource type="PackedScene" uid="uid://do7paidwkyx2e" path="res://maps/procedural_map_parts_ver_premade/parts/medium_part.tscn" id="4_vnae6"]
[ext_resource type="PackedScene" uid="uid://tap7imlv8vb0" path="res://maps/procedural_map_parts_ver_premade/parts/small_part.tscn" id="5_s0fpg"]
[ext_resource type="PackedScene" uid="uid://bqi71jcv228ha" path="res://maps/procedural_map_parts_ver_premade/blocks/corridor_base.tscn" id="6_nd2uf"]
[ext_resource type="PackedScene" uid="uid://72meffei7m1x" path="res://maps/procedural_map_parts_ver_premade/blocks/corridor_turn_right_base.tscn" id="7_l0kyl"]
[ext_resource type="PackedScene" uid="uid://doddrjiew6eov" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/end_part.tscn" id="3_dpdkl"]
[ext_resource type="PackedScene" uid="uid://do7paidwkyx2e" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/medium_part.tscn" id="4_vnae6"]
[ext_resource type="PackedScene" uid="uid://tap7imlv8vb0" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/small_part.tscn" id="5_s0fpg"]
[ext_resource type="PackedScene" uid="uid://bqi71jcv228ha" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/corridor_base.tscn" id="6_nd2uf"]
[ext_resource type="PackedScene" uid="uid://72meffei7m1x" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/corridor_turn_right_base.tscn" id="7_l0kyl"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_hajlu"]
sky_energy_multiplier = 0.0

View file

@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://cm24rsfnjw4ok"]
[ext_resource type="PackedScene" uid="uid://dpipi1pttxrcp" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_base.tscn" id="1_3yqjc"]
[ext_resource type="Script" uid="uid://dvmuhlmqeknv2" path="res://maps/procedural_map_parts_ver_premade/parts/big_part.gd" id="1_sdg7d"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="2_1mbjt"]
[ext_resource type="PackedScene" uid="uid://dpipi1pttxrcp" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_base.tscn" id="1_3yqjc"]
[ext_resource type="Script" uid="uid://dvmuhlmqeknv2" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/big_part.gd" id="1_sdg7d"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="2_1mbjt"]
[ext_resource type="PackedScene" uid="uid://clr8dvbm56jn8" path="res://entities/usable/music_player.tscn" id="4_adfox"]
[sub_resource type="BoxShape3D" id="BoxShape3D_b5l5s"]

View file

@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://doddrjiew6eov"]
[ext_resource type="Script" uid="uid://djswykurjuy6u" path="res://maps/procedural_map_parts_ver_premade/parts/end_part.gd" id="1_rm6ay"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="2_p5ot5"]
[ext_resource type="Script" uid="uid://djswykurjuy6u" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/end_part.gd" id="1_rm6ay"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="2_p5ot5"]
[sub_resource type="BoxShape3D" id="BoxShape3D_60a4j"]
size = Vector3(3, 3, 0.2)

View file

@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://do7paidwkyx2e"]
[ext_resource type="Script" uid="uid://c6asgt1euaglh" path="res://maps/procedural_map_parts_ver_premade/parts/medium_part.gd" id="1_lljjn"]
[ext_resource type="PackedScene" uid="uid://dpipi1pttxrcp" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_base.tscn" id="1_uhbr2"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="2_hu2t6"]
[ext_resource type="Script" uid="uid://c6asgt1euaglh" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/medium_part.gd" id="1_lljjn"]
[ext_resource type="PackedScene" uid="uid://dpipi1pttxrcp" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_base.tscn" id="1_uhbr2"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="2_hu2t6"]
[sub_resource type="BoxShape3D" id="BoxShape3D_hu2t6"]
size = Vector3(18, 18, 0.2)

View file

@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://tap7imlv8vb0"]
[ext_resource type="Script" uid="uid://u8cgplsupfdj" path="res://maps/procedural_map_parts_ver_premade/parts/small_part.gd" id="1_u3woj"]
[ext_resource type="PackedScene" uid="uid://dpipi1pttxrcp" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_base.tscn" id="2_nyrt0"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="3_kp5l2"]
[ext_resource type="Script" uid="uid://u8cgplsupfdj" path="res://scenes/maps/procedural_map_parts_ver_premade/parts/small_part.gd" id="1_u3woj"]
[ext_resource type="PackedScene" uid="uid://dpipi1pttxrcp" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_base.tscn" id="2_nyrt0"]
[ext_resource type="PackedScene" uid="uid://dyh7k0iqmoa1s" path="res://scenes/maps/procedural_map_parts_ver_premade/blocks/wall_hole_base.tscn" id="3_kp5l2"]
[sub_resource type="BoxShape3D" id="BoxShape3D_u3woj"]
size = Vector3(3, 3, 9)

View file

@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://cgtq0bwlps87x"]
[ext_resource type="Script" uid="uid://b81cq1wvkdtlg" path="res://maps/procedural_map_ver_generated_parts/map_generator.gd" id="1_rupvp"]
[ext_resource type="PackedScene" uid="uid://5k3qstcxs2p0" path="res://maps/procedural_map_ver_generated_parts/floor.tscn" id="2_wti8w"]
[ext_resource type="PackedScene" uid="uid://b50hwp4iervw" path="res://maps/procedural_map_ver_generated_parts/wall.tscn" id="3_uig64"]
[ext_resource type="Script" uid="uid://b81cq1wvkdtlg" path="res://scenes/maps/procedural_map_ver_generated_parts/map_generator.gd" id="1_rupvp"]
[ext_resource type="PackedScene" uid="uid://5k3qstcxs2p0" path="res://scenes/maps/procedural_map_ver_generated_parts/floor.tscn" id="2_wti8w"]
[ext_resource type="PackedScene" uid="uid://b50hwp4iervw" path="res://scenes/maps/procedural_map_ver_generated_parts/wall.tscn" id="3_uig64"]
[node name="MapGenerator" type="Node3D" unique_id=1914632083]
script = ExtResource("1_rupvp")