From 741145febd2b4fc2db4b076a339ded88dfa3c5e5 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 15 Jul 2017 18:40:47 -0300 Subject: -Fix for multiple reflection probes causing issues. -Fix for positional sound corruption to avoid making people deaf. --- scene/3d/audio_stream_player_3d.cpp | 32 ++++++++++++++++++++++++++------ scene/3d/audio_stream_player_3d.h | 7 ++++++- scene/3d/reflection_probe.cpp | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) (limited to 'scene') diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index cc9470e88d..87ea018425 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -382,6 +382,9 @@ void AudioStreamPlayer3D::_notification(int p_what) { } break; } + bool filled_reverb = false; + int vol_index_max = AudioServer::get_singleton()->get_speaker_mode() + 1; + if (area) { if (area->is_overriding_audio_bus()) { @@ -391,14 +394,14 @@ void AudioStreamPlayer3D::_notification(int p_what) { } if (area->is_using_reverb_bus()) { + + filled_reverb = true; StringName bus_name = area->get_reverb_bus(); output.reverb_bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus_name); float uniformity = area->get_reverb_uniformity(); float area_send = area->get_reverb_amount(); - int vol_index_max = AudioServer::get_singleton()->get_speaker_mode() + 1; - if (uniformity > 0.0) { float distance = cam_area_pos.length(); @@ -406,6 +409,9 @@ void AudioStreamPlayer3D::_notification(int p_what) { //float dist_att_db = -20 * Math::log(dist + 0.00001); //logarithmic attenuation, like in real life + float center_val[3] = { 0.5, 0.25, 0.16666 }; + AudioFrame center_frame(center_val[vol_index_max - 1], center_val[vol_index_max - 1]); + if (attenuation < 1.0) { //pan the uniform sound Vector3 rev_pos = cam_area_pos; @@ -448,14 +454,20 @@ void AudioStreamPlayer3D::_notification(int p_what) { } break; } - } - float center_val[3] = { 0.5, 0.25, 0.16666 }; - AudioFrame center_frame(center_val[vol_index_max - 1], center_val[vol_index_max - 1]); + for (int i = 0; i < vol_index_max; i++) { + + output.reverb_vol[i] = output.reverb_vol[i].linear_interpolate(center_frame, attenuation); + } + } else { + for (int i = 0; i < vol_index_max; i++) { + + output.reverb_vol[i] = center_frame; + } + } for (int i = 0; i < vol_index_max; i++) { - output.reverb_vol[i] = output.reverb_vol[i].linear_interpolate(center_frame, attenuation); output.reverb_vol[i] = output.vol[i].linear_interpolate(output.reverb_vol[i] * attenuation, uniformity); output.reverb_vol[i] *= area_send; } @@ -491,6 +503,14 @@ void AudioStreamPlayer3D::_notification(int p_what) { output.pitch_scale = 1.0; } + if (!filled_reverb) { + + for (int i = 0; i < vol_index_max; i++) { + + output.reverb_vol[i] = AudioFrame(0, 0); + } + } + outputs[new_output_count] = output; new_output_count++; if (new_output_count == MAX_OUTPUTS) diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 549bf67a2f..8603cab5a4 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -48,7 +48,12 @@ private: AudioFrame reverb_vol[3]; Viewport *viewport; //pointer only used for reference to previous mix - Output() { filter_gain = 0; } + Output() { + filter_gain = 0; + viewport = NULL; + reverb_bus_index = -1; + bus_index = -1; + } }; Output outputs[MAX_OUTPUTS]; diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index 86a62bec97..0dc5b58e45 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -162,7 +162,7 @@ bool ReflectionProbe::are_shadows_enabled() const { void ReflectionProbe::set_cull_mask(uint32_t p_layers) { cull_mask = p_layers; - VS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_layers); + VS::get_singleton()->reflection_probe_set_cull_mask(probe, p_layers); } uint32_t ReflectionProbe::get_cull_mask() const { -- cgit v1.2.3