diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/cpu_particles_2d.cpp | 3 | ||||
-rw-r--r-- | scene/3d/audio_stream_player_3d.cpp | 147 | ||||
-rw-r--r-- | scene/3d/audio_stream_player_3d.h | 1 | ||||
-rw-r--r-- | scene/3d/cpu_particles.cpp | 3 | ||||
-rw-r--r-- | scene/3d/light.cpp | 5 | ||||
-rw-r--r-- | scene/3d/sprite_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/visual_instance.cpp | 13 | ||||
-rw-r--r-- | scene/gui/base_button.cpp | 3 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 2 | ||||
-rw-r--r-- | scene/main/node.cpp | 2 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 2 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 2 | ||||
-rw-r--r-- | scene/resources/animation.cpp | 17 | ||||
-rw-r--r-- | scene/resources/audio_stream_sample.cpp | 3 | ||||
-rw-r--r-- | scene/resources/material.cpp | 10 | ||||
-rw-r--r-- | scene/resources/resource_format_text.cpp | 4 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.cpp | 2 |
17 files changed, 115 insertions, 106 deletions
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 1bddc4d22f..4b309a93b5 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -995,9 +995,6 @@ void CPUParticles2D::_notification(int p_what) { _set_redraw(false); } - if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) { - } - if (p_what == NOTIFICATION_DRAW) { if (!redraw) return; // don't add to render list diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 054c211d23..27f16f7601 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -35,6 +35,99 @@ #include "scene/3d/listener.h" #include "scene/main/viewport.h" +// Based on "A Novel Multichannel Panning Method for Standard and Arbitrary Loudspeaker Configurations" by Ramy Sadek and Chris Kyriakakis (2004) +// Speaker-Placement Correction Amplitude Panning (SPCAP) +class Spcap { +private: + struct Speaker { + Vector3 direction; + real_t effective_number_of_speakers; // precalculated + mutable real_t squared_gain; // temporary + }; + + PoolVector<Speaker> speakers; + +public: + Spcap(unsigned int speaker_count, const Vector3 *speaker_directions) { + this->speakers.resize(speaker_count); + PoolVector<Speaker>::Write w = this->speakers.write(); + for (unsigned int speaker_num = 0; speaker_num < speaker_count; speaker_num++) { + w[speaker_num].direction = speaker_directions[speaker_num]; + w[speaker_num].squared_gain = 0.0; + w[speaker_num].effective_number_of_speakers = 0.0; + for (unsigned int other_speaker_num = 0; other_speaker_num < speaker_count; other_speaker_num++) { + w[speaker_num].effective_number_of_speakers += 0.5 * (1.0 + w[speaker_num].direction.dot(w[other_speaker_num].direction)); + } + } + } + + unsigned int get_speaker_count() const { + return (unsigned int)this->speakers.size(); + } + + Vector3 get_speaker_direction(unsigned int index) const { + return this->speakers.read()[index].direction; + } + + void calculate(const Vector3 &source_direction, real_t tightness, unsigned int volume_count, real_t *volumes) const { + PoolVector<Speaker>::Read r = this->speakers.read(); + real_t sum_squared_gains = 0.0; + for (unsigned int speaker_num = 0; speaker_num < (unsigned int)this->speakers.size(); speaker_num++) { + real_t initial_gain = 0.5 * powf(1.0 + r[speaker_num].direction.dot(source_direction), tightness) / r[speaker_num].effective_number_of_speakers; + r[speaker_num].squared_gain = initial_gain * initial_gain; + sum_squared_gains += r[speaker_num].squared_gain; + } + + for (unsigned int speaker_num = 0; speaker_num < MIN(volume_count, (unsigned int)this->speakers.size()); speaker_num++) { + volumes[speaker_num] = sqrtf(r[speaker_num].squared_gain / sum_squared_gains); + } + } +}; + +//TODO: hardcoded main speaker directions for 2, 3.1, 5.1 and 7.1 setups - these are simplified and could also be made configurable +static const Vector3 speaker_directions[7] = { + Vector3(-1.0, 0.0, -1.0).normalized(), // front-left + Vector3(1.0, 0.0, -1.0).normalized(), // front-right + Vector3(0.0, 0.0, -1.0).normalized(), // center + Vector3(-1.0, 0.0, 1.0).normalized(), // rear-left + Vector3(1.0, 0.0, 1.0).normalized(), // rear-right + Vector3(-1.0, 0.0, 0.0).normalized(), // side-left + Vector3(1.0, 0.0, 0.0).normalized(), // side-right +}; + +void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tightness, AudioStreamPlayer3D::Output &output) { + unsigned int speaker_count; // only main speakers (no LFE) + switch (AudioServer::get_singleton()->get_speaker_mode()) { + default: //fallthrough + case AudioServer::SPEAKER_MODE_STEREO: speaker_count = 2; break; + case AudioServer::SPEAKER_SURROUND_31: speaker_count = 3; break; + case AudioServer::SPEAKER_SURROUND_51: speaker_count = 5; break; + case AudioServer::SPEAKER_SURROUND_71: speaker_count = 7; break; + } + + Spcap spcap(speaker_count, speaker_directions); //TODO: should only be created/recreated once the speaker mode / speaker positions changes + real_t volumes[7]; + spcap.calculate(source_dir, tightness, speaker_count, volumes); + + switch (AudioServer::get_singleton()->get_speaker_mode()) { + case AudioServer::SPEAKER_SURROUND_71: + output.vol[3].l = volumes[5]; // side-left + output.vol[3].r = volumes[6]; // side-right + //fallthrough + case AudioServer::SPEAKER_SURROUND_51: + output.vol[2].l = volumes[3]; // rear-left + output.vol[2].r = volumes[4]; // rear-right + //fallthrough + case AudioServer::SPEAKER_SURROUND_31: + output.vol[1].r = 1.0; // LFE - always full power + output.vol[1].l = volumes[2]; // center + //fallthrough + case AudioServer::SPEAKER_MODE_STEREO: + output.vol[0].r = volumes[1]; // front-right + output.vol[0].l = volumes[0]; // front-left + } +} + void AudioStreamPlayer3D::_mix_audio() { if (!stream_playback.is_valid() || !active || @@ -381,59 +474,11 @@ void AudioStreamPlayer3D::_notification(int p_what) { output.filter_gain = Math::db2linear(db_att); - Vector3 flat_pos = local_pos; - flat_pos.y = 0; - flat_pos.normalize(); + //TODO: The lower the second parameter (tightness) the more the sound will "enclose" the listener (more undirected / playing from + // speakers not facing the source) - this could be made distance dependent. + _calc_output_vol(local_pos.normalized(), 4.0, output); unsigned int cc = AudioServer::get_singleton()->get_channel_count(); - if (cc == 1) { - // Stereo pair - float c = flat_pos.x * 0.5 + 0.5; - - output.vol[0].l = 1.0 - c; - output.vol[0].r = c; - } else { - Vector3 listenertopos = global_pos - listener_node->get_global_transform().origin; - float c = listenertopos.normalized().dot(get_global_transform().basis.get_axis(2).normalized()); //it's z negative - float angle = Math::rad2deg(Math::acos(c)); - float av = angle * (flat_pos.x < 0 ? -1 : 1) / 180.0; - - if (cc >= 1) { - // Stereo pair - float fl = Math::abs(1.0 - Math::abs(-0.8 - av)); - float fr = Math::abs(1.0 - Math::abs(0.8 - av)); - - output.vol[0].l = fl; - output.vol[0].r = fr; - } - - if (cc >= 2) { - // Center pair - float center = 1.0 - Math::sin(Math::acos(c)); - - output.vol[1].l = center; - output.vol[1].r = center; - } - - if (cc >= 3) { - // Side pair - float sleft = Math::abs(1.0 - Math::abs(-0.4 - av)); - float sright = Math::abs(1.0 - Math::abs(0.4 - av)); - - output.vol[2].l = sleft; - output.vol[2].r = sright; - } - - if (cc >= 4) { - // Rear pair - float rleft = Math::abs(1.0 - Math::abs(-0.2 - av)); - float rright = Math::abs(1.0 - Math::abs(0.2 - av)); - - output.vol[3].l = rleft; - output.vol[3].r = rright; - } - } - for (unsigned int k = 0; k < cc; k++) { output.vol[k] *= multiplier; } diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 93954e758a..494aa70097 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -115,6 +115,7 @@ private: bool stream_paused_fade_out; StringName bus; + static void _calc_output_vol(const Vector3 &source_dir, real_t tightness, Output &output); void _mix_audio(); static void _mix_audios(void *self) { reinterpret_cast<AudioStreamPlayer3D *>(self)->_mix_audio(); } diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp index 7ab7363c7c..fc16bc36cb 100644 --- a/scene/3d/cpu_particles.cpp +++ b/scene/3d/cpu_particles.cpp @@ -1074,9 +1074,6 @@ void CPUParticles::_notification(int p_what) { _set_redraw(false); } - if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) { - } - if (p_what == NOTIFICATION_INTERNAL_PROCESS) { if (particles.size() == 0 || !is_visible_in_tree()) { diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 4ef945ab8d..85ee925248 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -200,9 +200,6 @@ void Light::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { _update_visibility(); } - - if (p_what == NOTIFICATION_EXIT_TREE) { - } } void Light::set_editor_only(bool p_editor_only) { @@ -413,7 +410,7 @@ DirectionalLight::DirectionalLight() : set_param(PARAM_SHADOW_NORMAL_BIAS, 0.8); set_param(PARAM_SHADOW_BIAS, 0.1); - set_param(PARAM_SHADOW_MAX_DISTANCE, 200); + set_param(PARAM_SHADOW_MAX_DISTANCE, 100); set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE, 0.25); set_shadow_mode(SHADOW_PARALLEL_4_SPLITS); set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 67c79d8b5a..2c315790ac 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -558,7 +558,7 @@ Rect2 Sprite3D::get_region_rect() const { void Sprite3D::set_frame(int p_frame) { - ERR_FAIL_INDEX(p_frame, vframes * hframes); + ERR_FAIL_INDEX(p_frame, int64_t(vframes) * hframes); if (frame != p_frame) diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp index 5141c84803..d1de0c56a7 100644 --- a/scene/3d/visual_instance.cpp +++ b/scene/3d/visual_instance.cpp @@ -215,17 +215,6 @@ float GeometryInstance::get_lod_max_hysteresis() const { } void GeometryInstance::_notification(int p_what) { - - if (p_what == NOTIFICATION_ENTER_WORLD) { - - if (flags[FLAG_USE_BAKED_LIGHT]) { - } - - } else if (p_what == NOTIFICATION_EXIT_WORLD) { - - if (flags[FLAG_USE_BAKED_LIGHT]) { - } - } } void GeometryInstance::set_flag(Flags p_flag, bool p_value) { @@ -236,8 +225,6 @@ void GeometryInstance::set_flag(Flags p_flag, bool p_value) { flags[p_flag] = p_value; VS::get_singleton()->instance_geometry_set_flag(get_instance(), (VS::InstanceFlags)p_flag, p_value); - if (p_flag == FLAG_USE_BAKED_LIGHT) { - } } bool GeometryInstance::get_flag(Flags p_flag) const { diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 52fcea2a71..4f71481280 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -115,9 +115,6 @@ void BaseButton::_notification(int p_what) { } } - if (p_what == NOTIFICATION_ENTER_TREE) { - } - if (p_what == NOTIFICATION_EXIT_TREE || (p_what == NOTIFICATION_VISIBILITY_CHANGED && !is_visible_in_tree())) { if (!toggle_mode) { diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 4005505830..814100afdc 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2921,8 +2921,6 @@ void Tree::_notification(int p_what) { drag_touching = false; drag_touching_deaccel = false; } - - } else { } } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 06d6f0871c..caa0da5d1f 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -210,7 +210,7 @@ void Node::_propagate_enter_tree() { } data.viewport = Object::cast_to<Viewport>(this); - if (!data.viewport) + if (!data.viewport && data.parent) data.viewport = data.parent->data.viewport; data.inside_tree = true; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 5eeaff6411..2badf19f2b 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1089,7 +1089,7 @@ void SceneTree::get_nodes_in_group(const StringName &p_group, List<Node *> *p_li static void _fill_array(Node *p_node, Array &array, int p_level) { - array.push_back(p_level); + array.push_back(p_node->get_child_count()); array.push_back(p_node->get_name()); array.push_back(p_node->get_class()); array.push_back(p_node->get_instance_id()); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index d147d43f50..9466b7c5c1 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -581,7 +581,7 @@ void Viewport::_notification(int p_what) { if (physics_object_capture != 0) { CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_capture)); - if (co) { + if (co && camera) { _collision_object_input_event(co, camera, ev, Vector3(), Vector3(), 0); captured = true; if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) { diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 64051fe304..8c8552ac54 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1667,8 +1667,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Vector2 pb = p_post_b; return a.cubic_interpolate(b, pa, pb, p_c); - - } break; + } case Variant::RECT2: { Rect2 a = p_a; @@ -1679,8 +1678,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a return Rect2( a.position.cubic_interpolate(b.position, pa.position, pb.position, p_c), a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); - - } break; + } case Variant::VECTOR3: { Vector3 a = p_a; @@ -1689,8 +1687,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Vector3 pb = p_post_b; return a.cubic_interpolate(b, pa, pb, p_c); - - } break; + } case Variant::QUAT: { Quat a = p_a; @@ -1699,8 +1696,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Quat pb = p_post_b; return a.cubic_slerp(b, pa, pb, p_c); - - } break; + } case Variant::AABB: { AABB a = p_a; @@ -1711,14 +1707,12 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a return AABB( a.position.cubic_interpolate(b.position, pa.position, pb.position, p_c), a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); - } break; + } default: { return _interpolate(p_a, p_b, p_c); } } - - return Variant(); } float Animation::_cubic_interpolate(const float &p_pre_a, const float &p_a, const float &p_b, const float &p_post_b, float p_c) const { @@ -3028,7 +3022,6 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons //this could be done as a second pass and would be //able to optimize more erase = false; - } else { } } } diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index 4b3e392013..5b61654c5d 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -564,7 +564,8 @@ Error AudioStreamSample::save_to_wav(const String &p_path) { file->store_32(sub_chunk_2_size); //Subchunk2Size // Add data - PoolVector<uint8_t>::Read read_data = get_data().read(); + PoolVector<uint8_t> data = get_data(); + PoolVector<uint8_t>::Read read_data = data.read(); switch (format) { case AudioStreamSample::FORMAT_8_BITS: for (unsigned int i = 0; i < data_bytes; i++) { diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 197ff14b38..44bc862198 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -691,9 +691,9 @@ void SpatialMaterial::_update_shader() { code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n"; code += "\tTANGENT = normalize(TANGENT);\n"; - code += "\tBINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n"; - code += "\tBINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n"; - code += "\tBINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n"; + code += "\tBINORMAL = vec3(0.0,-1.0,0.0) * abs(NORMAL.x);\n"; + code += "\tBINORMAL+= vec3(0.0,0.0,1.0) * abs(NORMAL.y);\n"; + code += "\tBINORMAL+= vec3(0.0,-1.0,0.0) * abs(NORMAL.z);\n"; code += "\tBINORMAL = normalize(BINORMAL);\n"; } @@ -2353,8 +2353,8 @@ SpatialMaterial::SpatialMaterial() : set_ao_light_affect(0.0); - set_metallic_texture_channel(TEXTURE_CHANNEL_BLUE); - set_roughness_texture_channel(TEXTURE_CHANNEL_GREEN); + set_metallic_texture_channel(TEXTURE_CHANNEL_RED); + set_roughness_texture_channel(TEXTURE_CHANNEL_RED); set_ao_texture_channel(TEXTURE_CHANNEL_RED); set_refraction_texture_channel(TEXTURE_CHANNEL_RED); diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 12bf007bb1..6212066c3c 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -1371,8 +1371,6 @@ String ResourceFormatSaverTextInstance::_write_resource(const RES &res) { //internal resource } } - - return "null"; } void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, bool p_main) { @@ -1514,8 +1512,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r } } - ERR_FAIL_COND_V(err != OK, err); - { String title = packed_scene.is_valid() ? "[gd_scene " : "[gd_resource "; if (packed_scene.is_null()) diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 06f18472ce..21ee247b02 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -3437,7 +3437,7 @@ String VisualShaderNodeCompare::get_warning(Shader::Mode p_mode, VisualShader::T if (ctype == CTYPE_BOOLEAN || ctype == CTYPE_TRANSFORM) { if (func > FUNC_NOT_EQUAL) { - return TTR("Invalid comparsion function for that type."); + return TTR("Invalid comparison function for that type."); } } |