diff options
Diffstat (limited to 'servers')
102 files changed, 1869 insertions, 659 deletions
diff --git a/servers/arvr_server.cpp b/servers/arvr_server.cpp index 724414ae96..f5597d8974 100644 --- a/servers/arvr_server.cpp +++ b/servers/arvr_server.cpp @@ -33,7 +33,7 @@ #include "arvr/arvr_positional_tracker.h" #include "core/project_settings.h" -ARVRServer *ARVRServer::singleton = NULL; +ARVRServer *ARVRServer::singleton = nullptr; ARVRServer *ARVRServer::get_singleton() { return singleton; @@ -109,7 +109,7 @@ Transform ARVRServer::get_reference_frame() const { }; void ARVRServer::center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height) { - if (primary_interface != NULL) { + if (primary_interface != nullptr) { // clear our current reference frame or we'll end up double adjusting it reference_frame = Transform(); @@ -142,7 +142,7 @@ void ARVRServer::center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height) Transform ARVRServer::get_hmd_transform() { Transform hmd_transform; - if (primary_interface != NULL) { + if (primary_interface != nullptr) { hmd_transform = primary_interface->get_transform_for_eye(ARVRInterface::EYE_MONO, hmd_transform); }; return hmd_transform; @@ -189,7 +189,7 @@ int ARVRServer::get_interface_count() const { }; Ref<ARVRInterface> ARVRServer::get_interface(int p_index) const { - ERR_FAIL_INDEX_V(p_index, interfaces.size(), NULL); + ERR_FAIL_INDEX_V(p_index, interfaces.size(), nullptr); return interfaces[p_index]; }; @@ -205,7 +205,7 @@ Ref<ARVRInterface> ARVRServer::find_interface(const String &p_name) const { }; }; - ERR_FAIL_COND_V(idx == -1, NULL); + ERR_FAIL_COND_V(idx == -1, nullptr); return interfaces[idx]; }; @@ -296,13 +296,13 @@ int ARVRServer::get_tracker_count() const { }; ARVRPositionalTracker *ARVRServer::get_tracker(int p_index) const { - ERR_FAIL_INDEX_V(p_index, trackers.size(), NULL); + ERR_FAIL_INDEX_V(p_index, trackers.size(), nullptr); return trackers[p_index]; }; ARVRPositionalTracker *ARVRServer::find_by_type_and_id(TrackerType p_tracker_type, int p_tracker_id) const { - ERR_FAIL_COND_V(p_tracker_id == 0, NULL); + ERR_FAIL_COND_V(p_tracker_id == 0, nullptr); for (int i = 0; i < trackers.size(); i++) { if (trackers[i]->get_type() == p_tracker_type && trackers[i]->get_tracker_id() == p_tracker_id) { @@ -310,7 +310,7 @@ ARVRPositionalTracker *ARVRServer::find_by_type_and_id(TrackerType p_tracker_typ }; }; - return NULL; + return nullptr; }; Ref<ARVRInterface> ARVRServer::get_primary_interface() const { @@ -382,5 +382,5 @@ ARVRServer::~ARVRServer() { trackers.remove(0); } - singleton = NULL; + singleton = nullptr; }; diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp index 69b098edfc..ed67e8902a 100644 --- a/servers/audio/audio_driver_dummy.cpp +++ b/servers/audio/audio_driver_dummy.cpp @@ -38,7 +38,7 @@ Error AudioDriverDummy::init() { active = false; thread_exited = false; exit_thread = false; - samples_in = NULL; + samples_in = nullptr; mix_rate = DEFAULT_MIX_RATE; speaker_mode = SPEAKER_MODE_STEREO; @@ -119,12 +119,12 @@ void AudioDriverDummy::finish() { }; memdelete(thread); - thread = NULL; + thread = nullptr; }; AudioDriverDummy::AudioDriverDummy() { - thread = NULL; + thread = nullptr; }; AudioDriverDummy::~AudioDriverDummy(){ diff --git a/servers/audio/audio_filter_sw.cpp b/servers/audio/audio_filter_sw.cpp index c0bf4f3a55..2771fc177b 100644 --- a/servers/audio/audio_filter_sw.cpp +++ b/servers/audio/audio_filter_sw.cpp @@ -237,7 +237,7 @@ AudioFilterSW::AudioFilterSW() { AudioFilterSW::Processor::Processor() { - set_filter(NULL); + set_filter(nullptr); } void AudioFilterSW::Processor::set_filter(AudioFilterSW *p_filter, bool p_clear_history) { diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cpp index 092c3315ee..0ac7ddc7a9 100644 --- a/servers/audio/audio_rb_resampler.cpp +++ b/servers/audio/audio_rb_resampler.cpp @@ -203,18 +203,18 @@ void AudioRBResampler::clear() { //should be stopped at this point but just in case memdelete_arr(rb); memdelete_arr(read_buf); - rb = NULL; + rb = nullptr; offset = 0; rb_read_pos = 0; rb_write_pos = 0; - read_buf = NULL; + read_buf = nullptr; } AudioRBResampler::AudioRBResampler() { - rb = NULL; + rb = nullptr; offset = 0; - read_buf = NULL; + read_buf = nullptr; rb_read_pos = 0; rb_write_pos = 0; diff --git a/servers/audio/audio_rb_resampler.h b/servers/audio/audio_rb_resampler.h index 8cd9714d57..40cf3e4cd7 100644 --- a/servers/audio/audio_rb_resampler.h +++ b/servers/audio/audio_rb_resampler.h @@ -69,7 +69,7 @@ public: } _FORCE_INLINE_ bool is_ready() const { - return rb != NULL; + return rb != nullptr; } _FORCE_INLINE_ int get_total() const { diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index 56529e208e..a74ac3c007 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -363,4 +363,7 @@ AudioEffectPitchShift::AudioEffectPitchShift() { pitch_scale = 1.0; oversampling = 4; fft_size = FFT_SIZE_2048; + wet = 0.0; + dry = 0.0; + filter = false; } diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp index 8f0c55ad83..f2784679b5 100644 --- a/servers/audio/effects/audio_effect_record.cpp +++ b/servers/audio/effects/audio_effect_record.cpp @@ -178,14 +178,14 @@ Ref<AudioEffectInstance> AudioEffectRecord::instance() { void AudioEffectRecord::ensure_thread_stopped() { recording_active = false; - if (current_instance != 0) { + if (current_instance != nullptr) { current_instance->finish(); } } void AudioEffectRecord::set_recording_active(bool p_record) { if (p_record) { - if (current_instance == 0) { + if (current_instance == nullptr) { WARN_PRINT("Recording should not be set as active before Godot has initialized."); recording_active = false; return; @@ -217,8 +217,8 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const { Vector<uint8_t> dst_data; - ERR_FAIL_COND_V(current_instance.is_null(), NULL); - ERR_FAIL_COND_V(current_instance->recording_data.size() == 0, NULL); + ERR_FAIL_COND_V(current_instance.is_null(), nullptr); + ERR_FAIL_COND_V(current_instance->recording_data.size() == 0, nullptr); if (dst_format == AudioStreamSample::FORMAT_8_BITS) { int data_size = current_instance->recording_data.size(); diff --git a/servers/audio/effects/audio_stream_generator.cpp b/servers/audio/effects/audio_stream_generator.cpp index 5f24cf3d6b..d272a2cdf7 100644 --- a/servers/audio/effects/audio_stream_generator.cpp +++ b/servers/audio/effects/audio_stream_generator.cpp @@ -205,7 +205,7 @@ void AudioStreamGeneratorPlayback::_bind_methods() { } AudioStreamGeneratorPlayback::AudioStreamGeneratorPlayback() { - generator = NULL; + generator = nullptr; skips = 0; active = false; mixed = 0; diff --git a/servers/audio/effects/reverb.cpp b/servers/audio/effects/reverb.cpp index 9946a5eeef..ea2174f1d4 100644 --- a/servers/audio/effects/reverb.cpp +++ b/servers/audio/effects/reverb.cpp @@ -314,7 +314,7 @@ void Reverb::clear_buffers() { if (comb[i].buffer) memdelete_arr(comb[i].buffer); - comb[i].buffer = 0; + comb[i].buffer = nullptr; } for (int i = 0; i < MAX_ALLPASS; i++) { @@ -322,7 +322,7 @@ void Reverb::clear_buffers() { if (allpass[i].buffer) memdelete_arr(allpass[i].buffer); - allpass[i].buffer = 0; + allpass[i].buffer = nullptr; } } @@ -342,7 +342,7 @@ Reverb::Reverb() { hpf_h2 = 0; input_buffer = memnew_arr(float, INPUT_BUFFER_MAX_SIZE); - echo_buffer = 0; + echo_buffer = nullptr; configure_buffers(); update_parameters(); diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 02e6d0f2d4..90033d4a87 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -45,7 +45,7 @@ #define MARK_EDITED #endif -AudioDriver *AudioDriver::singleton = NULL; +AudioDriver *AudioDriver::singleton = nullptr; AudioDriver *AudioDriver::get_singleton() { return singleton; @@ -215,7 +215,7 @@ void AudioDriverManager::initialize(int p_driver) { AudioDriver *AudioDriverManager::get_driver(int p_driver) { - ERR_FAIL_INDEX_V(p_driver, driver_count, NULL); + ERR_FAIL_INDEX_V(p_driver, driver_count, nullptr); return drivers[p_driver]; } @@ -322,7 +322,7 @@ void AudioServer::_mix_step() { bus->soloed = true; } else { - bus = NULL; + bus = nullptr; } } while (bus); @@ -388,7 +388,7 @@ void AudioServer::_mix_step() { //process send - Bus *send = NULL; + Bus *send = nullptr; if (i > 0) { //everything has a send save for master bus @@ -476,8 +476,8 @@ bool AudioServer::thread_has_channel_mix_buffer(int p_bus, int p_buffer) const { AudioFrame *AudioServer::thread_get_channel_mix_buffer(int p_bus, int p_buffer) { - ERR_FAIL_INDEX_V(p_bus, buses.size(), NULL); - ERR_FAIL_INDEX_V(p_buffer, buses[p_bus]->channels.size(), NULL); + ERR_FAIL_INDEX_V(p_bus, buses.size(), nullptr); + ERR_FAIL_INDEX_V(p_buffer, buses[p_bus]->channels.size(), nullptr); AudioFrame *data = buses.write[p_bus]->channels.write[p_buffer].buffer.ptrw(); @@ -1129,7 +1129,7 @@ double AudioServer::get_time_since_last_mix() const { return AudioDriver::get_singleton()->get_time_since_last_mix(); } -AudioServer *AudioServer::singleton = NULL; +AudioServer *AudioServer::singleton = nullptr; void AudioServer::add_callback(AudioCallback p_callback, void *p_userdata) { lock(); @@ -1372,7 +1372,7 @@ AudioServer::AudioServer() { AudioServer::~AudioServer() { - singleton = NULL; + singleton = nullptr; } ///////////////////////////////// diff --git a/servers/camera_server.cpp b/servers/camera_server.cpp index 1a86ff1af4..3caea6b7c3 100644 --- a/servers/camera_server.cpp +++ b/servers/camera_server.cpp @@ -35,7 +35,7 @@ //////////////////////////////////////////////////////// // CameraServer -CameraServer::CreateFunc CameraServer::create_func = NULL; +CameraServer::CreateFunc CameraServer::create_func = nullptr; void CameraServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_feed", "index"), &CameraServer::get_feed); @@ -54,7 +54,7 @@ void CameraServer::_bind_methods() { BIND_ENUM_CONSTANT(FEED_CBCR_IMAGE); }; -CameraServer *CameraServer::singleton = NULL; +CameraServer *CameraServer::singleton = nullptr; CameraServer *CameraServer::get_singleton() { return singleton; @@ -92,7 +92,7 @@ Ref<CameraFeed> CameraServer::get_feed_by_id(int p_id) { int index = get_feed_index(p_id); if (index == -1) { - return NULL; + return nullptr; } else { return feeds[index]; } @@ -132,7 +132,7 @@ void CameraServer::remove_feed(const Ref<CameraFeed> &p_feed) { }; Ref<CameraFeed> CameraServer::get_feed(int p_index) { - ERR_FAIL_INDEX_V(p_index, feeds.size(), NULL); + ERR_FAIL_INDEX_V(p_index, feeds.size(), nullptr); return feeds[p_index]; }; @@ -167,5 +167,5 @@ CameraServer::CameraServer() { }; CameraServer::~CameraServer() { - singleton = NULL; + singleton = nullptr; }; diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 9798c57707..da1a68a179 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "display_server.h" + #include "core/input/input_filter.h" #include "scene/resources/texture.h" @@ -434,7 +435,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("native_video_unpause"), &DisplayServer::native_video_unpause); ClassDB::bind_method(D_METHOD("dialog_show", "title", "description", "buttons", "callback"), &DisplayServer::dialog_show); - ClassDB::bind_method(D_METHOD("dialog_input_text", "title", "description", "existing_text", "callback"), &DisplayServer::dialog_show); + ClassDB::bind_method(D_METHOD("dialog_input_text", "title", "description", "existing_text", "callback"), &DisplayServer::dialog_input_text); ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &DisplayServer::get_latin_keyboard_variant); @@ -517,11 +518,6 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(WINDOW_FLAG_TRANSPARENT); BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS); BIND_ENUM_CONSTANT(WINDOW_FLAG_MAX); - BIND_ENUM_CONSTANT(WINDOW_FLAG_RESIZE_DISABLED_BIT); - BIND_ENUM_CONSTANT(WINDOW_FLAG_BORDERLESS_BIT); - BIND_ENUM_CONSTANT(WINDOW_FLAG_ALWAYS_ON_TOP_BIT); - BIND_ENUM_CONSTANT(WINDOW_FLAG_TRANSPARENT_BIT); - BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS_BIT); BIND_ENUM_CONSTANT(LATIN_KEYBOARD_QWERTY); BIND_ENUM_CONSTANT(LATIN_KEYBOARD_QWERTZ); diff --git a/servers/display_server.h b/servers/display_server.h index c0e92891a3..1956bcafca 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -200,6 +200,10 @@ public: WINDOW_FLAG_TRANSPARENT, WINDOW_FLAG_NO_FOCUS, WINDOW_FLAG_MAX, + }; + + // Separate enum otherwise we get warnings in switches not handling all values. + enum WindowFlagsBit { WINDOW_FLAG_RESIZE_DISABLED_BIT = (1 << WINDOW_FLAG_RESIZE_DISABLED), WINDOW_FLAG_BORDERLESS_BIT = (1 << WINDOW_FLAG_BORDERLESS), WINDOW_FLAG_ALWAYS_ON_TOP_BIT = (1 << WINDOW_FLAG_ALWAYS_ON_TOP), diff --git a/servers/navigation_server_2d.cpp b/servers/navigation_server_2d.cpp index fe9eaa5736..17f2232c72 100644 --- a/servers/navigation_server_2d.cpp +++ b/servers/navigation_server_2d.cpp @@ -37,7 +37,7 @@ @author AndreaCatania */ -NavigationServer2D *NavigationServer2D::singleton = NULL; +NavigationServer2D *NavigationServer2D::singleton = nullptr; #define FORWARD_0_C(FUNC_NAME) \ NavigationServer2D::FUNC_NAME() \ @@ -167,7 +167,7 @@ NavigationServer2D::NavigationServer2D() { } NavigationServer2D::~NavigationServer2D() { - singleton = NULL; + singleton = nullptr; } RID FORWARD_0_C(map_create); diff --git a/servers/navigation_server_2d.h b/servers/navigation_server_2d.h index af914e5ba9..d7384bae74 100644 --- a/servers/navigation_server_2d.h +++ b/servers/navigation_server_2d.h @@ -39,7 +39,7 @@ #include "core/rid.h" #include "scene/2d/navigation_region_2d.h" -// This server exposes the 3D `NavigationServer` features in the 2D world. +// This server exposes the `NavigationServer3D` features in the 2D world. class NavigationServer2D : public Object { GDCLASS(NavigationServer2D, Object); diff --git a/servers/navigation_server_3d.cpp b/servers/navigation_server_3d.cpp index 3e7a8e816e..67a4d0e413 100644 --- a/servers/navigation_server_3d.cpp +++ b/servers/navigation_server_3d.cpp @@ -34,7 +34,7 @@ #include "navigation_server_3d.h" -NavigationServer3D *NavigationServer3D::singleton = NULL; +NavigationServer3D *NavigationServer3D::singleton = nullptr; void NavigationServer3D::_bind_methods() { @@ -87,21 +87,21 @@ NavigationServer3D *NavigationServer3D::get_singleton_mut() { } NavigationServer3D::NavigationServer3D() { - ERR_FAIL_COND(singleton != NULL); + ERR_FAIL_COND(singleton != nullptr); singleton = this; } NavigationServer3D::~NavigationServer3D() { - singleton = NULL; + singleton = nullptr; } -NavigationServer3DCallback NavigationServer3DManager::create_callback = NULL; +NavigationServer3DCallback NavigationServer3DManager::create_callback = nullptr; void NavigationServer3DManager::set_default_server(NavigationServer3DCallback p_callback) { create_callback = p_callback; } NavigationServer3D *NavigationServer3DManager::new_default_server() { - ERR_FAIL_COND_V(create_callback == NULL, NULL); + ERR_FAIL_COND_V(create_callback == nullptr, nullptr); return create_callback(); } diff --git a/servers/physics_2d/area_pair_2d_sw.cpp b/servers/physics_2d/area_pair_2d_sw.cpp index 669f27bcc8..0e70a626c2 100644 --- a/servers/physics_2d/area_pair_2d_sw.cpp +++ b/servers/physics_2d/area_pair_2d_sw.cpp @@ -37,7 +37,7 @@ bool AreaPair2DSW::setup(real_t p_step) { if (area->is_shape_set_as_disabled(area_shape) || body->is_shape_set_as_disabled(body_shape)) { result = false; - } else if (area->test_collision_mask(body) && CollisionSolver2DSW::solve(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), Vector2(), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), Vector2(), NULL, this)) { + } else if (area->test_collision_mask(body) && CollisionSolver2DSW::solve(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), Vector2(), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), Vector2(), nullptr, this)) { result = true; } @@ -100,7 +100,7 @@ bool Area2Pair2DSW::setup(real_t p_step) { bool result = false; if (area_a->is_shape_set_as_disabled(shape_a) || area_b->is_shape_set_as_disabled(shape_b)) { result = false; - } else if (area_a->test_collision_mask(area_b) && CollisionSolver2DSW::solve(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), Vector2(), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), Vector2(), NULL, this)) { + } else if (area_a->test_collision_mask(area_b) && CollisionSolver2DSW::solve(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), Vector2(), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), Vector2(), nullptr, this)) { result = true; } diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 11cf1339bc..39e28fd002 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -538,8 +538,8 @@ void Body2DSW::integrate_forces(real_t p_step) { _update_shapes_with_motion(motion); } - // damp_area=NULL; // clear the area, so it is set in the next frame - def_area = NULL; // clear the area, so it is set in the next frame + // damp_area=nullptr; // clear the area, so it is set in the next frame + def_area = nullptr; // clear the area, so it is set in the next frame contact_count = 0; } @@ -650,7 +650,7 @@ void Body2DSW::set_force_integration_callback(ObjectID p_id, const StringName &p if (fi_callback) { memdelete(fi_callback); - fi_callback = NULL; + fi_callback = nullptr; } if (p_id.is_valid()) { @@ -682,8 +682,8 @@ Body2DSW::Body2DSW() : omit_force_integration = false; applied_torque = 0; island_step = 0; - island_next = NULL; - island_list_next = NULL; + island_next = nullptr; + island_list_next = nullptr; _set_static(false); first_time_kinematic = false; linear_damp = -1; @@ -697,7 +697,7 @@ Body2DSW::Body2DSW() : still_time = 0; continuous_cd_mode = PhysicsServer2D::CCD_MODE_DISABLED; can_sleep = true; - fi_callback = NULL; + fi_callback = nullptr; } Body2DSW::~Body2DSW() { @@ -706,7 +706,7 @@ Body2DSW::~Body2DSW() { memdelete(fi_callback); } -PhysicsDirectBodyState2DSW *PhysicsDirectBodyState2DSW::singleton = NULL; +PhysicsDirectBodyState2DSW *PhysicsDirectBodyState2DSW::singleton = nullptr; PhysicsDirectSpaceState2D *PhysicsDirectBodyState2DSW::get_space_state() { diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index e463377c7b..0514b263b4 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -419,7 +419,7 @@ public: virtual real_t get_step() const { return step; } PhysicsDirectBodyState2DSW() { singleton = this; - body = NULL; + body = nullptr; } }; diff --git a/servers/physics_2d/broad_phase_2d_basic.cpp b/servers/physics_2d/broad_phase_2d_basic.cpp index 11bf8712ac..5e3a13f4dd 100644 --- a/servers/physics_2d/broad_phase_2d_basic.cpp +++ b/servers/physics_2d/broad_phase_2d_basic.cpp @@ -65,7 +65,7 @@ void BroadPhase2DBasic::remove(ID p_id) { CollisionObject2DSW *BroadPhase2DBasic::get_object(ID p_id) const { const Map<ID, Element>::Element *E = element_map.find(p_id); - ERR_FAIL_COND_V(!E, NULL); + ERR_FAIL_COND_V(!E, nullptr); return E->get().owner; } bool BroadPhase2DBasic::is_static(ID p_id) const { @@ -158,7 +158,7 @@ void BroadPhase2DBasic::update() { if (pair_ok && !E) { - void *data = NULL; + void *data = nullptr; if (pair_callback) data = pair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, unpair_userdata); pair_map.insert(key, data); @@ -175,8 +175,8 @@ BroadPhase2DSW *BroadPhase2DBasic::_create() { BroadPhase2DBasic::BroadPhase2DBasic() { current = 1; - unpair_callback = NULL; - unpair_userdata = NULL; - pair_callback = NULL; - pair_userdata = NULL; + unpair_callback = nullptr; + unpair_userdata = nullptr; + pair_callback = nullptr; + pair_userdata = nullptr; } diff --git a/servers/physics_2d/broad_phase_2d_basic.h b/servers/physics_2d/broad_phase_2d_basic.h index fea5668c89..7d02590af9 100644 --- a/servers/physics_2d/broad_phase_2d_basic.h +++ b/servers/physics_2d/broad_phase_2d_basic.h @@ -91,8 +91,8 @@ public: virtual bool is_static(ID p_id) const; virtual int get_subindex(ID p_id) const; - virtual int cull_segment(const Vector2 &p_from, const Vector2 &p_to, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = NULL); - virtual int cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = NULL); + virtual int cull_segment(const Vector2 &p_from, const Vector2 &p_to, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = nullptr); + virtual int cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = nullptr); virtual void set_pair_callback(PairCallback p_pair_callback, void *p_userdata); virtual void set_unpair_callback(UnpairCallback p_unpair_callback, void *p_userdata); diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.cpp b/servers/physics_2d/broad_phase_2d_hash_grid.cpp index 711ff9f1f7..2cb021258a 100644 --- a/servers/physics_2d/broad_phase_2d_hash_grid.cpp +++ b/servers/physics_2d/broad_phase_2d_hash_grid.cpp @@ -394,7 +394,7 @@ void BroadPhase2DHashGrid::remove(ID p_id) { CollisionObject2DSW *BroadPhase2DHashGrid::get_object(ID p_id) const { const Map<ID, Element>::Element *E = element_map.find(p_id); - ERR_FAIL_COND_V(!E, NULL); + ERR_FAIL_COND_V(!E, nullptr); return E->get().owner; } bool BroadPhase2DHashGrid::is_static(ID p_id) const { @@ -646,7 +646,7 @@ BroadPhase2DHashGrid::BroadPhase2DHashGrid() { ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/large_object_surface_threshold_in_cells", PropertyInfo(Variant::INT, "physics/2d/large_object_surface_threshold_in_cells", PROPERTY_HINT_RANGE, "0,1024,1,or_greater")); for (uint32_t i = 0; i < hash_table_size; i++) - hash_table[i] = NULL; + hash_table[i] = nullptr; pass = 1; current = 0; diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.h b/servers/physics_2d/broad_phase_2d_hash_grid.h index e75b51c19d..dc29d0c619 100644 --- a/servers/physics_2d/broad_phase_2d_hash_grid.h +++ b/servers/physics_2d/broad_phase_2d_hash_grid.h @@ -44,7 +44,7 @@ class BroadPhase2DHashGrid : public BroadPhase2DSW { PairData() { colliding = false; rc = 1; - ud = NULL; + ud = nullptr; } }; @@ -177,8 +177,8 @@ public: virtual bool is_static(ID p_id) const; virtual int get_subindex(ID p_id) const; - virtual int cull_segment(const Vector2 &p_from, const Vector2 &p_to, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = NULL); - virtual int cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = NULL); + virtual int cull_segment(const Vector2 &p_from, const Vector2 &p_to, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = nullptr); + virtual int cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = nullptr); virtual void set_pair_callback(PairCallback p_pair_callback, void *p_userdata); virtual void set_unpair_callback(UnpairCallback p_unpair_callback, void *p_userdata); diff --git a/servers/physics_2d/broad_phase_2d_sw.cpp b/servers/physics_2d/broad_phase_2d_sw.cpp index c9e1dd8758..5ba557e70a 100644 --- a/servers/physics_2d/broad_phase_2d_sw.cpp +++ b/servers/physics_2d/broad_phase_2d_sw.cpp @@ -30,7 +30,7 @@ #include "broad_phase_2d_sw.h" -BroadPhase2DSW::CreateFunction BroadPhase2DSW::create_func = NULL; +BroadPhase2DSW::CreateFunction BroadPhase2DSW::create_func = nullptr; BroadPhase2DSW::~BroadPhase2DSW() { } diff --git a/servers/physics_2d/broad_phase_2d_sw.h b/servers/physics_2d/broad_phase_2d_sw.h index c7777d9d92..5e42c72d83 100644 --- a/servers/physics_2d/broad_phase_2d_sw.h +++ b/servers/physics_2d/broad_phase_2d_sw.h @@ -58,8 +58,8 @@ public: virtual bool is_static(ID p_id) const = 0; virtual int get_subindex(ID p_id) const = 0; - virtual int cull_segment(const Vector2 &p_from, const Vector2 &p_to, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = NULL) = 0; - virtual int cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = NULL) = 0; + virtual int cull_segment(const Vector2 &p_from, const Vector2 &p_to, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = nullptr) = 0; + virtual int cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices = nullptr) = 0; virtual void set_pair_callback(PairCallback p_pair_callback, void *p_userdata) = 0; virtual void set_unpair_callback(UnpairCallback p_unpair_callback, void *p_userdata) = 0; diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp index a6891372c2..0ec293c042 100644 --- a/servers/physics_2d/collision_object_2d_sw.cpp +++ b/servers/physics_2d/collision_object_2d_sw.cpp @@ -266,7 +266,7 @@ CollisionObject2DSW::CollisionObject2DSW(Type p_type) : _static = true; type = p_type; - space = NULL; + space = nullptr; collision_mask = 1; collision_layer = 1; pickable = true; diff --git a/servers/physics_2d/collision_solver_2d_sat.cpp b/servers/physics_2d/collision_solver_2d_sat.cpp index 217c93c6da..a954cb3de3 100644 --- a/servers/physics_2d/collision_solver_2d_sat.cpp +++ b/servers/physics_2d/collision_solver_2d_sat.cpp @@ -145,7 +145,7 @@ static void _generate_contacts_from_supports(const Vector2 *p_points_A, int p_po _generate_contacts_point_edge, }, { - 0, + nullptr, _generate_contacts_edge_edge, } }; @@ -1060,25 +1060,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<false, false, false>, _collision_segment_capsule<false, false, false>, _collision_segment_convex_polygon<false, false, false> }, - { 0, + { nullptr, _collision_circle_circle<false, false, false>, _collision_circle_rectangle<false, false, false>, _collision_circle_capsule<false, false, false>, _collision_circle_convex_polygon<false, false, false> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<false, false, false>, _collision_rectangle_capsule<false, false, false>, _collision_rectangle_convex_polygon<false, false, false> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<false, false, false>, _collision_capsule_convex_polygon<false, false, false> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<false, false, false> } }; @@ -1089,25 +1089,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<true, false, false>, _collision_segment_capsule<true, false, false>, _collision_segment_convex_polygon<true, false, false> }, - { 0, + { nullptr, _collision_circle_circle<true, false, false>, _collision_circle_rectangle<true, false, false>, _collision_circle_capsule<true, false, false>, _collision_circle_convex_polygon<true, false, false> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<true, false, false>, _collision_rectangle_capsule<true, false, false>, _collision_rectangle_convex_polygon<true, false, false> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<true, false, false>, _collision_capsule_convex_polygon<true, false, false> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<true, false, false> } }; @@ -1118,25 +1118,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<false, true, false>, _collision_segment_capsule<false, true, false>, _collision_segment_convex_polygon<false, true, false> }, - { 0, + { nullptr, _collision_circle_circle<false, true, false>, _collision_circle_rectangle<false, true, false>, _collision_circle_capsule<false, true, false>, _collision_circle_convex_polygon<false, true, false> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<false, true, false>, _collision_rectangle_capsule<false, true, false>, _collision_rectangle_convex_polygon<false, true, false> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<false, true, false>, _collision_capsule_convex_polygon<false, true, false> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<false, true, false> } }; @@ -1147,25 +1147,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<true, true, false>, _collision_segment_capsule<true, true, false>, _collision_segment_convex_polygon<true, true, false> }, - { 0, + { nullptr, _collision_circle_circle<true, true, false>, _collision_circle_rectangle<true, true, false>, _collision_circle_capsule<true, true, false>, _collision_circle_convex_polygon<true, true, false> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<true, true, false>, _collision_rectangle_capsule<true, true, false>, _collision_rectangle_convex_polygon<true, true, false> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<true, true, false>, _collision_capsule_convex_polygon<true, true, false> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<true, true, false> } }; @@ -1176,25 +1176,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<false, false, true>, _collision_segment_capsule<false, false, true>, _collision_segment_convex_polygon<false, false, true> }, - { 0, + { nullptr, _collision_circle_circle<false, false, true>, _collision_circle_rectangle<false, false, true>, _collision_circle_capsule<false, false, true>, _collision_circle_convex_polygon<false, false, true> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<false, false, true>, _collision_rectangle_capsule<false, false, true>, _collision_rectangle_convex_polygon<false, false, true> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<false, false, true>, _collision_capsule_convex_polygon<false, false, true> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<false, false, true> } }; @@ -1205,25 +1205,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<true, false, true>, _collision_segment_capsule<true, false, true>, _collision_segment_convex_polygon<true, false, true> }, - { 0, + { nullptr, _collision_circle_circle<true, false, true>, _collision_circle_rectangle<true, false, true>, _collision_circle_capsule<true, false, true>, _collision_circle_convex_polygon<true, false, true> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<true, false, true>, _collision_rectangle_capsule<true, false, true>, _collision_rectangle_convex_polygon<true, false, true> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<true, false, true>, _collision_capsule_convex_polygon<true, false, true> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<true, false, true> } }; @@ -1234,25 +1234,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<false, true, true>, _collision_segment_capsule<false, true, true>, _collision_segment_convex_polygon<false, true, true> }, - { 0, + { nullptr, _collision_circle_circle<false, true, true>, _collision_circle_rectangle<false, true, true>, _collision_circle_capsule<false, true, true>, _collision_circle_convex_polygon<false, true, true> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<false, true, true>, _collision_rectangle_capsule<false, true, true>, _collision_rectangle_convex_polygon<false, true, true> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<false, true, true>, _collision_capsule_convex_polygon<false, true, true> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<false, true, true> } }; @@ -1263,25 +1263,25 @@ bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D _collision_segment_rectangle<true, true, true>, _collision_segment_capsule<true, true, true>, _collision_segment_convex_polygon<true, true, true> }, - { 0, + { nullptr, _collision_circle_circle<true, true, true>, _collision_circle_rectangle<true, true, true>, _collision_circle_capsule<true, true, true>, _collision_circle_convex_polygon<true, true, true> }, - { 0, - 0, + { nullptr, + nullptr, _collision_rectangle_rectangle<true, true, true>, _collision_rectangle_capsule<true, true, true>, _collision_rectangle_convex_polygon<true, true, true> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_capsule_capsule<true, true, true>, _collision_capsule_convex_polygon<true, true, true> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<true, true, true> } }; diff --git a/servers/physics_2d/collision_solver_2d_sat.h b/servers/physics_2d/collision_solver_2d_sat.h index 105cb9104d..6bb485f561 100644 --- a/servers/physics_2d/collision_solver_2d_sat.h +++ b/servers/physics_2d/collision_solver_2d_sat.h @@ -33,6 +33,6 @@ #include "collision_solver_2d_sw.h" -bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap = false, Vector2 *sep_axis = NULL, real_t p_margin_A = 0, real_t p_margin_B = 0); +bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap = false, Vector2 *sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0); #endif // COLLISION_SOLVER_2D_SAT_H diff --git a/servers/physics_2d/collision_solver_2d_sw.h b/servers/physics_2d/collision_solver_2d_sw.h index e73ee8fd7e..f39cfee0a9 100644 --- a/servers/physics_2d/collision_solver_2d_sw.h +++ b/servers/physics_2d/collision_solver_2d_sw.h @@ -40,11 +40,11 @@ public: private: static bool solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result); static void concave_callback(void *p_userdata, Shape2DSW *p_convex); - static bool solve_concave(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = NULL, real_t p_margin_A = 0, real_t p_margin_B = 0); - static bool solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = NULL); + static bool solve_concave(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0); + static bool solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr); public: - static bool solve(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, Vector2 *sep_axis = NULL, real_t p_margin_A = 0, real_t p_margin_B = 0); + static bool solve(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, Vector2 *sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0); }; #endif // COLLISION_SOLVER_2D_SW_H diff --git a/servers/physics_2d/constraint_2d_sw.h b/servers/physics_2d/constraint_2d_sw.h index b5c994cbdd..f8eb16214f 100644 --- a/servers/physics_2d/constraint_2d_sw.h +++ b/servers/physics_2d/constraint_2d_sw.h @@ -45,7 +45,7 @@ class Constraint2DSW { RID self; protected: - Constraint2DSW(Body2DSW **p_body_ptr = NULL, int p_body_count = 0) { + Constraint2DSW(Body2DSW **p_body_ptr = nullptr, int p_body_count = 0) { _body_ptr = p_body_ptr; _body_count = p_body_count; island_step = 0; diff --git a/servers/physics_2d/joints_2d_sw.h b/servers/physics_2d/joints_2d_sw.h index f4aeb6e3c8..a0d25dc70d 100644 --- a/servers/physics_2d/joints_2d_sw.h +++ b/servers/physics_2d/joints_2d_sw.h @@ -51,7 +51,7 @@ public: _FORCE_INLINE_ real_t get_max_bias() const { return max_bias; } virtual PhysicsServer2D::JointType get_type() const = 0; - Joint2DSW(Body2DSW **p_body_ptr = NULL, int p_body_count = 0) : + Joint2DSW(Body2DSW **p_body_ptr = nullptr, int p_body_count = 0) : Constraint2DSW(p_body_ptr, p_body_count) { bias = 0; max_force = max_bias = 3.40282e+38; @@ -86,7 +86,7 @@ public: void set_param(PhysicsServer2D::PinJointParam p_param, real_t p_value); real_t get_param(PhysicsServer2D::PinJointParam p_param) const; - PinJoint2DSW(const Vector2 &p_pos, Body2DSW *p_body_a, Body2DSW *p_body_b = NULL); + PinJoint2DSW(const Vector2 &p_pos, Body2DSW *p_body_a, Body2DSW *p_body_b = nullptr); ~PinJoint2DSW(); }; diff --git a/servers/physics_2d/physics_server_2d_sw.cpp b/servers/physics_2d/physics_server_2d_sw.cpp index e2a482e960..871e2aba1d 100644 --- a/servers/physics_2d/physics_server_2d_sw.cpp +++ b/servers/physics_2d/physics_server_2d_sw.cpp @@ -42,7 +42,7 @@ RID PhysicsServer2DSW::_shape_create(ShapeType p_shape) { - Shape2DSW *shape = NULL; + Shape2DSW *shape = nullptr; switch (p_shape) { case SHAPE_LINE: { @@ -227,7 +227,7 @@ bool PhysicsServer2DSW::shape_collide(RID p_shape_A, const Transform2D &p_xform_ if (p_result_max == 0) { - return CollisionSolver2DSW::solve(shape_A, p_xform_A, p_motion_A, shape_B, p_xform_B, p_motion_B, NULL, NULL); + return CollisionSolver2DSW::solve(shape_A, p_xform_A, p_motion_A, shape_B, p_xform_B, p_motion_B, nullptr, nullptr); } CollCbkData cbk; @@ -313,8 +313,8 @@ int PhysicsServer2DSW::space_get_contact_count(RID p_space) const { PhysicsDirectSpaceState2D *PhysicsServer2DSW::space_get_direct_state(RID p_space) { Space2DSW *space = space_owner.getornull(p_space); - ERR_FAIL_COND_V(!space, NULL); - ERR_FAIL_COND_V_MSG((using_threads && !doing_sync) || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_COND_V(!space, nullptr); + ERR_FAIL_COND_V_MSG((using_threads && !doing_sync) || space->is_locked(), nullptr, "Space state is inaccessible right now, wait for iteration or physics process notification."); return space->get_direct_state(); } @@ -332,7 +332,7 @@ void PhysicsServer2DSW::area_set_space(RID p_area, RID p_space) { Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - Space2DSW *space = NULL; + Space2DSW *space = nullptr; if (p_space.is_valid()) { space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); @@ -596,7 +596,7 @@ void PhysicsServer2DSW::body_set_space(RID p_body, RID p_space) { Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); - Space2DSW *space = NULL; + Space2DSW *space = nullptr; if (p_space.is_valid()) { space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); @@ -1069,15 +1069,15 @@ int PhysicsServer2DSW::body_test_ray_separation(RID p_body, const Transform2D &p PhysicsDirectBodyState2D *PhysicsServer2DSW::body_get_direct_state(RID p_body) { - ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification."); if (!body_owner.owns(p_body)) - return NULL; + return nullptr; Body2DSW *body = body_owner.getornull(p_body); - ERR_FAIL_COND_V(!body, NULL); - ERR_FAIL_COND_V(!body->get_space(), NULL); - ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_COND_V(!body, nullptr); + ERR_FAIL_COND_V(!body->get_space(), nullptr); + ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification."); direct_state->body = body; return direct_state; @@ -1142,7 +1142,7 @@ RID PhysicsServer2DSW::pin_joint_create(const Vector2 &p_pos, RID p_body_a, RID Body2DSW *A = body_owner.getornull(p_body_a); ERR_FAIL_COND_V(!A, RID()); - Body2DSW *B = NULL; + Body2DSW *B = nullptr; if (body_owner.owns(p_body_b)) { B = body_owner.getornull(p_body_b); ERR_FAIL_COND_V(!B, RID()); @@ -1276,7 +1276,7 @@ void PhysicsServer2DSW::free(RID p_rid) { _clear_query(area->get_monitor_query()); */ - area->set_space(NULL); + area->set_space(nullptr); while (area->get_shape_count()) { @@ -1291,7 +1291,7 @@ void PhysicsServer2DSW::free(RID p_rid) { while (space->get_objects().size()) { CollisionObject2DSW *co = (CollisionObject2DSW *)space->get_objects().front()->get(); - co->set_space(NULL); + co->set_space(nullptr); } active_spaces.erase(space); @@ -1444,7 +1444,7 @@ int PhysicsServer2DSW::get_process_info(ProcessInfo p_info) { return 0; } -PhysicsServer2DSW *PhysicsServer2DSW::singletonsw = NULL; +PhysicsServer2DSW *PhysicsServer2DSW::singletonsw = nullptr; PhysicsServer2DSW::PhysicsServer2DSW() { diff --git a/servers/physics_2d/physics_server_2d_sw.h b/servers/physics_2d/physics_server_2d_sw.h index 9dfa8bf474..918958ffe2 100644 --- a/servers/physics_2d/physics_server_2d_sw.h +++ b/servers/physics_2d/physics_server_2d_sw.h @@ -249,7 +249,7 @@ public: virtual void body_set_pickable(RID p_body, bool p_pickable); - virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true); + virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true); virtual int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001); // this function only works on physics process, errors and returns null otherwise diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.cpp b/servers/physics_2d/physics_server_2d_wrap_mt.cpp index 5f65e296fd..0a89a76615 100644 --- a/servers/physics_2d/physics_server_2d_wrap_mt.cpp +++ b/servers/physics_2d/physics_server_2d_wrap_mt.cpp @@ -126,7 +126,7 @@ void PhysicsServer2DWrapMT::finish() { Thread::wait_to_finish(thread); memdelete(thread); - thread = NULL; + thread = nullptr; } else { physics_2d_server->finish(); } @@ -150,7 +150,7 @@ PhysicsServer2DWrapMT::PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool physics_2d_server = p_contained; create_thread = p_create_thread; - thread = NULL; + thread = nullptr; step_pending = 0; step_thread_up = false; diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.h b/servers/physics_2d/physics_server_2d_wrap_mt.h index ffd46feebd..7e61927378 100644 --- a/servers/physics_2d/physics_server_2d_wrap_mt.h +++ b/servers/physics_2d/physics_server_2d_wrap_mt.h @@ -112,7 +112,7 @@ public: // this function only works on physics process, errors and returns null otherwise PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) { - ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), NULL); + ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), nullptr); return physics_2d_server->space_get_direct_state(p_space); } @@ -255,7 +255,7 @@ public: FUNC2(body_set_pickable, RID, bool); - bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true) { + bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes); @@ -270,7 +270,7 @@ public: // this function only works on physics process, errors and returns null otherwise PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) { - ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), NULL); + ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), nullptr); return physics_2d_server->body_get_direct_state(p_body); } diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 5fefb9595f..06096d674a 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -643,7 +643,7 @@ void ConvexPolygonShape2DSW::set_data(const Variant &p_data) { if (points) memdelete_arr(points); - points = NULL; + points = nullptr; point_count = 0; if (p_data.get_type() == Variant::PACKED_VECTOR2_ARRAY) { @@ -706,7 +706,7 @@ Variant ConvexPolygonShape2DSW::get_data() const { ConvexPolygonShape2DSW::ConvexPolygonShape2DSW() { - points = NULL; + points = nullptr; point_count = 0; } diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index cba190995f..7ae2e9769f 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -222,7 +222,7 @@ int PhysicsDirectSpaceState2DSW::intersect_shape(const RID &p_shape, const Trans const CollisionObject2DSW *col_obj = space->intersection_query_results[i]; int shape_idx = space->intersection_query_subindex_results[i]; - if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), NULL, NULL, NULL, p_margin)) + if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), nullptr, nullptr, nullptr, p_margin)) continue; r_results[cc].collider_id = col_obj->get_instance_id(); @@ -265,12 +265,12 @@ bool PhysicsDirectSpaceState2DSW::cast_motion(const RID &p_shape, const Transfor Transform2D col_obj_xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx); //test initial overlap, does it collide if going all the way? - if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), NULL, NULL, NULL, p_margin)) { + if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), nullptr, nullptr, nullptr, p_margin)) { continue; } //test initial overlap - if (CollisionSolver2DSW::solve(shape, p_xform, Vector2(), col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), NULL, NULL, NULL, p_margin)) { + if (CollisionSolver2DSW::solve(shape, p_xform, Vector2(), col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), nullptr, nullptr, nullptr, p_margin)) { return false; } @@ -285,7 +285,7 @@ bool PhysicsDirectSpaceState2DSW::cast_motion(const RID &p_shape, const Transfor real_t ofs = (low + hi) * 0.5; Vector2 sep = mnormal; //important optimization for this to work fast enough - bool collided = CollisionSolver2DSW::solve(shape, p_xform, p_motion * ofs, col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), NULL, NULL, &sep, p_margin); + bool collided = CollisionSolver2DSW::solve(shape, p_xform, p_motion * ofs, col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), nullptr, nullptr, &sep, p_margin); if (collided) { @@ -348,7 +348,7 @@ bool PhysicsDirectSpaceState2DSW::collide_shape(RID p_shape, const Transform2D & cbk.valid_dir = Vector2(); cbk.valid_depth = 0; - if (CollisionSolver2DSW::solve(shape, p_shape_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), cbkres, cbkptr, NULL, p_margin)) { + if (CollisionSolver2DSW::solve(shape, p_shape_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), cbkres, cbkptr, nullptr, p_margin)) { collided = cbk.amount > 0; } } @@ -415,7 +415,7 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh _RestCallbackData2D rcd; rcd.best_len = 0; - rcd.best_object = NULL; + rcd.best_object = nullptr; rcd.best_shape = 0; rcd.min_allowed_depth = space->test_motion_min_contact_depth; @@ -435,7 +435,7 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh rcd.object = col_obj; rcd.shape = shape_idx; rcd.local_shape = 0; - bool sc = CollisionSolver2DSW::solve(shape, p_shape_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), _rest_cbk_result, &rcd, NULL, p_margin); + bool sc = CollisionSolver2DSW::solve(shape, p_shape_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), _rest_cbk_result, &rcd, nullptr, p_margin); if (!sc) continue; } @@ -464,7 +464,7 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh PhysicsDirectSpaceState2DSW::PhysicsDirectSpaceState2DSW() { - space = NULL; + space = nullptr; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -613,7 +613,7 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t */ Shape2DSW *against_shape = col_obj->get_shape(shape_idx); - if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), cbkres, cbkptr, NULL, p_margin)) { + if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), cbkres, cbkptr, nullptr, p_margin)) { if (cbk.amount > 0) { collided = true; } @@ -818,7 +818,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co bool did_collide = false; Shape2DSW *against_shape = col_obj->get_shape(shape_idx); - if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), cbkres, cbkptr, NULL, separation_margin)) { + if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), cbkres, cbkptr, nullptr, separation_margin)) { did_collide = cbk.passed > current_passed; //more passed, so collision actually existed } @@ -925,12 +925,12 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co Transform2D col_obj_shape_xform = col_obj->get_transform() * col_obj->get_shape_transform(col_shape_idx); //test initial overlap, does it collide if going all the way? - if (!CollisionSolver2DSW::solve(body_shape, body_shape_xform, p_motion, against_shape, col_obj_shape_xform, Vector2(), NULL, NULL, NULL, 0)) { + if (!CollisionSolver2DSW::solve(body_shape, body_shape_xform, p_motion, against_shape, col_obj_shape_xform, Vector2(), nullptr, nullptr, nullptr, 0)) { continue; } //test initial overlap - if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), NULL, NULL, NULL, 0)) { + if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), nullptr, nullptr, nullptr, 0)) { if (col_obj->is_shape_set_as_one_way_collision(col_shape_idx)) { continue; @@ -950,7 +950,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co real_t ofs = (low + hi) * 0.5; Vector2 sep = mnormal; //important optimization for this to work fast enough - bool collided = CollisionSolver2DSW::solve(body_shape, body_shape_xform, p_motion * ofs, against_shape, col_obj_shape_xform, Vector2(), NULL, NULL, &sep, 0); + bool collided = CollisionSolver2DSW::solve(body_shape, body_shape_xform, p_motion * ofs, against_shape, col_obj_shape_xform, Vector2(), nullptr, nullptr, &sep, 0); if (collided) { @@ -1018,7 +1018,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co _RestCallbackData2D rcd; rcd.best_len = 0; - rcd.best_object = NULL; + rcd.best_object = nullptr; rcd.best_shape = 0; rcd.min_allowed_depth = test_motion_min_contact_depth; @@ -1081,7 +1081,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co rcd.object = col_obj; rcd.shape = shape_idx; rcd.local_shape = j; - bool sc = CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), _rest_cbk_result, &rcd, NULL, p_margin); + bool sc = CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), _rest_cbk_result, &rcd, nullptr, p_margin); if (!sc) continue; } @@ -1156,7 +1156,7 @@ void *Space2DSW::_broadphase_pair(CollisionObject2DSW *A, int p_subindex_A, Coll return b; } - return NULL; + return nullptr; } void Space2DSW::_broadphase_unpair(CollisionObject2DSW *A, int p_subindex_A, CollisionObject2DSW *B, int p_subindex_B, void *p_data, void *p_self) { @@ -1351,7 +1351,7 @@ Space2DSW::Space2DSW() { broadphase = BroadPhase2DSW::create_func(); broadphase->set_pair_callback(_broadphase_pair, this); broadphase->set_unpair_callback(_broadphase_unpair, this); - area = NULL; + area = nullptr; direct_access = memnew(PhysicsDirectSpaceState2DSW); direct_access->space = this; diff --git a/servers/physics_2d/step_2d_sw.cpp b/servers/physics_2d/step_2d_sw.cpp index 198fccdb80..6f3bcfec13 100644 --- a/servers/physics_2d/step_2d_sw.cpp +++ b/servers/physics_2d/step_2d_sw.cpp @@ -60,7 +60,7 @@ void Step2DSW::_populate_island(Body2DSW *p_body, Body2DSW **p_island, Constrain bool Step2DSW::_setup_island(Constraint2DSW *p_island, real_t p_delta) { Constraint2DSW *ci = p_island; - Constraint2DSW *prev_ci = NULL; + Constraint2DSW *prev_ci = nullptr; bool removed_root = false; while (ci) { bool process = ci->setup(p_delta); @@ -164,8 +164,8 @@ void Step2DSW::step(Space2DSW *p_space, real_t p_delta, int p_iterations) { /* GENERATE CONSTRAINT ISLANDS */ - Body2DSW *island_list = NULL; - Constraint2DSW *constraint_island_list = NULL; + Body2DSW *island_list = nullptr; + Constraint2DSW *constraint_island_list = nullptr; b = body_list->first(); int island_count = 0; @@ -175,8 +175,8 @@ void Step2DSW::step(Space2DSW *p_space, real_t p_delta, int p_iterations) { if (body->get_island_step() != _step) { - Body2DSW *island = NULL; - Constraint2DSW *constraint_island = NULL; + Body2DSW *island = nullptr; + Constraint2DSW *constraint_island = nullptr; _populate_island(body, &island, &constraint_island); island->set_island_list_next(island_list); @@ -202,7 +202,7 @@ void Step2DSW::step(Space2DSW *p_space, real_t p_delta, int p_iterations) { if (c->get_island_step() == _step) continue; c->set_island_step(_step); - c->set_island_next(NULL); + c->set_island_next(nullptr); c->set_island_list_next(constraint_island_list); constraint_island_list = c; } @@ -219,7 +219,7 @@ void Step2DSW::step(Space2DSW *p_space, real_t p_delta, int p_iterations) { { Constraint2DSW *ci = constraint_island_list; - Constraint2DSW *prev_ci = NULL; + Constraint2DSW *prev_ci = nullptr; while (ci) { if (_setup_island(ci, p_delta)) { diff --git a/servers/physics_3d/area_pair_3d_sw.cpp b/servers/physics_3d/area_pair_3d_sw.cpp index e92a3a0dd1..fa2fb2dabb 100644 --- a/servers/physics_3d/area_pair_3d_sw.cpp +++ b/servers/physics_3d/area_pair_3d_sw.cpp @@ -37,7 +37,7 @@ bool AreaPair3DSW::setup(real_t p_step) { if (area->is_shape_set_as_disabled(area_shape) || body->is_shape_set_as_disabled(body_shape)) { result = false; - } else if (area->test_collision_mask(body) && CollisionSolver3DSW::solve_static(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), NULL, this)) { + } else if (area->test_collision_mask(body) && CollisionSolver3DSW::solve_static(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), nullptr, this)) { result = true; } @@ -100,7 +100,7 @@ bool Area2Pair3DSW::setup(real_t p_step) { bool result = false; if (area_a->is_shape_set_as_disabled(shape_a) || area_b->is_shape_set_as_disabled(shape_b)) { result = false; - } else if (area_a->test_collision_mask(area_b) && CollisionSolver3DSW::solve_static(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), NULL, this)) { + } else if (area_a->test_collision_mask(area_b) && CollisionSolver3DSW::solve_static(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), nullptr, this)) { result = true; } diff --git a/servers/physics_3d/body_3d_sw.cpp b/servers/physics_3d/body_3d_sw.cpp index 6a00e4f471..fea5aed6ad 100644 --- a/servers/physics_3d/body_3d_sw.cpp +++ b/servers/physics_3d/body_3d_sw.cpp @@ -569,7 +569,7 @@ void Body3DSW::integrate_forces(real_t p_step) { _update_shapes_with_motion(motion); } - def_area = NULL; // clear the area, so it is set in the next frame + def_area = nullptr; // clear the area, so it is set in the next frame contact_count = 0; } @@ -746,7 +746,7 @@ void Body3DSW::set_force_integration_callback(ObjectID p_id, const StringName &p if (fi_callback) { memdelete(fi_callback); - fi_callback = NULL; + fi_callback = nullptr; } if (p_id.is_valid()) { @@ -781,8 +781,8 @@ Body3DSW::Body3DSW() : omit_force_integration = false; //applied_torque=0; island_step = 0; - island_next = NULL; - island_list_next = NULL; + island_next = nullptr; + island_list_next = nullptr; first_time_kinematic = false; first_integration = false; _set_static(false); @@ -797,7 +797,7 @@ Body3DSW::Body3DSW() : still_time = 0; continuous_cd = false; can_sleep = true; - fi_callback = NULL; + fi_callback = nullptr; } Body3DSW::~Body3DSW() { @@ -806,7 +806,7 @@ Body3DSW::~Body3DSW() { memdelete(fi_callback); } -PhysicsDirectBodyState3DSW *PhysicsDirectBodyState3DSW::singleton = NULL; +PhysicsDirectBodyState3DSW *PhysicsDirectBodyState3DSW::singleton = nullptr; PhysicsDirectSpaceState3D *PhysicsDirectBodyState3DSW::get_space_state() { diff --git a/servers/physics_3d/body_3d_sw.h b/servers/physics_3d/body_3d_sw.h index 368dd59b06..b553cf0670 100644 --- a/servers/physics_3d/body_3d_sw.h +++ b/servers/physics_3d/body_3d_sw.h @@ -468,7 +468,7 @@ public: virtual real_t get_step() const { return step; } PhysicsDirectBodyState3DSW() { singleton = this; - body = NULL; + body = nullptr; } }; diff --git a/servers/physics_3d/broad_phase_3d_basic.cpp b/servers/physics_3d/broad_phase_3d_basic.cpp index bea87a45ca..08ea219869 100644 --- a/servers/physics_3d/broad_phase_3d_basic.cpp +++ b/servers/physics_3d/broad_phase_3d_basic.cpp @@ -34,7 +34,7 @@ BroadPhase3DSW::ID BroadPhase3DBasic::create(CollisionObject3DSW *p_object, int p_subindex) { - ERR_FAIL_COND_V(p_object == NULL, 0); + ERR_FAIL_COND_V(p_object == nullptr, 0); current++; @@ -88,7 +88,7 @@ void BroadPhase3DBasic::remove(ID p_id) { CollisionObject3DSW *BroadPhase3DBasic::get_object(ID p_id) const { const Map<ID, Element>::Element *E = element_map.find(p_id); - ERR_FAIL_COND_V(!E, NULL); + ERR_FAIL_COND_V(!E, nullptr); return E->get().owner; } bool BroadPhase3DBasic::is_static(ID p_id) const { @@ -201,7 +201,7 @@ void BroadPhase3DBasic::update() { if (pair_ok && !E) { - void *data = NULL; + void *data = nullptr; if (pair_callback) data = pair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, unpair_userdata); pair_map.insert(key, data); @@ -218,8 +218,8 @@ BroadPhase3DSW *BroadPhase3DBasic::_create() { BroadPhase3DBasic::BroadPhase3DBasic() { current = 1; - unpair_callback = NULL; - unpair_userdata = NULL; - pair_callback = NULL; - pair_userdata = NULL; + unpair_callback = nullptr; + unpair_userdata = nullptr; + pair_callback = nullptr; + pair_userdata = nullptr; } diff --git a/servers/physics_3d/broad_phase_3d_basic.h b/servers/physics_3d/broad_phase_3d_basic.h index 9b20b7619a..563dda6931 100644 --- a/servers/physics_3d/broad_phase_3d_basic.h +++ b/servers/physics_3d/broad_phase_3d_basic.h @@ -92,9 +92,9 @@ public: virtual bool is_static(ID p_id) const; virtual int get_subindex(ID p_id) const; - virtual int cull_point(const Vector3 &p_point, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL); - virtual int cull_segment(const Vector3 &p_from, const Vector3 &p_to, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL); - virtual int cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL); + virtual int cull_point(const Vector3 &p_point, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr); + virtual int cull_segment(const Vector3 &p_from, const Vector3 &p_to, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr); + virtual int cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr); virtual void set_pair_callback(PairCallback p_pair_callback, void *p_userdata); virtual void set_unpair_callback(UnpairCallback p_unpair_callback, void *p_userdata); diff --git a/servers/physics_3d/broad_phase_3d_sw.cpp b/servers/physics_3d/broad_phase_3d_sw.cpp index 5e367a7736..1a20fdd0cb 100644 --- a/servers/physics_3d/broad_phase_3d_sw.cpp +++ b/servers/physics_3d/broad_phase_3d_sw.cpp @@ -30,7 +30,7 @@ #include "broad_phase_3d_sw.h" -BroadPhase3DSW::CreateFunction BroadPhase3DSW::create_func = NULL; +BroadPhase3DSW::CreateFunction BroadPhase3DSW::create_func = nullptr; BroadPhase3DSW::~BroadPhase3DSW() { } diff --git a/servers/physics_3d/broad_phase_3d_sw.h b/servers/physics_3d/broad_phase_3d_sw.h index 47d09a8b1d..5950489619 100644 --- a/servers/physics_3d/broad_phase_3d_sw.h +++ b/servers/physics_3d/broad_phase_3d_sw.h @@ -58,9 +58,9 @@ public: virtual bool is_static(ID p_id) const = 0; virtual int get_subindex(ID p_id) const = 0; - virtual int cull_point(const Vector3 &p_point, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL) = 0; - virtual int cull_segment(const Vector3 &p_from, const Vector3 &p_to, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL) = 0; - virtual int cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL) = 0; + virtual int cull_point(const Vector3 &p_point, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr) = 0; + virtual int cull_segment(const Vector3 &p_from, const Vector3 &p_to, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr) = 0; + virtual int cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr) = 0; virtual void set_pair_callback(PairCallback p_pair_callback, void *p_userdata) = 0; virtual void set_unpair_callback(UnpairCallback p_unpair_callback, void *p_userdata) = 0; diff --git a/servers/physics_3d/broad_phase_octree.cpp b/servers/physics_3d/broad_phase_octree.cpp index 50ac17e027..264ab21e1e 100644 --- a/servers/physics_3d/broad_phase_octree.cpp +++ b/servers/physics_3d/broad_phase_octree.cpp @@ -55,7 +55,7 @@ void BroadPhaseOctree::remove(ID p_id) { CollisionObject3DSW *BroadPhaseOctree::get_object(ID p_id) const { CollisionObject3DSW *it = octree.get(p_id); - ERR_FAIL_COND_V(!it, NULL); + ERR_FAIL_COND_V(!it, nullptr); return it; } bool BroadPhaseOctree::is_static(ID p_id) const { @@ -86,7 +86,7 @@ void *BroadPhaseOctree::_pair_callback(void *self, OctreeElementID p_A, Collisio BroadPhaseOctree *bpo = (BroadPhaseOctree *)(self); if (!bpo->pair_callback) - return NULL; + return nullptr; return bpo->pair_callback(p_object_A, subindex_A, p_object_B, subindex_B, bpo->pair_userdata); } @@ -123,7 +123,7 @@ BroadPhase3DSW *BroadPhaseOctree::_create() { BroadPhaseOctree::BroadPhaseOctree() { octree.set_pair_callback(_pair_callback, this); octree.set_unpair_callback(_unpair_callback, this); - pair_callback = NULL; - pair_userdata = NULL; - unpair_userdata = NULL; + pair_callback = nullptr; + pair_userdata = nullptr; + unpair_userdata = nullptr; } diff --git a/servers/physics_3d/broad_phase_octree.h b/servers/physics_3d/broad_phase_octree.h index 25cf5b32da..0ad59d8b0c 100644 --- a/servers/physics_3d/broad_phase_octree.h +++ b/servers/physics_3d/broad_phase_octree.h @@ -57,9 +57,9 @@ public: virtual bool is_static(ID p_id) const; virtual int get_subindex(ID p_id) const; - virtual int cull_point(const Vector3 &p_point, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL); - virtual int cull_segment(const Vector3 &p_from, const Vector3 &p_to, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL); - virtual int cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = NULL); + virtual int cull_point(const Vector3 &p_point, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr); + virtual int cull_segment(const Vector3 &p_from, const Vector3 &p_to, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr); + virtual int cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_results, int p_max_results, int *p_result_indices = nullptr); virtual void set_pair_callback(PairCallback p_pair_callback, void *p_userdata); virtual void set_unpair_callback(UnpairCallback p_unpair_callback, void *p_userdata); diff --git a/servers/physics_3d/collision_object_3d_sw.cpp b/servers/physics_3d/collision_object_3d_sw.cpp index ba13d70e4f..24715d211d 100644 --- a/servers/physics_3d/collision_object_3d_sw.cpp +++ b/servers/physics_3d/collision_object_3d_sw.cpp @@ -231,7 +231,7 @@ CollisionObject3DSW::CollisionObject3DSW(Type p_type) : _static = true; type = p_type; - space = NULL; + space = nullptr; collision_layer = 1; collision_mask = 1; diff --git a/servers/physics_3d/collision_solver_3d_sat.cpp b/servers/physics_3d/collision_solver_3d_sat.cpp index 0a7a9caf91..5096b080ab 100644 --- a/servers/physics_3d/collision_solver_3d_sat.cpp +++ b/servers/physics_3d/collision_solver_3d_sat.cpp @@ -241,13 +241,13 @@ static void _generate_contacts_from_supports(const Vector3 *p_points_A, int p_po _generate_contacts_point_face, }, { - 0, + nullptr, _generate_contacts_edge_edge, _generate_contacts_face_face, }, { - 0, - 0, + nullptr, + nullptr, _generate_contacts_face_face, } }; @@ -1483,36 +1483,36 @@ bool sat_calculate_penetration(const Shape3DSW *p_shape_A, const Transform &p_tr _collision_sphere_cylinder<false>, _collision_sphere_convex_polygon<false>, _collision_sphere_face<false> }, - { 0, + { nullptr, _collision_box_box<false>, _collision_box_capsule<false>, _collision_box_cylinder<false>, _collision_box_convex_polygon<false>, _collision_box_face<false> }, - { 0, - 0, + { nullptr, + nullptr, _collision_capsule_capsule<false>, _collision_capsule_cylinder<false>, _collision_capsule_convex_polygon<false>, _collision_capsule_face<false> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_cylinder_cylinder<false>, _collision_cylinder_convex_polygon<false>, _collision_cylinder_face<false> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<false>, _collision_convex_polygon_face<false> }, - { 0, - 0, - 0, - 0, - 0, - 0 }, + { nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr }, }; static const CollisionFunc collision_table_margin[6][6] = { @@ -1522,36 +1522,36 @@ bool sat_calculate_penetration(const Shape3DSW *p_shape_A, const Transform &p_tr _collision_sphere_cylinder<true>, _collision_sphere_convex_polygon<true>, _collision_sphere_face<true> }, - { 0, + { nullptr, _collision_box_box<true>, _collision_box_capsule<true>, _collision_box_cylinder<true>, _collision_box_convex_polygon<true>, _collision_box_face<true> }, - { 0, - 0, + { nullptr, + nullptr, _collision_capsule_capsule<true>, _collision_capsule_cylinder<true>, _collision_capsule_convex_polygon<true>, _collision_capsule_face<true> }, - { 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, _collision_cylinder_cylinder<true>, _collision_cylinder_convex_polygon<true>, _collision_cylinder_face<true> }, - { 0, - 0, - 0, - 0, + { nullptr, + nullptr, + nullptr, + nullptr, _collision_convex_polygon_convex_polygon<true>, _collision_convex_polygon_face<true> }, - { 0, - 0, - 0, - 0, - 0, - 0 }, + { nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr }, }; _CollectorCallback callback; diff --git a/servers/physics_3d/collision_solver_3d_sat.h b/servers/physics_3d/collision_solver_3d_sat.h index c8ffd8e660..5eccfda9ac 100644 --- a/servers/physics_3d/collision_solver_3d_sat.h +++ b/servers/physics_3d/collision_solver_3d_sat.h @@ -33,6 +33,6 @@ #include "collision_solver_3d_sw.h" -bool sat_calculate_penetration(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, CollisionSolver3DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap = false, Vector3 *r_prev_axis = NULL, real_t p_margin_a = 0, real_t p_margin_b = 0); +bool sat_calculate_penetration(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, CollisionSolver3DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap = false, Vector3 *r_prev_axis = nullptr, real_t p_margin_a = 0, real_t p_margin_b = 0); #endif // COLLISION_SOLVER_SAT_H diff --git a/servers/physics_3d/collision_solver_3d_sw.cpp b/servers/physics_3d/collision_solver_3d_sw.cpp index 26de49c96f..5d31e1f546 100644 --- a/servers/physics_3d/collision_solver_3d_sw.cpp +++ b/servers/physics_3d/collision_solver_3d_sw.cpp @@ -125,7 +125,7 @@ void CollisionSolver3DSW::concave_callback(void *p_userdata, Shape3DSW *p_convex _ConcaveCollisionInfo &cinfo = *(_ConcaveCollisionInfo *)(p_userdata); cinfo.aabb_tests++; - bool collided = collision_solver(cinfo.shape_A, *cinfo.transform_A, p_convex, *cinfo.transform_B, cinfo.result_callback, cinfo.userdata, cinfo.swap_result, NULL, cinfo.margin_A, cinfo.margin_B); + bool collided = collision_solver(cinfo.shape_A, *cinfo.transform_A, p_convex, *cinfo.transform_B, cinfo.result_callback, cinfo.userdata, cinfo.swap_result, nullptr, cinfo.margin_A, cinfo.margin_B); if (!collided) return; @@ -316,8 +316,8 @@ bool CollisionSolver3DSW::solve_distance(const Shape3DSW *p_shape_A, const Trans cinfo.transform_A = &p_transform_A; cinfo.shape_A = p_shape_A; cinfo.transform_B = &p_transform_B; - cinfo.result_callback = NULL; - cinfo.userdata = NULL; + cinfo.result_callback = nullptr; + cinfo.userdata = nullptr; cinfo.swap_result = false; cinfo.collided = false; cinfo.collisions = 0; diff --git a/servers/physics_3d/collision_solver_3d_sw.h b/servers/physics_3d/collision_solver_3d_sw.h index ec76a4217e..13f54ca8fb 100644 --- a/servers/physics_3d/collision_solver_3d_sw.h +++ b/servers/physics_3d/collision_solver_3d_sw.h @@ -46,8 +46,8 @@ private: static bool solve_distance_plane(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B); public: - static bool solve_static(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, CallbackResult p_result_callback, void *p_userdata, Vector3 *r_sep_axis = NULL, real_t p_margin_A = 0, real_t p_margin_B = 0); - static bool solve_distance(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B, const AABB &p_concave_hint, Vector3 *r_sep_axis = NULL); + static bool solve_static(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, CallbackResult p_result_callback, void *p_userdata, Vector3 *r_sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0); + static bool solve_distance(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B, const AABB &p_concave_hint, Vector3 *r_sep_axis = nullptr); }; #endif // COLLISION_SOLVER__SW_H diff --git a/servers/physics_3d/constraint_3d_sw.h b/servers/physics_3d/constraint_3d_sw.h index b9d3ac4f12..5e2b00404b 100644 --- a/servers/physics_3d/constraint_3d_sw.h +++ b/servers/physics_3d/constraint_3d_sw.h @@ -46,7 +46,7 @@ class Constraint3DSW { RID self; protected: - Constraint3DSW(Body3DSW **p_body_ptr = NULL, int p_body_count = 0) { + Constraint3DSW(Body3DSW **p_body_ptr = nullptr, int p_body_count = 0) { _body_ptr = p_body_ptr; _body_count = p_body_count; island_step = 0; diff --git a/servers/physics_3d/gjk_epa.cpp b/servers/physics_3d/gjk_epa.cpp index bd0d429e7b..db37f261ce 100644 --- a/servers/physics_3d/gjk_epa.cpp +++ b/servers/physics_3d/gjk_epa.cpp @@ -515,14 +515,14 @@ struct GJK { sFace* root; U count; - sList() : root(0),count(0) {} + sList() : root(nullptr),count(0) {} }; struct sHorizon { sFace* cf; sFace* ff; U nf; - sHorizon() : cf(0),ff(0),nf(0) {} + sHorizon() : cf(nullptr),ff(nullptr),nf(0) {} }; struct eStatus { enum _ { Valid, @@ -559,7 +559,7 @@ struct GJK } static inline void append(sList& list,sFace* face) { - face->l[0] = 0; + face->l[0] = nullptr; face->l[1] = list.root; if(list.root) list.root->l[0]=face; list.root = face; @@ -720,13 +720,13 @@ struct GJK } else m_status=eStatus::Degenerated; remove(m_hull,face); append(m_stock,face); - return(0); + return(nullptr); } // -- GODOT start -- //m_status=m_stock.root?eStatus::OutOfVertices:eStatus::OutOfFaces; m_status=eStatus::OutOfFaces; // -- GODOT end -- - return(0); + return(nullptr); } sFace* findbest() { diff --git a/servers/physics_3d/joints_3d_sw.h b/servers/physics_3d/joints_3d_sw.h index 435ee2301d..0f2d4892a8 100644 --- a/servers/physics_3d/joints_3d_sw.h +++ b/servers/physics_3d/joints_3d_sw.h @@ -38,7 +38,7 @@ class Joint3DSW : public Constraint3DSW { public: virtual PhysicsServer3D::JointType get_type() const = 0; - _FORCE_INLINE_ Joint3DSW(Body3DSW **p_body_ptr = NULL, int p_body_count = 0) : + _FORCE_INLINE_ Joint3DSW(Body3DSW **p_body_ptr = nullptr, int p_body_count = 0) : Constraint3DSW(p_body_ptr, p_body_count) { } }; diff --git a/servers/physics_3d/physics_server_3d_sw.cpp b/servers/physics_3d/physics_server_3d_sw.cpp index da84630088..bc42c2fd9e 100644 --- a/servers/physics_3d/physics_server_3d_sw.cpp +++ b/servers/physics_3d/physics_server_3d_sw.cpp @@ -45,7 +45,7 @@ RID PhysicsServer3DSW::shape_create(ShapeType p_shape) { - Shape3DSW *shape = NULL; + Shape3DSW *shape = nullptr; switch (p_shape) { case SHAPE_PLANE: { @@ -70,7 +70,7 @@ RID PhysicsServer3DSW::shape_create(ShapeType p_shape) { } break; case SHAPE_CYLINDER: { - ERR_FAIL_V_MSG(RID(), "CylinderShape is not supported in GodotPhysics. Please switch to Bullet in the Project Settings."); + ERR_FAIL_V_MSG(RID(), "CylinderShape3D is not supported in GodotPhysics. Please switch to Bullet in the Project Settings."); } break; case SHAPE_CONVEX_POLYGON: { @@ -195,8 +195,8 @@ real_t PhysicsServer3DSW::space_get_param(RID p_space, SpaceParameter p_param) c PhysicsDirectSpaceState3D *PhysicsServer3DSW::space_get_direct_state(RID p_space) { Space3DSW *space = space_owner.getornull(p_space); - ERR_FAIL_COND_V(!space, NULL); - ERR_FAIL_COND_V_MSG(!doing_sync || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_COND_V(!space, nullptr); + ERR_FAIL_COND_V_MSG(!doing_sync || space->is_locked(), nullptr, "Space state is inaccessible right now, wait for iteration or physics process notification."); return space->get_direct_state(); } @@ -235,7 +235,7 @@ void PhysicsServer3DSW::area_set_space(RID p_area, RID p_space) { Area3DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - Space3DSW *space = NULL; + Space3DSW *space = nullptr; if (p_space.is_valid()) { space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); @@ -492,7 +492,7 @@ void PhysicsServer3DSW::body_set_space(RID p_body, RID p_space) { Body3DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); - Space3DSW *space = NULL; + Space3DSW *space = nullptr; if (p_space.is_valid()) { space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); @@ -978,8 +978,8 @@ int PhysicsServer3DSW::body_test_ray_separation(RID p_body, const Transform &p_t PhysicsDirectBodyState3D *PhysicsServer3DSW::body_get_direct_state(RID p_body) { Body3DSW *body = body_owner.getornull(p_body); - ERR_FAIL_COND_V(!body, NULL); - ERR_FAIL_COND_V_MSG(!doing_sync || body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_COND_V(!body, nullptr); + ERR_FAIL_COND_V_MSG(!doing_sync || body->get_space()->is_locked(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification."); direct_state->body = body; return direct_state; @@ -1341,7 +1341,7 @@ void PhysicsServer3DSW::free(RID p_rid) { _clear_query(body->get_direct_state_query()); */ - body->set_space(NULL); + body->set_space(nullptr); while (body->get_shape_count()) { @@ -1360,7 +1360,7 @@ void PhysicsServer3DSW::free(RID p_rid) { _clear_query(area->get_monitor_query()); */ - area->set_space(NULL); + area->set_space(nullptr); while (area->get_shape_count()) { @@ -1375,7 +1375,7 @@ void PhysicsServer3DSW::free(RID p_rid) { while (space->get_objects().size()) { CollisionObject3DSW *co = (CollisionObject3DSW *)space->get_objects().front()->get(); - co->set_space(NULL); + co->set_space(nullptr); } active_spaces.erase(space); @@ -1572,7 +1572,7 @@ void PhysicsServer3DSW::_shape_col_cbk(const Vector3 &p_point_A, const Vector3 & } } -PhysicsServer3DSW *PhysicsServer3DSW::singleton = NULL; +PhysicsServer3DSW *PhysicsServer3DSW::singleton = nullptr; PhysicsServer3DSW::PhysicsServer3DSW() { singleton = this; BroadPhase3DSW::create_func = BroadPhaseOctree::_create; diff --git a/servers/physics_3d/physics_server_3d_sw.h b/servers/physics_3d/physics_server_3d_sw.h index 67123084c1..6e79d9eceb 100644 --- a/servers/physics_3d/physics_server_3d_sw.h +++ b/servers/physics_3d/physics_server_3d_sw.h @@ -237,7 +237,7 @@ public: virtual void body_set_ray_pickable(RID p_body, bool p_enable); virtual bool body_is_ray_pickable(RID p_body) const; - virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true); + virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true); virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001); // this function only works on physics process, errors and returns null otherwise diff --git a/servers/physics_3d/shape_3d_sw.cpp b/servers/physics_3d/shape_3d_sw.cpp index 52253d615a..61c32b779a 100644 --- a/servers/physics_3d/shape_3d_sw.cpp +++ b/servers/physics_3d/shape_3d_sw.cpp @@ -1385,8 +1385,8 @@ _VolumeSW_BVH *_volume_sw_build_bvh(_VolumeSW_BVH_Element *p_elements, int p_siz if (p_size == 1) { //leaf bvh->aabb = p_elements[0].aabb; - bvh->left = NULL; - bvh->right = NULL; + bvh->left = nullptr; + bvh->right = nullptr; bvh->face_index = p_elements->face_index; count++; return bvh; diff --git a/servers/physics_3d/space_3d_sw.cpp b/servers/physics_3d/space_3d_sw.cpp index 9bd507e178..bd8e89a8f5 100644 --- a/servers/physics_3d/space_3d_sw.cpp +++ b/servers/physics_3d/space_3d_sw.cpp @@ -83,7 +83,7 @@ int PhysicsDirectSpaceState3DSW::intersect_point(const Vector3 &p_point, ShapeRe if (r_results[cc].collider_id.is_valid()) r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id); else - r_results[cc].collider = NULL; + r_results[cc].collider = nullptr; r_results[cc].rid = col_obj->get_self(); r_results[cc].shape = shape_idx; @@ -162,7 +162,7 @@ bool PhysicsDirectSpaceState3DSW::intersect_ray(const Vector3 &p_from, const Vec if (r_result.collider_id.is_valid()) r_result.collider = ObjectDB::get_instance(r_result.collider_id); else - r_result.collider = NULL; + r_result.collider = nullptr; r_result.normal = res_normal; r_result.position = res_point; r_result.rid = res_obj->get_self(); @@ -203,7 +203,7 @@ int PhysicsDirectSpaceState3DSW::intersect_shape(const RID &p_shape, const Trans const CollisionObject3DSW *col_obj = space->intersection_query_results[i]; int shape_idx = space->intersection_query_subindex_results[i]; - if (!CollisionSolver3DSW::solve_static(shape, p_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), NULL, NULL, NULL, p_margin, 0)) + if (!CollisionSolver3DSW::solve_static(shape, p_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), nullptr, nullptr, nullptr, p_margin, 0)) continue; if (r_results) { @@ -211,7 +211,7 @@ int PhysicsDirectSpaceState3DSW::intersect_shape(const RID &p_shape, const Trans if (r_results[cc].collider_id.is_valid()) r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id); else - r_results[cc].collider = NULL; + r_results[cc].collider = nullptr; r_results[cc].rid = col_obj->get_self(); r_results[cc].shape = shape_idx; } @@ -364,7 +364,7 @@ bool PhysicsDirectSpaceState3DSW::collide_shape(RID p_shape, const Transform &p_ continue; } - if (CollisionSolver3DSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, NULL, p_margin)) { + if (CollisionSolver3DSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, nullptr, p_margin)) { collided = true; } } @@ -415,7 +415,7 @@ bool PhysicsDirectSpaceState3DSW::rest_info(RID p_shape, const Transform &p_shap _RestCallbackData rcd; rcd.best_len = 0; - rcd.best_object = NULL; + rcd.best_object = nullptr; rcd.best_shape = 0; rcd.min_allowed_depth = space->test_motion_min_contact_depth; @@ -432,7 +432,7 @@ bool PhysicsDirectSpaceState3DSW::rest_info(RID p_shape, const Transform &p_shap rcd.object = col_obj; rcd.shape = shape_idx; - bool sc = CollisionSolver3DSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, NULL, p_margin); + bool sc = CollisionSolver3DSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, nullptr, p_margin); if (!sc) continue; } @@ -501,7 +501,7 @@ Vector3 PhysicsDirectSpaceState3DSW::get_closest_point_to_object_volume(RID p_ob PhysicsDirectSpaceState3DSW::PhysicsDirectSpaceState3DSW() { - space = NULL; + space = nullptr; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -621,7 +621,7 @@ int Space3DSW::test_body_ray_separation(Body3DSW *p_body, const Transform &p_tra } Shape3DSW *against_shape = col_obj->get_shape(shape_idx); - if (CollisionSolver3DSW::solve_static(body_shape, body_shape_xform, against_shape, col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, NULL, p_margin)) { + if (CollisionSolver3DSW::solve_static(body_shape, body_shape_xform, against_shape, col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, nullptr, p_margin)) { if (cbk.amount > 0) { collided = true; } @@ -775,7 +775,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons const CollisionObject3DSW *col_obj = intersection_query_results[i]; int shape_idx = intersection_query_subindex_results[i]; - if (CollisionSolver3DSW::solve_static(body_shape, body_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, NULL, p_margin)) { + if (CollisionSolver3DSW::solve_static(body_shape, body_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, nullptr, p_margin)) { collided = cbk.amount > 0; } } @@ -935,7 +935,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons _RestCallbackData rcd; rcd.best_len = 0; - rcd.best_object = NULL; + rcd.best_object = nullptr; rcd.best_shape = 0; rcd.min_allowed_depth = test_motion_min_contact_depth; @@ -953,7 +953,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons rcd.object = col_obj; rcd.shape = shape_idx; - bool sc = CollisionSolver3DSW::solve_static(body_shape, body_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, NULL, p_margin); + bool sc = CollisionSolver3DSW::solve_static(body_shape, body_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, nullptr, p_margin); if (!sc) continue; } @@ -1030,7 +1030,7 @@ void *Space3DSW::_broadphase_pair(CollisionObject3DSW *A, int p_subindex_A, Coll return b; } - return NULL; + return nullptr; } void Space3DSW::_broadphase_unpair(CollisionObject3DSW *A, int p_subindex_A, CollisionObject3DSW *B, int p_subindex_B, void *p_data, void *p_self) { @@ -1226,7 +1226,7 @@ Space3DSW::Space3DSW() { broadphase = BroadPhase3DSW::create_func(); broadphase->set_pair_callback(_broadphase_pair, this); broadphase->set_unpair_callback(_broadphase_unpair, this); - area = NULL; + area = nullptr; direct_access = memnew(PhysicsDirectSpaceState3DSW); direct_access->space = this; diff --git a/servers/physics_3d/space_3d_sw.h b/servers/physics_3d/space_3d_sw.h index fb4fb6aa1f..3634834952 100644 --- a/servers/physics_3d/space_3d_sw.h +++ b/servers/physics_3d/space_3d_sw.h @@ -51,7 +51,7 @@ public: virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false); virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL); + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = nullptr); virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const; diff --git a/servers/physics_3d/step_3d_sw.cpp b/servers/physics_3d/step_3d_sw.cpp index dda88b45c6..1a7d5f8cec 100644 --- a/servers/physics_3d/step_3d_sw.cpp +++ b/servers/physics_3d/step_3d_sw.cpp @@ -88,7 +88,7 @@ void Step3DSW::_solve_island(Constraint3DSW *p_island, int p_iterations, real_t { Constraint3DSW *ci = p_island; - Constraint3DSW *prev = NULL; + Constraint3DSW *prev = nullptr; while (ci) { if (ci->get_priority() < at_priority) { if (prev) { @@ -177,8 +177,8 @@ void Step3DSW::step(Space3DSW *p_space, real_t p_delta, int p_iterations) { /* GENERATE CONSTRAINT ISLANDS */ - Body3DSW *island_list = NULL; - Constraint3DSW *constraint_island_list = NULL; + Body3DSW *island_list = nullptr; + Constraint3DSW *constraint_island_list = nullptr; b = body_list->first(); int island_count = 0; @@ -188,8 +188,8 @@ void Step3DSW::step(Space3DSW *p_space, real_t p_delta, int p_iterations) { if (body->get_island_step() != _step) { - Body3DSW *island = NULL; - Constraint3DSW *constraint_island = NULL; + Body3DSW *island = nullptr; + Constraint3DSW *constraint_island = nullptr; _populate_island(body, &island, &constraint_island); island->set_island_list_next(island_list); @@ -215,7 +215,7 @@ void Step3DSW::step(Space3DSW *p_space, real_t p_delta, int p_iterations) { if (c->get_island_step() == _step) continue; c->set_island_step(_step); - c->set_island_next(NULL); + c->set_island_next(nullptr); c->set_island_list_next(constraint_island_list); constraint_island_list = c; } diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index 11fa2acc1a..48c51b5350 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -34,7 +34,7 @@ #include "core/print_string.h" #include "core/project_settings.h" -PhysicsServer2D *PhysicsServer2D::singleton = NULL; +PhysicsServer2D *PhysicsServer2D::singleton = nullptr; void PhysicsDirectBodyState2D::integrate_forces() { @@ -531,7 +531,7 @@ PhysicsTestMotionResult2D::PhysicsTestMotionResult2D() { bool PhysicsServer2D::_body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<PhysicsTestMotionResult2D> &p_result) { - MotionResult *r = NULL; + MotionResult *r = nullptr; if (p_result.is_valid()) r = p_result->get_result_ptr(); return body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r); @@ -771,7 +771,7 @@ PhysicsServer2D::PhysicsServer2D() { PhysicsServer2D::~PhysicsServer2D() { - singleton = NULL; + singleton = nullptr; } Vector<PhysicsServer2DManager::ClassInfo> PhysicsServer2DManager::physics_2d_servers; @@ -826,14 +826,14 @@ String PhysicsServer2DManager::get_server_name(int p_id) { } PhysicsServer2D *PhysicsServer2DManager::new_default_server() { - ERR_FAIL_COND_V(default_server_id == -1, NULL); + ERR_FAIL_COND_V(default_server_id == -1, nullptr); return physics_2d_servers[default_server_id].create_callback(); } PhysicsServer2D *PhysicsServer2DManager::new_server(const String &p_name) { int id = find_server_id(p_name); if (id == -1) { - return NULL; + return nullptr; } else { return physics_2d_servers[id].create_callback(); } diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index 632371565c..8c833b390f 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -513,7 +513,7 @@ public: } }; - virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, float p_margin = 0.001, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true) = 0; + virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, float p_margin = 0.001, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) = 0; struct SeparationResult { @@ -644,7 +644,7 @@ class PhysicsServer2DManager { ClassInfo() : name(""), - create_callback(NULL) {} + create_callback(nullptr) {} ClassInfo(String p_name, CreatePhysicsServer2DCallback p_create_callback) : name(p_name), diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index 0ee471231b..a5a02fd1bd 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -34,7 +34,7 @@ #include "core/print_string.h" #include "core/project_settings.h" -PhysicsServer3D *PhysicsServer3D::singleton = NULL; +PhysicsServer3D *PhysicsServer3D::singleton = nullptr; void PhysicsDirectBodyState3D::integrate_forces() { @@ -725,13 +725,13 @@ void PhysicsServer3D::_bind_methods() { PhysicsServer3D::PhysicsServer3D() { - ERR_FAIL_COND(singleton != NULL); + ERR_FAIL_COND(singleton != nullptr); singleton = this; } PhysicsServer3D::~PhysicsServer3D() { - singleton = NULL; + singleton = nullptr; } Vector<PhysicsServer3DManager::ClassInfo> PhysicsServer3DManager::physics_servers; @@ -786,14 +786,14 @@ String PhysicsServer3DManager::get_server_name(int p_id) { } PhysicsServer3D *PhysicsServer3DManager::new_default_server() { - ERR_FAIL_COND_V(default_server_id == -1, NULL); + ERR_FAIL_COND_V(default_server_id == -1, nullptr); return physics_servers[default_server_id].create_callback(); } PhysicsServer3D *PhysicsServer3DManager::new_server(const String &p_name) { int id = find_server_id(p_name); if (id == -1) { - return NULL; + return nullptr; } else { return physics_servers[id].create_callback(); } diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index ddef8a9b20..a2f08b3ed8 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -189,7 +189,7 @@ public: Vector3 linear_velocity; //velocity at contact point }; - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL) = 0; + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = nullptr) = 0; virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; @@ -500,7 +500,7 @@ public: } }; - virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true) = 0; + virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) = 0; struct SeparationResult { @@ -785,7 +785,7 @@ class PhysicsServer3DManager { ClassInfo() : name(""), - create_callback(NULL) {} + create_callback(nullptr) {} ClassInfo(String p_name, CreatePhysicsServer3DCallback p_create_callback) : name(p_name), diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index c53ffcc7b5..64b48bea50 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -68,7 +68,7 @@ #include "rendering_server.h" #include "servers/rendering/shader_types.h" -ShaderTypes *shader_types = NULL; +ShaderTypes *shader_types = nullptr; PhysicsServer3D *_createGodotPhysics3DCallback() { return memnew(PhysicsServer3DSW); @@ -194,10 +194,10 @@ void register_server_singletons() { Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer", NavigationServer3D::get_singleton_mut())); + Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton_mut())); + Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton_mut())); Engine::get_singleton()->add_singleton(Engine::Singleton("ARVRServer", ARVRServer::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton())); } diff --git a/servers/rendering/rasterizer.cpp b/servers/rendering/rasterizer.cpp index a3f93a3f8c..f62e0a43a6 100644 --- a/servers/rendering/rasterizer.cpp +++ b/servers/rendering/rasterizer.cpp @@ -33,7 +33,7 @@ #include "core/os/os.h" #include "core/print_string.h" -Rasterizer *(*Rasterizer::_create_func)() = NULL; +Rasterizer *(*Rasterizer::_create_func)() = nullptr; void RasterizerScene::InstanceDependency::instance_notify_changed(bool p_aabb, bool p_dependencies) { for (Map<InstanceBase *, uint32_t>::Element *E = instances.front(); E; E = E->next()) { @@ -67,9 +67,9 @@ Rasterizer *Rasterizer::create() { return _create_func(); } -RasterizerCanvas *RasterizerCanvas::singleton = NULL; +RasterizerCanvas *RasterizerCanvas::singleton = nullptr; -RasterizerStorage *RasterizerStorage::base_singleton = NULL; +RasterizerStorage *RasterizerStorage::base_singleton = nullptr; RasterizerStorage::RasterizerStorage() { diff --git a/servers/rendering/rasterizer.h b/servers/rendering/rasterizer.h index eb33db04fc..6676b00723 100644 --- a/servers/rendering/rasterizer.h +++ b/servers/rendering/rasterizer.h @@ -79,7 +79,9 @@ public: virtual void environment_glow_set_use_bicubic_upscale(bool p_enable) = 0; virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) = 0; - virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) = 0; + virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) = 0; + virtual void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) = 0; + virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, RS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) = 0; virtual void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size) = 0; @@ -107,7 +109,6 @@ public: struct InstanceBase; struct InstanceDependency { - void instance_notify_changed(bool p_aabb, bool p_dependencies); void instance_notify_deleted(RID p_deleted); @@ -119,7 +120,6 @@ public: }; struct InstanceBase { - RS::InstanceType base_type; RID base; @@ -219,7 +219,7 @@ public: baked_light = false; dynamic_gi = false; redraw_if_visible = false; - lightmap_capture = NULL; + lightmap_capture = nullptr; } virtual ~InstanceBase() { @@ -231,7 +231,9 @@ public: virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) = 0; virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0) = 0; virtual void light_instance_mark_visible(RID p_light_instance) = 0; - virtual bool light_instances_can_render_shadow_cube() const { return true; } + virtual bool light_instances_can_render_shadow_cube() const { + return true; + } virtual RID reflection_atlas_create() = 0; virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) = 0; @@ -751,10 +753,10 @@ public: energy = 1.0; item_shadow_mask = -1; mode = RS::CANVAS_LIGHT_MODE_ADD; - // texture_cache = NULL; - next_ptr = NULL; - mask_next_ptr = NULL; - filter_next_ptr = NULL; + // texture_cache = nullptr; + next_ptr = nullptr; + mask_next_ptr = nullptr; + filter_next_ptr = nullptr; use_shadow = false; shadow_buffer_size = 2048; shadow_filter = RS::CANVAS_LIGHT_FILTER_NONE; @@ -1005,7 +1007,7 @@ public: //must update rect - if (commands == NULL) { + if (commands == nullptr) { rect = Rect2(); rect_dirty = false; @@ -1115,12 +1117,12 @@ public: template <class T> T *alloc_command() { T *command; - if (commands == NULL) { + if (commands == nullptr) { // As the most common use case of canvas items is to // use only one command, the first is done with it's // own allocation. The rest of them use blocks. command = memnew(T); - command->next = NULL; + command->next = nullptr; commands = command; last_command = command; } else { @@ -1147,7 +1149,7 @@ public: //allocate block and add to the linked list void *memory = c->memory + c->usage; command = memnew_placement(memory, T); - command->next = NULL; + command->next = nullptr; last_command->next = command; last_command = command; c->usage += sizeof(T); @@ -1172,7 +1174,7 @@ public: Command *n = c->next; if (c == commands) { memdelete(commands); - commands = NULL; + commands = nullptr; } else { c->~Command(); } @@ -1186,36 +1188,36 @@ public: } } - last_command = NULL; - commands = NULL; + last_command = nullptr; + commands = nullptr; current_block = 0; clip = false; rect_dirty = true; - final_clip_owner = NULL; - material_owner = NULL; + final_clip_owner = nullptr; + material_owner = nullptr; light_masked = false; } Item() { - commands = NULL; - last_command = NULL; + commands = nullptr; + last_command = nullptr; current_block = 0; light_mask = 1; - vp_render = NULL; - next = NULL; - final_clip_owner = NULL; + vp_render = nullptr; + next = nullptr; + final_clip_owner = nullptr; clip = false; final_modulate = Color(1, 1, 1, 1); visible = true; rect_dirty = true; custom_rect = false; behind = false; - material_owner = NULL; - copy_back_buffer = NULL; + material_owner = nullptr; + copy_back_buffer = nullptr; distance_field = false; light_masked = false; update_when_visible = false; z_final = 0; - custom_data = NULL; + custom_data = nullptr; } virtual ~Item() { clear(); @@ -1248,7 +1250,7 @@ public: LightOccluderInstance() { enabled = true; - next = NULL; + next = nullptr; light_mask = 1; cull_cache = RS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; } diff --git a/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.cpp index 8d52ffd7b9..ba4f4c4acb 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.cpp @@ -1220,7 +1220,7 @@ void RasterizerCanvasRD::_render_item(RD::DrawListID p_draw_list, const Item *p_ glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 5)); glVertexAttribDivisor(10, 1); glEnableVertexAttribArray(11); //color - glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, NULL); + glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, nullptr); glVertexAttribDivisor(11, 1); glEnableVertexAttribArray(12); //custom glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 2)); @@ -1262,7 +1262,7 @@ void RasterizerCanvasRD::_render_item(RD::DrawListID p_draw_list, const Item *p_ glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 5)); glVertexAttribDivisor(10, 1); glEnableVertexAttribArray(11); //color - glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, NULL); + glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, nullptr); glVertexAttribDivisor(11, 1); glEnableVertexAttribArray(12); //custom glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 2)); @@ -1314,13 +1314,13 @@ void RasterizerCanvasRD::_render_item(RD::DrawListID p_draw_list, const Item *p_ if (current_clip && reclip) { //will make it re-enable clipping if needed afterwards - current_clip = NULL; + current_clip = nullptr; } } void RasterizerCanvasRD::_render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, RID p_screen_uniform_set) { - Item *current_clip = NULL; + Item *current_clip = nullptr; Transform2D canvas_transform_inverse = p_canvas_transform_inverse; @@ -1369,7 +1369,7 @@ void RasterizerCanvasRD::_render_items(RID p_to_render_target, int p_item_count, if (ci->material != prev_material) { - MaterialData *material_data = NULL; + MaterialData *material_data = nullptr; if (ci->material.is_valid()) { material_data = (MaterialData *)storage->material_get_data(ci->material, RasterizerStorageRD::SHADER_TYPE_2D); } @@ -2532,7 +2532,7 @@ RasterizerCanvasRD::~RasterizerCanvasRD() { //anything remains? if (bindings.texture_bindings.size()) { ERR_PRINT("Some texture bindings were not properly freed (leaked canvasitems?"); - const TextureBindingID *key = NULL; + const TextureBindingID *key = nullptr; while ((key = bindings.texture_bindings.next(key))) { TextureBinding *tb = bindings.texture_bindings[*key]; tb->reference_count = 1; diff --git a/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.h b/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.h index 0c151975bc..83b431eaf6 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_canvas_rd.h @@ -383,7 +383,7 @@ class RasterizerCanvasRD : public RasterizerCanvas { for (int i = 0; i < DEFAULT_MAX_LIGHTS_PER_ITEM; i++) { light_cache[i].light_version = 0; - light_cache[i].light = NULL; + light_cache[i].light = nullptr; } light_cache_count = 0xFFFFFFFF; } diff --git a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp index 9ccc1f172e..3b22cb4d9d 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp @@ -50,6 +50,16 @@ static _FORCE_INLINE_ void store_transform_3x3(const Basis &p_basis, float *p_ar p_array[11] = 0; } +static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) { + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + + p_array[i * 4 + j] = p_mtx.matrix[i][j]; + } + } +} + RID RasterizerEffectsRD::_get_uniform_set_from_image(RID p_image) { if (image_to_uniform_set_cache.has(p_image)) { @@ -120,6 +130,80 @@ RID RasterizerEffectsRD::_get_compute_uniform_set_from_texture(RID p_texture, bo return uniform_set; } +RID RasterizerEffectsRD::_get_compute_uniform_set_from_texture_pair(RID p_texture1, RID p_texture2, bool p_use_mipmaps) { + + TexturePair tp; + tp.texture1 = p_texture1; + tp.texture2 = p_texture2; + + if (texture_pair_to_compute_uniform_set_cache.has(tp)) { + RID uniform_set = texture_pair_to_compute_uniform_set_cache[tp]; + if (RD::get_singleton()->uniform_set_is_valid(uniform_set)) { + return uniform_set; + } + } + + Vector<RD::Uniform> uniforms; + { + RD::Uniform u; + u.type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE; + u.binding = 0; + u.ids.push_back(p_use_mipmaps ? default_mipmap_sampler : default_sampler); + u.ids.push_back(p_texture1); + uniforms.push_back(u); + } + { + RD::Uniform u; + u.type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE; + u.binding = 1; + u.ids.push_back(p_use_mipmaps ? default_mipmap_sampler : default_sampler); + u.ids.push_back(p_texture2); + uniforms.push_back(u); + } + //any thing with the same configuration (one texture in binding 0 for set 0), is good + RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0), 1); + + texture_pair_to_compute_uniform_set_cache[tp] = uniform_set; + + return uniform_set; +} + +RID RasterizerEffectsRD::_get_compute_uniform_set_from_image_pair(RID p_texture1, RID p_texture2) { + + TexturePair tp; + tp.texture1 = p_texture1; + tp.texture2 = p_texture2; + + if (image_pair_to_compute_uniform_set_cache.has(tp)) { + RID uniform_set = image_pair_to_compute_uniform_set_cache[tp]; + if (RD::get_singleton()->uniform_set_is_valid(uniform_set)) { + return uniform_set; + } + } + + Vector<RD::Uniform> uniforms; + { + RD::Uniform u; + u.type = RD::UNIFORM_TYPE_IMAGE; + u.binding = 0; + u.ids.push_back(p_texture1); + uniforms.push_back(u); + } + { + RD::Uniform u; + u.type = RD::UNIFORM_TYPE_IMAGE; + u.binding = 1; + u.ids.push_back(p_texture2); + uniforms.push_back(u); + } + //any thing with the same configuration (one texture in binding 0 for set 0), is good + RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0), 3); + + image_pair_to_compute_uniform_set_cache[tp] = uniform_set; + + return uniform_set; +} + void RasterizerEffectsRD::copy_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_rect, bool p_flip_y, bool p_force_luminance) { zeromem(&blur.push_constant, sizeof(BlurPushConstant)); @@ -218,6 +302,7 @@ void RasterizerEffectsRD::gaussian_glow(RID p_source_rd_texture, RID p_framebuff blur.push_constant.glow_exposure = p_exposure; blur.push_constant.glow_white = 0; //actually unused blur.push_constant.glow_luminance_cap = p_luminance_cap; + blur.push_constant.glow_auto_exposure_grey = p_auto_exposure_grey; //unused also //HORIZONTAL @@ -250,6 +335,165 @@ void RasterizerEffectsRD::gaussian_glow(RID p_source_rd_texture, RID p_framebuff RD::get_singleton()->draw_list_end(); } +void RasterizerEffectsRD::screen_space_reflection(RID p_diffuse, RID p_normal, RenderingServer::EnvironmentSSRRoughnessQuality p_roughness_quality, RID p_roughness, RID p_blur_radius, RID p_blur_radius2, RID p_metallic, const Color &p_metallic_mask, RID p_depth, RID p_scale_depth, RID p_scale_normal, RID p_output, RID p_output_blur, const Size2i &p_screen_size, int p_max_steps, float p_fade_in, float p_fade_out, float p_tolerance, const CameraMatrix &p_camera) { + + RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin(); + + int32_t x_groups = (p_screen_size.width - 1) / 8 + 1; + int32_t y_groups = (p_screen_size.height - 1) / 8 + 1; + + { //scale color and depth to half + ssr_scale.push_constant.camera_z_far = p_camera.get_z_far(); + ssr_scale.push_constant.camera_z_near = p_camera.get_z_near(); + ssr_scale.push_constant.orthogonal = p_camera.is_orthogonal(); + ssr_scale.push_constant.filter = false; //enabling causes arctifacts + ssr_scale.push_constant.screen_size[0] = p_screen_size.x; + ssr_scale.push_constant.screen_size[1] = p_screen_size.y; + + RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr_scale.pipeline); + + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_diffuse), 0); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture_pair(p_depth, p_normal), 1); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_output_blur), 2); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_scale_depth, p_scale_normal), 3); + + RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr_scale.push_constant, sizeof(ScreenSpaceReflectionScalePushConstant)); + + RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1); + + RD::get_singleton()->compute_list_add_barrier(compute_list); + } + + { + + ssr.push_constant.camera_z_far = p_camera.get_z_far(); + ssr.push_constant.camera_z_near = p_camera.get_z_near(); + ssr.push_constant.orthogonal = p_camera.is_orthogonal(); + ssr.push_constant.screen_size[0] = p_screen_size.x; + ssr.push_constant.screen_size[1] = p_screen_size.y; + ssr.push_constant.curve_fade_in = p_fade_in; + ssr.push_constant.distance_fade = p_fade_out; + ssr.push_constant.num_steps = p_max_steps; + ssr.push_constant.depth_tolerance = p_tolerance; + ssr.push_constant.use_half_res = true; + ssr.push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_camera.matrix[0][0]); + ssr.push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_camera.matrix[1][1]); + ssr.push_constant.proj_info[2] = (1.0f - p_camera.matrix[0][2]) / p_camera.matrix[0][0]; + ssr.push_constant.proj_info[3] = (1.0f + p_camera.matrix[1][2]) / p_camera.matrix[1][1]; + ssr.push_constant.metallic_mask[0] = CLAMP(p_metallic_mask.r * 255.0, 0, 255); + ssr.push_constant.metallic_mask[1] = CLAMP(p_metallic_mask.g * 255.0, 0, 255); + ssr.push_constant.metallic_mask[2] = CLAMP(p_metallic_mask.b * 255.0, 0, 255); + ssr.push_constant.metallic_mask[3] = CLAMP(p_metallic_mask.a * 255.0, 0, 255); + store_camera(p_camera, ssr.push_constant.projection); + + RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr.pipelines[(p_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED) ? SCREEN_SPACE_REFLECTION_ROUGH : SCREEN_SPACE_REFLECTION_NORMAL]); + + RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr.push_constant, sizeof(ScreenSpaceReflectionPushConstant)); + + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output_blur, p_scale_depth), 0); + + if (p_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED) { + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output, p_blur_radius), 1); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture_pair(p_metallic, p_roughness), 3); + } else { + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_output), 1); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_metallic), 3); + } + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_normal), 2); + + RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1); + } + + if (p_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED) { + + //blurr + + RD::get_singleton()->compute_list_add_barrier(compute_list); + + ssr_filter.push_constant.orthogonal = p_camera.is_orthogonal(); + ssr_filter.push_constant.edge_tolerance = Math::sin(Math::deg2rad(15.0)); + ssr_filter.push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_camera.matrix[0][0]); + ssr_filter.push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_camera.matrix[1][1]); + ssr_filter.push_constant.proj_info[2] = (1.0f - p_camera.matrix[0][2]) / p_camera.matrix[0][0]; + ssr_filter.push_constant.proj_info[3] = (1.0f + p_camera.matrix[1][2]) / p_camera.matrix[1][1]; + ssr_filter.push_constant.vertical = 0; + if (p_roughness_quality == RS::ENV_SSR_ROUGNESS_QUALITY_LOW) { + ssr_filter.push_constant.steps = p_max_steps / 3; + ssr_filter.push_constant.increment = 3; + } else if (p_roughness_quality == RS::ENV_SSR_ROUGNESS_QUALITY_MEDIUM) { + ssr_filter.push_constant.steps = p_max_steps / 2; + ssr_filter.push_constant.increment = 2; + } else { + ssr_filter.push_constant.steps = p_max_steps; + ssr_filter.push_constant.increment = 1; + } + + ssr_filter.push_constant.screen_size[0] = p_screen_size.width; + ssr_filter.push_constant.screen_size[1] = p_screen_size.height; + + RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr_filter.pipelines[SCREEN_SPACE_REFLECTION_FILTER_HORIZONTAL]); + + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output, p_blur_radius), 0); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_normal), 1); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output_blur, p_blur_radius2), 2); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_depth), 3); + + RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr_filter.push_constant, sizeof(ScreenSpaceReflectionFilterPushConstant)); + + RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1); + + RD::get_singleton()->compute_list_add_barrier(compute_list); + + RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr_filter.pipelines[SCREEN_SPACE_REFLECTION_FILTER_VERTICAL]); + + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output_blur, p_blur_radius2), 0); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_normal), 1); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_output), 2); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_depth), 3); + + ssr_filter.push_constant.vertical = 1; + + RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr_filter.push_constant, sizeof(ScreenSpaceReflectionFilterPushConstant)); + + RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1); + } + + RD::get_singleton()->compute_list_end(); +} + +void RasterizerEffectsRD::merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection) { + + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD, Vector<Color>()); + + if (p_reflection.is_valid()) { + + if (p_base.is_valid()) { + RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_SSR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer))); + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_base), 2); + } else { + RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_ADDITIVE_SSR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer))); + } + + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_specular), 0); + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_reflection), 1); + + } else { + + if (p_base.is_valid()) { + RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_ADD].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer))); + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_base), 2); + } else { + RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_ADDITIVE_ADD].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer))); + } + + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_specular), 0); + } + + RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array); + RD::get_singleton()->draw_list_draw(draw_list, true); + RD::get_singleton()->draw_list_end(); +} + void RasterizerEffectsRD::make_mipmap(RID p_source_rd_texture, RID p_dest_framebuffer, const Vector2 &p_pixel_size) { zeromem(&blur.push_constant, sizeof(BlurPushConstant)); @@ -970,6 +1214,7 @@ RasterizerEffectsRD::RasterizerEffectsRD() { for (int i = SSAO_BLUR_PASS; i <= SSAO_BLUR_UPSCALE; i++) { ssao.pipelines[pipeline] = RD::get_singleton()->compute_pipeline_create(ssao.blur_shader.version_get_shader(ssao.blur_shader_version, i - SSAO_BLUR_PASS)); + pipeline++; } } @@ -1035,6 +1280,82 @@ RasterizerEffectsRD::RasterizerEffectsRD() { filter.uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.shader.version_get_shader(filter.shader_version, filter.use_high_quality ? 0 : 1), 1); } + { + Vector<String> specular_modes; + specular_modes.push_back("\n#define MODE_MERGE\n"); + specular_modes.push_back("\n#define MODE_MERGE\n#define MODE_SSR\n"); + specular_modes.push_back("\n"); + specular_modes.push_back("\n#define MODE_SSR\n"); + + specular_merge.shader.initialize(specular_modes); + + specular_merge.shader_version = specular_merge.shader.version_create(); + + //use additive + + RD::PipelineColorBlendState::Attachment ba; + ba.enable_blend = true; + ba.src_color_blend_factor = RD::BLEND_FACTOR_ONE; + ba.dst_color_blend_factor = RD::BLEND_FACTOR_ONE; + ba.src_alpha_blend_factor = RD::BLEND_FACTOR_ONE; + ba.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE; + ba.color_blend_op = RD::BLEND_OP_ADD; + ba.alpha_blend_op = RD::BLEND_OP_ADD; + + RD::PipelineColorBlendState blend_additive; + blend_additive.attachments.push_back(ba); + + for (int i = 0; i < SPECULAR_MERGE_MAX; i++) { + + RD::PipelineColorBlendState blend_state; + if (i == SPECULAR_MERGE_ADDITIVE_ADD || i == SPECULAR_MERGE_ADDITIVE_SSR) { + blend_state = blend_additive; + } else { + blend_state = RD::PipelineColorBlendState::create_disabled(); + } + specular_merge.pipelines[i].setup(specular_merge.shader.version_get_shader(specular_merge.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), blend_state, 0); + } + } + + { + Vector<String> ssr_modes; + ssr_modes.push_back("\n"); + ssr_modes.push_back("\n#define MODE_ROUGH\n"); + + ssr.shader.initialize(ssr_modes); + + ssr.shader_version = ssr.shader.version_create(); + + for (int i = 0; i < SCREEN_SPACE_REFLECTION_MAX; i++) { + ssr.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr.shader.version_get_shader(ssr.shader_version, i)); + } + } + + { + Vector<String> ssr_filter_modes; + ssr_filter_modes.push_back("\n"); + ssr_filter_modes.push_back("\n#define VERTICAL_PASS\n"); + + ssr_filter.shader.initialize(ssr_filter_modes); + + ssr_filter.shader_version = ssr_filter.shader.version_create(); + + for (int i = 0; i < SCREEN_SPACE_REFLECTION_FILTER_MAX; i++) { + ssr_filter.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr_filter.shader.version_get_shader(ssr_filter.shader_version, i)); + } + } + + { + Vector<String> ssr_scale_modes; + ssr_scale_modes.push_back("\n"); + + ssr_scale.shader.initialize(ssr_scale_modes); + + ssr_scale.shader_version = ssr_scale.shader.version_create(); + + ssr_scale.pipeline = RD::get_singleton()->compute_pipeline_create(ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0)); + } + RD::SamplerState sampler; sampler.mag_filter = RD::SAMPLER_FILTER_LINEAR; sampler.min_filter = RD::SAMPLER_FILTER_LINEAR; diff --git a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h index 69da5dc6d4..32eb8c8cda 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h @@ -41,6 +41,10 @@ #include "servers/rendering/rasterizer_rd/shaders/cubemap_roughness.glsl.gen.h" #include "servers/rendering/rasterizer_rd/shaders/luminance_reduce.glsl.gen.h" #include "servers/rendering/rasterizer_rd/shaders/roughness_limiter.glsl.gen.h" +#include "servers/rendering/rasterizer_rd/shaders/screen_space_reflection.glsl.gen.h" +#include "servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl.gen.h" +#include "servers/rendering/rasterizer_rd/shaders/screen_space_reflection_scale.glsl.gen.h" +#include "servers/rendering/rasterizer_rd/shaders/specular_merge.glsl.gen.h" #include "servers/rendering/rasterizer_rd/shaders/ssao.glsl.gen.h" #include "servers/rendering/rasterizer_rd/shaders/ssao_blur.glsl.gen.h" #include "servers/rendering/rasterizer_rd/shaders/ssao_minify.glsl.gen.h" @@ -378,6 +382,104 @@ class RasterizerEffectsRD { float pad[3]; }; + enum SpecularMergeMode { + SPECULAR_MERGE_ADD, + SPECULAR_MERGE_SSR, + SPECULAR_MERGE_ADDITIVE_ADD, + SPECULAR_MERGE_ADDITIVE_SSR, + SPECULAR_MERGE_MAX + }; + + struct SpecularMerge { + + SpecularMergeShaderRD shader; + RID shader_version; + RenderPipelineVertexFormatCacheRD pipelines[SPECULAR_MERGE_MAX]; + + } specular_merge; + + enum ScreenSpaceReflectionMode { + SCREEN_SPACE_REFLECTION_NORMAL, + SCREEN_SPACE_REFLECTION_ROUGH, + SCREEN_SPACE_REFLECTION_MAX, + }; + + struct ScreenSpaceReflectionPushConstant { + + float proj_info[4]; + + int32_t screen_size[2]; + float camera_z_near; + float camera_z_far; + + int32_t num_steps; + float depth_tolerance; + float distance_fade; + float curve_fade_in; + + uint32_t orthogonal; + float filter_mipmap_levels; + uint32_t use_half_res; + uint8_t metallic_mask[4]; + + float projection[16]; + }; + + struct ScreenSpaceReflection { + + ScreenSpaceReflectionPushConstant push_constant; + ScreenSpaceReflectionShaderRD shader; + RID shader_version; + RID pipelines[SCREEN_SPACE_REFLECTION_MAX]; + + } ssr; + + struct ScreenSpaceReflectionFilterPushConstant { + + float proj_info[4]; + + uint32_t orthogonal; + float edge_tolerance; + int32_t increment; + uint32_t pad; + + int32_t screen_size[2]; + uint32_t vertical; + uint32_t steps; + }; + enum { + SCREEN_SPACE_REFLECTION_FILTER_HORIZONTAL, + SCREEN_SPACE_REFLECTION_FILTER_VERTICAL, + SCREEN_SPACE_REFLECTION_FILTER_MAX, + }; + + struct ScreenSpaceReflectionFilter { + + ScreenSpaceReflectionFilterPushConstant push_constant; + ScreenSpaceReflectionFilterShaderRD shader; + RID shader_version; + RID pipelines[SCREEN_SPACE_REFLECTION_FILTER_MAX]; + } ssr_filter; + + struct ScreenSpaceReflectionScalePushConstant { + + int32_t screen_size[2]; + float camera_z_near; + float camera_z_far; + + uint32_t orthogonal; + uint32_t filter; + uint32_t pad[2]; + }; + + struct ScreenSpaceReflectionScale { + + ScreenSpaceReflectionScalePushConstant push_constant; + ScreenSpaceReflectionScaleShaderRD shader; + RID shader_version; + RID pipeline; + } ssr_scale; + RID default_sampler; RID default_mipmap_sampler; RID index_buffer; @@ -386,11 +488,28 @@ class RasterizerEffectsRD { Map<RID, RID> texture_to_uniform_set_cache; Map<RID, RID> image_to_uniform_set_cache; + + struct TexturePair { + RID texture1; + RID texture2; + _FORCE_INLINE_ bool operator<(const TexturePair &p_pair) const { + if (texture1 == p_pair.texture1) { + return texture2 < p_pair.texture2; + } else { + return texture1 < p_pair.texture1; + } + } + }; + Map<RID, RID> texture_to_compute_uniform_set_cache; + Map<TexturePair, RID> texture_pair_to_compute_uniform_set_cache; + Map<TexturePair, RID> image_pair_to_compute_uniform_set_cache; RID _get_uniform_set_from_image(RID p_texture); RID _get_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false); RID _get_compute_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false); + RID _get_compute_uniform_set_from_texture_pair(RID p_texture, RID p_texture2, bool p_use_mipmaps = false); + RID _get_compute_uniform_set_from_image_pair(RID p_texture, RID p_texture2); public: //TODO must re-do most of the shaders in compute @@ -450,6 +569,9 @@ public: void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array); void render_sky(RD::DrawListID p_list, float p_time, RID p_fb, RID p_samplers, RID p_lights, RenderPipelineVertexFormatCacheRD *p_pipeline, RID p_uniform_set, RID p_texture_set, const CameraMatrix &p_camera, const Basis &p_orientation, float p_multiplier, const Vector3 &p_position); + void screen_space_reflection(RID p_diffuse, RID p_normal, RS::EnvironmentSSRRoughnessQuality p_roughness_quality, RID p_roughness, RID p_blur_radius, RID p_blur_radius2, RID p_metallic, const Color &p_metallic_mask, RID p_depth, RID p_scale_depth, RID p_scale_normal, RID p_output, RID p_output_blur, const Size2i &p_screen_size, int p_max_steps, float p_fade_in, float p_fade_out, float p_tolerance, const CameraMatrix &p_camera); + void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection); + RasterizerEffectsRD(); ~RasterizerEffectsRD(); }; diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp index bf3cd045f1..6094fbb36f 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp @@ -321,7 +321,7 @@ void RasterizerSceneHighEndRD::ShaderData::set_code(const String &p_code) { } else if (k == SHADER_VERSION_DEPTH_PASS_WITH_NORMAL) { blend_state = blend_state_depth_normal; } else if (k == SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS) { - blend_state = blend_state_depth_normal; + blend_state = blend_state_depth_normal_roughness; } else if (k == SHADER_VERSION_DEPTH_PASS_WITH_MATERIAL) { blend_state = RD::PipelineColorBlendState::create_disabled(5); //writes to normal and roughness in opaque way @@ -537,12 +537,20 @@ void RasterizerSceneHighEndRD::RenderBufferDataHighEnd::ensure_specular() { specular = RD::get_singleton()->texture_create(tf, RD::TextureView()); - Vector<RID> fb; - fb.push_back(color); - fb.push_back(specular); - fb.push_back(depth); + { + Vector<RID> fb; + fb.push_back(color); + fb.push_back(specular); + fb.push_back(depth); + + color_specular_fb = RD::get_singleton()->framebuffer_create(fb); + } + { + Vector<RID> fb; + fb.push_back(specular); - color_specular_fb = RD::get_singleton()->framebuffer_create(fb); + specular_only_fb = RD::get_singleton()->framebuffer_create(fb); + } } } @@ -554,6 +562,7 @@ void RasterizerSceneHighEndRD::RenderBufferDataHighEnd::clear() { } color_specular_fb = RID(); + specular_only_fb = RID(); color_fb = RID(); if (normal_buffer.is_valid()) { @@ -1074,12 +1083,12 @@ void RasterizerSceneHighEndRD::_add_geometry(InstanceBase *p_instance, uint32_t } } - MaterialData *material = NULL; + MaterialData *material = nullptr; if (m_src.is_valid()) { material = (MaterialData *)storage->material_get_data(m_src, RasterizerStorageRD::SHADER_TYPE_3D); if (!material || !material->shader_data->valid) { - material = NULL; + material = nullptr; } } @@ -1203,7 +1212,7 @@ void RasterizerSceneHighEndRD::_fill_render_list(InstanceBase **p_cull_result, i case RS::INSTANCE_MESH: { - const RID *materials = NULL; + const RID *materials = nullptr; uint32_t surface_count; materials = storage->mesh_get_surface_count_and_materials(inst->base, surface_count); @@ -1237,7 +1246,7 @@ void RasterizerSceneHighEndRD::_fill_render_list(InstanceBase **p_cull_result, i continue; } - const RID *materials = NULL; + const RID *materials = nullptr; uint32_t surface_count; materials = storage->mesh_get_surface_count_and_materials(mesh, surface_count); @@ -1258,7 +1267,7 @@ void RasterizerSceneHighEndRD::_fill_render_list(InstanceBase **p_cull_result, i RasterizerStorageGLES3::Immediate *immediate = storage->immediate_owner.getornull(inst->base); ERR_CONTINUE(!immediate); - _add_geometry(immediate, inst, NULL, -1, p_depth_pass, p_shadow_pass); + _add_geometry(immediate, inst, nullptr, -1, p_depth_pass, p_shadow_pass); } break; case RS::INSTANCE_PARTICLES: { @@ -1637,7 +1646,7 @@ void RasterizerSceneHighEndRD::_setup_lights(RID *p_light_cull_result, int p_lig void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID *p_gi_probe_cull_result, int p_gi_probe_cull_count, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, const Color &p_default_bg_color) { - RenderBufferDataHighEnd *render_buffer = NULL; + RenderBufferDataHighEnd *render_buffer = nullptr; if (p_render_buffer.is_valid()) { render_buffer = (RenderBufferDataHighEnd *)render_buffers_get_data(p_render_buffer); } @@ -1699,11 +1708,14 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor Size2 screen_pixel_size; Size2i screen_size; RID opaque_framebuffer; + RID opaque_specular_framebuffer; RID depth_framebuffer; RID alpha_framebuffer; PassMode depth_pass_mode = PASS_MODE_DEPTH; Vector<Color> depth_pass_clear; + bool using_separate_specular = false; + bool using_ssr = false; if (render_buffer) { screen_pixel_size.width = 1.0 / render_buffer->width; @@ -1715,6 +1727,10 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor if (p_environment.is_valid() && environment_is_ssr_enabled(p_environment)) { depth_pass_mode = PASS_MODE_DEPTH_NORMAL_ROUGHNESS; + render_buffer->ensure_specular(); + using_separate_specular = true; + using_ssr = true; + opaque_specular_framebuffer = render_buffer->color_specular_fb; } else if (screen_space_roughness_limiter_is_active()) { depth_pass_mode = PASS_MODE_DEPTH_NORMAL; //we need to allocate both these, if not allocated @@ -1845,22 +1861,22 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor _fill_instances(render_list.elements, render_list.element_count, false); - bool can_continue = true; //unless the middle buffers are needed bool debug_giprobes = get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_ALBEDO || get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING || get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION; - bool using_separate_specular = false; bool depth_pre_pass = depth_framebuffer.is_valid(); RID render_buffers_uniform_set; + bool using_ssao = depth_pre_pass && p_render_buffer.is_valid() && p_environment.is_valid() && environment_is_ssao_enabled(p_environment); + if (depth_pre_pass) { //depth pre pass RENDER_TIMESTAMP("Render Depth Pre-Pass"); - RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(depth_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_CONTINUE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_CONTINUE, depth_pass_clear); + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(depth_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, using_ssao ? RD::FINAL_ACTION_READ : RD::FINAL_ACTION_CONTINUE, depth_pass_clear); _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(depth_framebuffer), render_list.elements, render_list.element_count, false, depth_pass_mode, render_buffer == nullptr, radiance_uniform_set, RID()); RD::get_singleton()->draw_list_end(); } - if (p_render_buffer.is_valid() && p_environment.is_valid() && environment_is_ssao_enabled(p_environment)) { + if (using_ssao) { _process_ssao(p_render_buffer, p_environment, render_buffer->normal_buffer, p_cam_projection); } @@ -1878,23 +1894,41 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor RENDER_TIMESTAMP("Render Opaque Pass"); + bool can_continue_color = !scene_state.used_screen_texture && !using_ssr && !scene_state.used_sss; + bool can_continue_depth = !scene_state.used_depth_texture && !using_ssr; + { - bool will_continue = (can_continue || draw_sky || debug_giprobes); + + bool will_continue_color = (can_continue_color || draw_sky || debug_giprobes); + bool will_continue_depth = (can_continue_depth || draw_sky || debug_giprobes); + //regular forward for now Vector<Color> c; c.push_back(clear_color.to_linear()); - RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(opaque_framebuffer, keep_color ? RD::INITIAL_ACTION_KEEP : RD::INITIAL_ACTION_CLEAR, will_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, depth_pre_pass ? RD::INITIAL_ACTION_CONTINUE : RD::INITIAL_ACTION_CLEAR, will_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, c, 1.0, 0); - _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(opaque_framebuffer), render_list.elements, render_list.element_count, false, PASS_MODE_COLOR, render_buffer == nullptr, radiance_uniform_set, render_buffers_uniform_set); + if (using_separate_specular) { + c.push_back(Color(0, 0, 0, 0)); + } + RID framebuffer = using_separate_specular ? opaque_specular_framebuffer : opaque_framebuffer; + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(framebuffer, keep_color ? RD::INITIAL_ACTION_KEEP : RD::INITIAL_ACTION_CLEAR, will_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, depth_pre_pass ? (using_ssao ? RD::INITIAL_ACTION_KEEP : RD::INITIAL_ACTION_CONTINUE) : RD::INITIAL_ACTION_CLEAR, will_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, c, 1.0, 0); + _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(framebuffer), render_list.elements, render_list.element_count, false, using_separate_specular ? PASS_MODE_COLOR_SPECULAR : PASS_MODE_COLOR, render_buffer == nullptr, radiance_uniform_set, render_buffers_uniform_set); RD::get_singleton()->draw_list_end(); + + if (will_continue_color && using_separate_specular) { + // close the specular framebuffer, as it's no longer used + draw_list = RD::get_singleton()->draw_list_begin(render_buffer->specular_only_fb, RD::INITIAL_ACTION_CONTINUE, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, RD::FINAL_ACTION_CONTINUE); + RD::get_singleton()->draw_list_end(); + } } if (debug_giprobes) { //debug giprobes - bool will_continue = (can_continue || draw_sky); + bool will_continue_color = (can_continue_color || draw_sky); + bool will_continue_depth = (can_continue_depth || draw_sky); + CameraMatrix dc; dc.set_depth_correction(true); CameraMatrix cm = (dc * p_cam_projection) * CameraMatrix(p_cam_transform.affine_inverse()); - RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(opaque_framebuffer, RD::INITIAL_ACTION_CONTINUE, will_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, will_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ); + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(opaque_framebuffer, RD::INITIAL_ACTION_CONTINUE, will_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, will_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ); for (int i = 0; i < p_gi_probe_cull_count; i++) { _debug_giprobe(p_gi_probe_cull_result[i], draw_list, opaque_framebuffer, cm, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION, 1.0); } @@ -1911,12 +1945,24 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor projection = correction * p_cam_projection; } - _draw_sky(can_continue, opaque_framebuffer, p_environment, projection, p_cam_transform); + _draw_sky(can_continue_color, can_continue_depth, opaque_framebuffer, p_environment, projection, p_cam_transform); + } + + if (using_separate_specular) { + + if (scene_state.used_sss) { + RENDER_TIMESTAMP("Sub Surface Scattering"); - if (using_separate_specular && !can_continue) { - //can't continue, so close the buffers - //RD::get_singleton()->draw_list_begin(render_buffer->color_specular_fb, RD::INITIAL_ACTION_CONTINUE, RD::FINAL_ACTION_READ_COLOR_AND_DEPTH, c); - //RD::get_singleton()->draw_list_end(); + //_process_sss() + } + + if (using_ssr) { + RENDER_TIMESTAMP("Screen Space Reflection"); + _process_ssr(p_render_buffer, render_buffer->color_fb, render_buffer->normal_buffer, render_buffer->roughness_buffer, render_buffer->specular, render_buffer->specular, Color(0, 0, 0, 1), p_environment, p_cam_projection, true); + } else { + //just mix specular back + RENDER_TIMESTAMP("Merge Specular"); + storage->get_effects()->merge_specular(render_buffer->color_fb, render_buffer->specular, RID(), RID()); } } @@ -1929,7 +1975,7 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor _fill_instances(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, false); { - RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(alpha_framebuffer, can_continue ? RD::INITIAL_ACTION_CONTINUE : RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, can_continue ? RD::INITIAL_ACTION_CONTINUE : RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ); + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(alpha_framebuffer, can_continue_color ? RD::INITIAL_ACTION_CONTINUE : RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, can_continue_depth ? RD::INITIAL_ACTION_CONTINUE : RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ); _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(alpha_framebuffer), &render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, false, PASS_MODE_COLOR, render_buffer == nullptr, radiance_uniform_set, render_buffers_uniform_set); RD::get_singleton()->draw_list_end(); } @@ -1937,13 +1983,13 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor //_render_list #if 0 if (state.directional_light_count == 0) { - directional_light = NULL; - _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, false, shadow_atlas != NULL); + directional_light = nullptr; + _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, false, shadow_atlas != nullptr); } else { for (int i = 0; i < state.directional_light_count; i++) { directional_light = directional_lights[i]; - _setup_directional_light(i, p_cam_transform.affine_inverse(), shadow_atlas != NULL && shadow_atlas->size > 0); - _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, i > 0, shadow_atlas != NULL); + _setup_directional_light(i, p_cam_transform.affine_inverse(), shadow_atlas != nullptr && shadow_atlas->size > 0); + _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, i > 0, shadow_atlas != nullptr); } } #endif @@ -2366,7 +2412,7 @@ void RasterizerSceneHighEndRD::_update_render_buffers_uniform_set(RID p_render_b } } -RasterizerSceneHighEndRD *RasterizerSceneHighEndRD::singleton = NULL; +RasterizerSceneHighEndRD *RasterizerSceneHighEndRD::singleton = nullptr; void RasterizerSceneHighEndRD::set_time(double p_time, double p_step) { time = p_time; diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h index 4c3422cedb..e79bf2b378 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h @@ -207,6 +207,7 @@ class RasterizerSceneHighEndRD : public RasterizerSceneRD { RID depth_normal_roughness_fb; RID color_fb; RID color_specular_fb; + RID specular_only_fb; int width, height; void ensure_specular(); @@ -489,7 +490,7 @@ class RasterizerSceneHighEndRD : public RasterizerSceneRD { _FORCE_INLINE_ Element *add_element() { if (element_count + alpha_element_count >= max_elements) - return NULL; + return nullptr; elements[element_count] = &base_elements[element_count]; return elements[element_count++]; } @@ -497,7 +498,7 @@ class RasterizerSceneHighEndRD : public RasterizerSceneRD { _FORCE_INLINE_ Element *add_alpha_element() { if (element_count + alpha_element_count >= max_elements) - return NULL; + return nullptr; int idx = max_elements - alpha_element_count - 1; elements[idx] = &base_elements[idx]; alpha_element_count++; diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp index 517eea12f4..af86d145ad 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp @@ -456,7 +456,7 @@ RID RasterizerSceneRD::sky_get_material(RID p_sky) const { return sky->material; } -void RasterizerSceneRD::_draw_sky(bool p_can_continue, RID p_fb, RID p_environment, const CameraMatrix &p_projection, const Transform &p_transform) { +void RasterizerSceneRD::_draw_sky(bool p_can_continue_color, bool p_can_continue_depth, RID p_fb, RID p_environment, const CameraMatrix &p_projection, const Transform &p_transform) { ERR_FAIL_COND(!is_environment(p_environment)); @@ -465,12 +465,12 @@ void RasterizerSceneRD::_draw_sky(bool p_can_continue, RID p_fb, RID p_environme RID sky_material = sky_get_material(environment_get_sky(p_environment)); - SkyMaterialData *material = NULL; + SkyMaterialData *material = nullptr; if (sky_material.is_valid()) { material = (SkyMaterialData *)storage->material_get_data(sky_material, RasterizerStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { - material = NULL; + material = nullptr; } } @@ -537,7 +537,7 @@ void RasterizerSceneRD::_draw_sky(bool p_can_continue, RID p_fb, RID p_environme RID texture_uniform_set = _get_sky_textures(sky, SKY_TEXTURE_SET_BACKGROUND); - RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_fb, RD::INITIAL_ACTION_CONTINUE, p_can_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, p_can_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ); + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_fb, RD::INITIAL_ACTION_CONTINUE, p_can_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, p_can_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ); storage->get_effects()->render_sky(draw_list, time, p_fb, sky_scene_state.sampler_uniform_set, sky_scene_state.light_uniform_set, pipeline, material->uniform_set, texture_uniform_set, camera, sky_transform, multiplier, p_transform.origin); RD::get_singleton()->draw_list_end(); } @@ -551,12 +551,12 @@ void RasterizerSceneRD::_setup_sky(RID p_environment, const Vector3 &p_position, RID sky_material = sky_get_material(environment_get_sky(p_environment)); - SkyMaterialData *material = NULL; + SkyMaterialData *material = nullptr; if (sky_material.is_valid()) { material = (SkyMaterialData *)storage->material_get_data(sky_material, RasterizerStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { - material = NULL; + material = nullptr; } } @@ -688,12 +688,12 @@ void RasterizerSceneRD::_update_sky(RID p_environment, const CameraMatrix &p_pro RID sky_material = sky_get_material(environment_get_sky(p_environment)); - SkyMaterialData *material = NULL; + SkyMaterialData *material = nullptr; if (sky_material.is_valid()) { material = (SkyMaterialData *)storage->material_get_data(sky_material, RasterizerStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { - material = NULL; + material = nullptr; } } @@ -1231,6 +1231,26 @@ void RasterizerSceneRD::environment_glow_set_use_bicubic_upscale(bool p_enable) glow_bicubic_upscale = p_enable; } +void RasterizerSceneRD::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) { + + Environent *env = environment_owner.getornull(p_env); + ERR_FAIL_COND(!env); + + env->ssr_enabled = p_enable; + env->ssr_max_steps = p_max_steps; + env->ssr_fade_in = p_fade_int; + env->ssr_fade_out = p_fade_out; + env->ssr_depth_tolerance = p_depth_tolerance; +} + +void RasterizerSceneRD::environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) { + ssr_roughness_quality = p_quality; +} + +RS::EnvironmentSSRRoughnessQuality RasterizerSceneRD::environment_get_ssr_roughness_quality() const { + return ssr_roughness_quality; +} + void RasterizerSceneRD::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, RS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) { Environent *env = environment_owner.getornull(p_env); @@ -1272,7 +1292,7 @@ bool RasterizerSceneRD::environment_is_ssr_enabled(RID p_env) const { Environent *env = environment_owner.getornull(p_env); ERR_FAIL_COND_V(!env, false); - return false; + return env->ssr_enabled; } bool RasterizerSceneRD::is_environment(RID p_env) const { @@ -3167,6 +3187,74 @@ void RasterizerSceneRD::_free_render_buffer_data(RenderBuffers *rb) { rb->ssao.ao_full = RID(); rb->ssao.depth_slices.clear(); } + + if (rb->ssr.blur_radius[0].is_valid()) { + RD::get_singleton()->free(rb->ssr.blur_radius[0]); + RD::get_singleton()->free(rb->ssr.blur_radius[1]); + rb->ssr.blur_radius[0] = RID(); + rb->ssr.blur_radius[1] = RID(); + } + + if (rb->ssr.depth_scaled.is_valid()) { + RD::get_singleton()->free(rb->ssr.depth_scaled); + rb->ssr.depth_scaled = RID(); + RD::get_singleton()->free(rb->ssr.normal_scaled); + rb->ssr.normal_scaled = RID(); + } +} + +void RasterizerSceneRD::_process_ssr(RID p_render_buffers, RID p_dest_framebuffer, RID p_normal_buffer, RID p_roughness_buffer, RID p_specular_buffer, RID p_metallic, const Color &p_metallic_mask, RID p_environment, const CameraMatrix &p_projection, bool p_use_additive) { + + RenderBuffers *rb = render_buffers_owner.getornull(p_render_buffers); + ERR_FAIL_COND(!rb); + + bool can_use_effects = rb->width >= 8 && rb->height >= 8; + + if (!can_use_effects) { + //just copy + storage->get_effects()->merge_specular(p_dest_framebuffer, p_specular_buffer, p_use_additive ? RID() : rb->texture, RID()); + return; + } + + Environent *env = environment_owner.getornull(p_environment); + ERR_FAIL_COND(!env); + + ERR_FAIL_COND(!env->ssr_enabled); + + if (rb->ssr.depth_scaled.is_null()) { + RD::TextureFormat tf; + tf.format = RD::DATA_FORMAT_R32_SFLOAT; + tf.width = rb->width / 2; + tf.height = rb->height / 2; + tf.type = RD::TEXTURE_TYPE_2D; + tf.usage_bits = RD::TEXTURE_USAGE_STORAGE_BIT; + + rb->ssr.depth_scaled = RD::get_singleton()->texture_create(tf, RD::TextureView()); + + tf.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; + + rb->ssr.normal_scaled = RD::get_singleton()->texture_create(tf, RD::TextureView()); + } + + if (ssr_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED && !rb->ssr.blur_radius[0].is_valid()) { + RD::TextureFormat tf; + tf.format = RD::DATA_FORMAT_R8_UNORM; + tf.width = rb->width / 2; + tf.height = rb->height / 2; + tf.type = RD::TEXTURE_TYPE_2D; + tf.usage_bits = RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT; + + rb->ssr.blur_radius[0] = RD::get_singleton()->texture_create(tf, RD::TextureView()); + rb->ssr.blur_radius[1] = RD::get_singleton()->texture_create(tf, RD::TextureView()); + } + + if (rb->blur[0].texture.is_null()) { + _allocate_blur_textures(rb); + _render_buffers_uniform_set_changed(p_render_buffers); + } + + storage->get_effects()->screen_space_reflection(rb->texture, p_normal_buffer, ssr_roughness_quality, p_roughness_buffer, rb->ssr.blur_radius[0], rb->ssr.blur_radius[1], p_metallic, p_metallic_mask, rb->depth_texture, rb->ssr.depth_scaled, rb->ssr.normal_scaled, rb->blur[0].mipmaps[1].texture, rb->blur[1].mipmaps[0].texture, Size2i(rb->width / 2, rb->height / 2), env->ssr_max_steps, env->ssr_fade_in, env->ssr_fade_out, env->ssr_depth_tolerance, p_projection); + storage->get_effects()->merge_specular(p_dest_framebuffer, p_specular_buffer, p_use_additive ? RID() : rb->texture, rb->blur[0].mipmaps[1].texture); } void RasterizerSceneRD::_process_ssao(RID p_render_buffers, RID p_environment, RID p_normal_buffer, const CameraMatrix &p_projection) { @@ -3469,7 +3557,7 @@ bool RasterizerSceneRD::is_using_radiance_cubemap_array() const { RasterizerSceneRD::RenderBufferData *RasterizerSceneRD::render_buffers_get_data(RID p_render_buffers) { RenderBuffers *rb = render_buffers_owner.getornull(p_render_buffers); - ERR_FAIL_COND_V(!rb, NULL); + ERR_FAIL_COND_V(!rb, nullptr); return rb->data; } @@ -3798,7 +3886,7 @@ float RasterizerSceneRD::screen_space_roughness_limiter_get_curve() const { return screen_space_roughness_limiter_curve; } -RasterizerSceneRD *RasterizerSceneRD::singleton = NULL; +RasterizerSceneRD *RasterizerSceneRD::singleton = nullptr; RasterizerSceneRD::RasterizerSceneRD(RasterizerStorageRD *p_storage) { storage = p_storage; @@ -4012,6 +4100,7 @@ RasterizerSceneRD::RasterizerSceneRD(RasterizerStorageRD *p_storage) { screen_space_roughness_limiter = GLOBAL_GET("rendering/quality/filters/screen_space_roughness_limiter"); screen_space_roughness_limiter_curve = GLOBAL_GET("rendering/quality/filters/screen_space_roughness_limiter_curve"); glow_bicubic_upscale = int(GLOBAL_GET("rendering/quality/glow/upscale_mode")) > 0; + ssr_roughness_quality = RS::EnvironmentSSRRoughnessQuality(int(GLOBAL_GET("rendering/quality/screen_space_reflection/roughness_quality"))); } RasterizerSceneRD::~RasterizerSceneRD() { diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h index e26607aba5..11a8555d22 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h @@ -92,10 +92,11 @@ protected: virtual RID _render_buffers_get_normal_texture(RID p_render_buffers) = 0; void _process_ssao(RID p_render_buffers, RID p_environment, RID p_normal_buffer, const CameraMatrix &p_projection); + void _process_ssr(RID p_render_buffers, RID p_dest_framebuffer, RID p_normal_buffer, RID p_roughness_buffer, RID p_specular_buffer, RID p_metallic, const Color &p_metallic_mask, RID p_environment, const CameraMatrix &p_projection, bool p_use_additive); void _setup_sky(RID p_environment, const Vector3 &p_position, const Size2i p_screen_size); void _update_sky(RID p_environment, const CameraMatrix &p_projection, const Transform &p_transform); - void _draw_sky(bool p_can_continue, RID p_fb, RID p_environment, const CameraMatrix &p_projection, const Transform &p_transform); + void _draw_sky(bool p_can_continue_color, bool p_can_continue_depth, RID p_fb, RID p_environment, const CameraMatrix &p_projection, const Transform &p_transform); private: RS::ViewportDebugDraw debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED; @@ -571,7 +572,7 @@ private: Rect2 atlas_rect; }; - RS::LightType light_type; + RS::LightType light_type = RS::LIGHT_DIRECTIONAL; ShadowTransform shadow_transform[4]; @@ -581,7 +582,7 @@ private: Vector3 light_vector; Vector3 spot_vector; - float linear_att; + float linear_att = 0.0; uint64_t shadow_pass = 0; uint64_t last_scene_pass = 0; @@ -590,7 +591,7 @@ private: uint32_t light_index = 0; uint32_t light_directional_index = 0; - uint32_t current_shadow_atlas_key; + uint32_t current_shadow_atlas_key = 0; Vector2 dp; @@ -657,11 +658,20 @@ private: float ssao_ao_channel_affect = 0.0; float ssao_blur_edge_sharpness = 4.0; RS::EnvironmentSSAOBlur ssao_blur = RS::ENV_SSAO_BLUR_3x3; + + /// SSR + /// + bool ssr_enabled = false; + int ssr_max_steps = 64; + float ssr_fade_in = 0.15; + float ssr_fade_out = 2.0; + float ssr_depth_tolerance = 0.2; }; RS::EnvironmentSSAOQuality ssao_quality = RS::ENV_SSAO_QUALITY_MEDIUM; bool ssao_half_size = false; bool glow_bicubic_upscale = false; + RS::EnvironmentSSRRoughnessQuality ssr_roughness_quality = RS::ENV_SSR_ROUGNESS_QUALITY_LOW; static uint64_t auto_exposure_counter; @@ -733,6 +743,12 @@ private: RID ao[2]; RID ao_full; //when using half-size } ssao; + + struct SSR { + RID normal_scaled; + RID depth_scaled; + RID blur_radius[2]; + } ssr; }; bool screen_space_roughness_limiter = false; @@ -832,7 +848,7 @@ public: void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {} - void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) {} + void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance); void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, RS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness); void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size); bool environment_is_ssao_enabled(RID p_env) const; @@ -840,6 +856,9 @@ public: float environment_get_ssao_light_affect(RID p_env) const; bool environment_is_ssr_enabled(RID p_env) const; + void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality); + RS::EnvironmentSSRRoughnessQuality environment_get_ssr_roughness_quality() const; + void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale); void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) {} diff --git a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp index 83af15602c..322e89ef9a 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "rasterizer_storage_rd.h" + #include "core/engine.h" #include "core/project_settings.h" #include "servers/rendering/shader_language.h" @@ -861,7 +862,7 @@ Size2 RasterizerStorageRD::texture_size_with_proxy(RID p_proxy) { RID RasterizerStorageRD::shader_create() { Shader shader; - shader.data = NULL; + shader.data = nullptr; shader.type = SHADER_TYPE_MAX; return shader_owner.make_rid(shader); @@ -889,7 +890,7 @@ void RasterizerStorageRD::shader_set_code(RID p_shader, const String &p_code) { if (new_type != shader->type) { if (shader->data) { memdelete(shader->data); - shader->data = NULL; + shader->data = nullptr; } for (Set<Material *>::Element *E = shader->owners.front(); E; E = E->next()) { @@ -898,7 +899,7 @@ void RasterizerStorageRD::shader_set_code(RID p_shader, const String &p_code) { material->shader_type = new_type; if (material->data) { memdelete(material->data); - material->data = NULL; + material->data = nullptr; } } @@ -990,10 +991,10 @@ void RasterizerStorageRD::shader_set_data_request_function(ShaderType p_shader_t RID RasterizerStorageRD::material_create() { Material material; - material.data = NULL; - material.shader = NULL; + material.data = nullptr; + material.shader = nullptr; material.shader_type = SHADER_TYPE_MAX; - material.update_next = NULL; + material.update_next = nullptr; material.update_requested = false; material.uniform_dirty = false; material.texture_dirty = false; @@ -1025,12 +1026,12 @@ void RasterizerStorageRD::material_set_shader(RID p_material, RID p_shader) { if (material->data) { memdelete(material->data); - material->data = NULL; + material->data = nullptr; } if (material->shader) { material->shader->owners.erase(material); - material->shader = NULL; + material->shader = nullptr; material->shader_type = SHADER_TYPE_MAX; } @@ -1049,7 +1050,7 @@ void RasterizerStorageRD::material_set_shader(RID p_material, RID p_shader) { return; } - ERR_FAIL_COND(shader->data == NULL); + ERR_FAIL_COND(shader->data == nullptr); material->data = material_data_request_func[shader->type](shader->data); material->data->set_next_pass(material->next_pass); @@ -1664,7 +1665,7 @@ void RasterizerStorageRD::MaterialData::update_textures(const Map<StringName, Va RasterizerStorageRD *singleton = (RasterizerStorageRD *)RasterizerStorage::base_singleton; #ifdef TOOLS_ENABLED Texture *roughness_detect_texture = nullptr; - RS::TextureDetectRoughnessChannel roughness_channel; + RS::TextureDetectRoughnessChannel roughness_channel = RS::TEXTURE_DETECT_ROUGNHESS_R; Texture *normal_detect_texture = nullptr; #endif @@ -1769,10 +1770,10 @@ void RasterizerStorageRD::_update_queued_materials() { material->update_requested = false; material->texture_dirty = false; material->uniform_dirty = false; - material->update_next = NULL; + material->update_next = nullptr; material = next; } - material_update_list = NULL; + material_update_list = nullptr; } /* MESH API */ @@ -4452,10 +4453,10 @@ String RasterizerStorageRD::get_captured_timestamp_name(uint32_t p_index) const RasterizerStorageRD::RasterizerStorageRD() { for (int i = 0; i < SHADER_TYPE_MAX; i++) { - shader_data_request_func[i] = NULL; + shader_data_request_func[i] = nullptr; } - material_update_list = NULL; + material_update_list = nullptr; { //create default textures RD::TextureFormat tformat; diff --git a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h index e69be644d7..49f77e49e1 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h @@ -218,7 +218,7 @@ private: struct Mesh { struct Surface { - RS::PrimitiveType primitive; + RS::PrimitiveType primitive = RS::PRIMITIVE_POINTS; uint32_t format = 0; RID vertex_buffer; @@ -232,8 +232,8 @@ private: // cache-efficient structure. struct Version { - uint32_t input_mask; - RD::VertexFormatID vertex_format; + uint32_t input_mask = 0; + RD::VertexFormatID vertex_format = 0; RID vertex_array; }; @@ -246,7 +246,7 @@ private: uint32_t index_count = 0; struct LOD { - float edge_length; + float edge_length = 0.0; RID index_buffer; RID index_array; }; @@ -456,9 +456,9 @@ private: RID color; //used for retrieving from CPU - RD::DataFormat color_format; - RD::DataFormat color_format_srgb; - Image::Format image_format; + RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8; + RD::DataFormat color_format_srgb = RD::DATA_FORMAT_R4G4_UNORM_PACK8; + Image::Format image_format = Image::FORMAT_L8; bool flags[RENDER_TARGET_FLAG_MAX]; @@ -604,7 +604,7 @@ public: _FORCE_INLINE_ MaterialData *material_get_data(RID p_material, ShaderType p_shader_type) { Material *material = material_owner.getornull(p_material); if (!material || material->shader_type != p_shader_type) { - return NULL; + return nullptr; } else { return material->data; } @@ -640,10 +640,10 @@ public: _FORCE_INLINE_ const RID *mesh_get_surface_count_and_materials(RID p_mesh, uint32_t &r_surface_count) { Mesh *mesh = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!mesh, NULL); + ERR_FAIL_COND_V(!mesh, nullptr); r_surface_count = mesh->surface_count; if (r_surface_count == 0) { - return NULL; + return nullptr; } if (mesh->material_cache.empty()) { mesh->material_cache.resize(mesh->surface_count); @@ -1037,7 +1037,7 @@ public: void lightmap_capture_set_energy(RID p_capture, float p_energy) {} float lightmap_capture_get_energy(RID p_capture) const { return 0.0; } const Vector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const { - return NULL; + return nullptr; } /* PARTICLES */ diff --git a/servers/rendering/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp b/servers/rendering/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp index 4ee020aa69..2bfdb7fffe 100644 --- a/servers/rendering/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp +++ b/servers/rendering/rasterizer_rd/render_pipeline_vertex_format_cache_rd.cpp @@ -57,7 +57,7 @@ void RenderPipelineVertexFormatCacheRD::_clear() { } version_count = 0; memfree(versions); - versions = NULL; + versions = nullptr; } } @@ -88,7 +88,7 @@ void RenderPipelineVertexFormatCacheRD::clear() { RenderPipelineVertexFormatCacheRD::RenderPipelineVertexFormatCacheRD() { version_count = 0; - versions = NULL; + versions = nullptr; input_mask = 0; } diff --git a/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp b/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp index b3a4b0ede8..4a0b4f02b1 100644 --- a/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp +++ b/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp @@ -303,7 +303,7 @@ void ShaderCompilerRD::_dump_function_deps(const SL::ShaderNode *p_node, const S _dump_function_deps(p_node, E->get(), p_func_code, r_to_add, added); - SL::FunctionNode *fnode = NULL; + SL::FunctionNode *fnode = nullptr; for (int i = 0; i < p_node->functions.size(); i++) { if (p_node->functions[i].name == E->get()) { @@ -572,7 +572,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge function = fnode; current_func_name = fnode->name; function_code[fnode->name] = _dump_node_code(fnode->body, p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning); - function = NULL; + function = nullptr; } //place functions in actual code @@ -605,7 +605,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge _dump_function_deps(pnode, fnode->name, function_code, r_gen_code.fragment_global, added_fragment); r_gen_code.light = function_code[light_name]; } - function = NULL; + function = nullptr; } //code+=dump_node_code(pnode->body,p_level); @@ -798,12 +798,12 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge else code = _mkid(anode->name); - if (anode->call_expression != NULL) { + if (anode->call_expression != nullptr) { code += "."; code += _dump_node_code(anode->call_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); } - if (anode->index_expression != NULL) { + if (anode->index_expression != nullptr) { code += "["; code += _dump_node_code(anode->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); code += "]"; @@ -1025,7 +1025,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge case SL::Node::TYPE_MEMBER: { SL::MemberNode *mnode = (SL::MemberNode *)p_node; code = _dump_node_code(mnode->owner, p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + "." + mnode->name; - if (mnode->index_expression != NULL) { + if (mnode->index_expression != nullptr) { code += "["; code += _dump_node_code(mnode->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); code += "]"; @@ -1048,7 +1048,7 @@ Error ShaderCompilerRD::compile(RS::ShaderMode p_mode, const String &p_code, Ide print_line(itos(i + 1) + " " + shader[i]); } - _err_print_error(NULL, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER); + _err_print_error(nullptr, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER); return err; } @@ -1066,7 +1066,7 @@ Error ShaderCompilerRD::compile(RS::ShaderMode p_mode, const String &p_code, Ide used_flag_pointers.clear(); shader = parser.get_shader(); - function = NULL; + function = nullptr; _dump_node_code(shader, 1, r_gen_code, *p_actions, actions, false); return OK; diff --git a/servers/rendering/rasterizer_rd/shader_rd.cpp b/servers/rendering/rasterizer_rd/shader_rd.cpp index 3dcfd0faf9..d60a58813e 100644 --- a/servers/rendering/rasterizer_rd/shader_rd.cpp +++ b/servers/rendering/rasterizer_rd/shader_rd.cpp @@ -191,7 +191,7 @@ RID ShaderRD::version_create() { version.dirty = true; version.valid = false; version.initialize_needed = true; - version.variants = NULL; + version.variants = nullptr; return version_owner.make_rid(version); } @@ -203,7 +203,7 @@ void ShaderRD::_clear_version(Version *p_version) { } memdelete_arr(p_version->variants); - p_version->variants = NULL; + p_version->variants = nullptr; } } @@ -394,7 +394,7 @@ void ShaderRD::_compile_version(Version *p_version) { } } memdelete_arr(p_version->variants); - p_version->variants = NULL; + p_version->variants = nullptr; return; } diff --git a/servers/rendering/rasterizer_rd/shaders/SCsub b/servers/rendering/rasterizer_rd/shaders/SCsub index 6e852e2dc5..ade0418bd2 100644 --- a/servers/rendering/rasterizer_rd/shaders/SCsub +++ b/servers/rendering/rasterizer_rd/shaders/SCsub @@ -22,3 +22,7 @@ if "RD_GLSL" in env["BUILDERS"]: env.RD_GLSL("ssao_minify.glsl") env.RD_GLSL("ssao_blur.glsl") env.RD_GLSL("roughness_limiter.glsl") + env.RD_GLSL("screen_space_reflection.glsl") + env.RD_GLSL("screen_space_reflection_filter.glsl") + env.RD_GLSL("screen_space_reflection_scale.glsl") + env.RD_GLSL("specular_merge.glsl") diff --git a/servers/rendering/rasterizer_rd/shaders/screen_space_reflection.glsl b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection.glsl new file mode 100644 index 0000000000..e3c26c9b72 --- /dev/null +++ b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection.glsl @@ -0,0 +1,262 @@ +/* clang-format off */ +[compute] + +#version 450 + +VERSION_DEFINES + + + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +/* clang-format on */ + +layout(rgba16f, set = 0, binding = 0) uniform restrict readonly image2D source_diffuse; +layout(r32f, set = 0, binding = 1) uniform restrict readonly image2D source_depth; +layout(rgba16f, set = 1, binding = 0) uniform restrict writeonly image2D ssr_image; +#ifdef MODE_ROUGH +layout(r8, set = 1, binding = 1) uniform restrict writeonly image2D blur_radius_image; +#endif +layout(rgba8, set = 2, binding = 0) uniform restrict readonly image2D source_normal; +layout(set = 3, binding = 0) uniform sampler2D source_metallic; +#ifdef MODE_ROUGH +layout(set = 3, binding = 1) uniform sampler2D source_roughness; +#endif + +layout(push_constant, binding = 2, std430) uniform Params { + + vec4 proj_info; + + ivec2 screen_size; + float camera_z_near; + float camera_z_far; + + int num_steps; + float depth_tolerance; + float distance_fade; + float curve_fade_in; + + bool orthogonal; + float filter_mipmap_levels; + bool use_half_res; + uint metallic_mask; + + mat4 projection; +} +params; + +vec2 view_to_screen(vec3 view_pos, out float w) { + vec4 projected = params.projection * vec4(view_pos, 1.0); + projected.xyz /= projected.w; + projected.xy = projected.xy * 0.5 + 0.5; + w = projected.w; + return projected.xy; +} + +#define M_PI 3.14159265359 + +vec3 reconstructCSPosition(vec2 S, float z) { + if (params.orthogonal) { + return vec3((S.xy * params.proj_info.xy + params.proj_info.zw), z); + } else { + return vec3((S.xy * params.proj_info.xy + params.proj_info.zw) * z, z); + } +} + +void main() { + + // Pixel being shaded + ivec2 ssC = ivec2(gl_GlobalInvocationID.xy); + + if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing + return; + } + + vec2 pixel_size = 1.0 / vec2(params.screen_size); + vec2 uv = vec2(ssC) * pixel_size; + + uv += pixel_size * 0.5; + + float base_depth = imageLoad(source_depth, ssC).r; + + // World space point being shaded + vec3 vertex = reconstructCSPosition(uv * vec2(params.screen_size), base_depth); + + vec3 normal = imageLoad(source_normal, ssC).xyz * 2.0 - 1.0; + normal = normalize(normal); + normal.y = -normal.y; //because this code reads flipped + + vec3 view_dir = normalize(vertex); + vec3 ray_dir = normalize(reflect(view_dir, normal)); + + if (dot(ray_dir, normal) < 0.001) { + imageStore(ssr_image, ssC, vec4(0.0)); + return; + } + //ray_dir = normalize(view_dir - normal * dot(normal,view_dir) * 2.0); + //ray_dir = normalize(vec3(1.0, 1.0, -1.0)); + + //////////////// + + // make ray length and clip it against the near plane (don't want to trace beyond visible) + float ray_len = (vertex.z + ray_dir.z * params.camera_z_far) > -params.camera_z_near ? (-params.camera_z_near - vertex.z) / ray_dir.z : params.camera_z_far; + vec3 ray_end = vertex + ray_dir * ray_len; + + float w_begin; + vec2 vp_line_begin = view_to_screen(vertex, w_begin); + float w_end; + vec2 vp_line_end = view_to_screen(ray_end, w_end); + vec2 vp_line_dir = vp_line_end - vp_line_begin; + + // we need to interpolate w along the ray, to generate perspective correct reflections + w_begin = 1.0 / w_begin; + w_end = 1.0 / w_end; + + float z_begin = vertex.z * w_begin; + float z_end = ray_end.z * w_end; + + vec2 line_begin = vp_line_begin / pixel_size; + vec2 line_dir = vp_line_dir / pixel_size; + float z_dir = z_end - z_begin; + float w_dir = w_end - w_begin; + + // clip the line to the viewport edges + + float scale_max_x = min(1.0, 0.99 * (1.0 - vp_line_begin.x) / max(1e-5, vp_line_dir.x)); + float scale_max_y = min(1.0, 0.99 * (1.0 - vp_line_begin.y) / max(1e-5, vp_line_dir.y)); + float scale_min_x = min(1.0, 0.99 * vp_line_begin.x / max(1e-5, -vp_line_dir.x)); + float scale_min_y = min(1.0, 0.99 * vp_line_begin.y / max(1e-5, -vp_line_dir.y)); + float line_clip = min(scale_max_x, scale_max_y) * min(scale_min_x, scale_min_y); + line_dir *= line_clip; + z_dir *= line_clip; + w_dir *= line_clip; + + // clip z and w advance to line advance + vec2 line_advance = normalize(line_dir); // down to pixel + float step_size = length(line_advance) / length(line_dir); + float z_advance = z_dir * step_size; // adapt z advance to line advance + float w_advance = w_dir * step_size; // adapt w advance to line advance + + // make line advance faster if direction is closer to pixel edges (this avoids sampling the same pixel twice) + float advance_angle_adj = 1.0 / max(abs(line_advance.x), abs(line_advance.y)); + line_advance *= advance_angle_adj; // adapt z advance to line advance + z_advance *= advance_angle_adj; + w_advance *= advance_angle_adj; + + vec2 pos = line_begin; + float z = z_begin; + float w = w_begin; + float z_from = z / w; + float z_to = z_from; + float depth; + vec2 prev_pos = pos; + + bool found = false; + + float steps_taken = 0.0; + + for (int i = 0; i < params.num_steps; i++) { + + pos += line_advance; + z += z_advance; + w += w_advance; + + // convert to linear depth + + depth = imageLoad(source_depth, ivec2(pos - 0.5)).r; + + if (-depth >= params.camera_z_far) { //went beyond camera + break; + } + + z_from = z_to; + z_to = z / w; + + if (depth > z_to) { + // if depth was surpassed + if (depth <= max(z_to, z_from) + params.depth_tolerance) { + // check the depth tolerance + //check that normal is valid + found = true; + } + break; + } + + steps_taken += 1.0; + prev_pos = pos; + } + + if (found) { + + float margin_blend = 1.0; + + vec2 margin = vec2((params.screen_size.x + params.screen_size.y) * 0.5 * 0.05); // make a uniform margin + if (any(bvec4(lessThan(pos, -margin), greaterThan(pos, params.screen_size + margin)))) { + // clip outside screen + margin + imageStore(ssr_image, ssC, vec4(0.0)); + return; + } + + { + //blend fading out towards external margin + vec2 margin_grad = mix(pos - params.screen_size, -pos, lessThan(pos, vec2(0.0))); + margin_blend = 1.0 - smoothstep(0.0, margin.x, max(margin_grad.x, margin_grad.y)); + //margin_blend = 1.0; + } + + vec2 final_pos; + float grad; + grad = steps_taken / float(params.num_steps); + float initial_fade = params.curve_fade_in == 0.0 ? 1.0 : pow(clamp(grad, 0.0, 1.0), params.curve_fade_in); + float fade = pow(clamp(1.0 - grad, 0.0, 1.0), params.distance_fade) * initial_fade; + final_pos = pos; + + vec4 final_color; + +#ifdef MODE_ROUGH + + // if roughness is enabled, do screen space cone tracing + float blur_radius = 0.0; + float roughness = texelFetch(source_roughness, ssC << 1, 0).r; + + if (roughness > 0.001) { + + float cone_angle = min(roughness, 0.999) * M_PI * 0.5; + float cone_len = length(final_pos - line_begin); + float op_len = 2.0 * tan(cone_angle) * cone_len; // opposite side of iso triangle + { + // fit to sphere inside cone (sphere ends at end of cone), something like this: + // ___ + // \O/ + // V + // + // as it avoids bleeding from beyond the reflection as much as possible. As a plus + // it also makes the rough reflection more elongated. + float a = op_len; + float h = cone_len; + float a2 = a * a; + float fh2 = 4.0f * h * h; + blur_radius = (a * (sqrt(a2 + fh2) - a)) / (4.0f * h); + } + } + + final_color = imageLoad(source_diffuse, ivec2((final_pos - 0.5) * pixel_size)); + + imageStore(blur_radius_image, ssC, vec4(blur_radius / 255.0)); //stored in r8 + +#endif + + final_color = vec4(imageLoad(source_diffuse, ivec2(final_pos - 0.5)).rgb, fade * margin_blend); + //change blend by metallic + vec4 metallic_mask = unpackUnorm4x8(params.metallic_mask); + final_color.a *= dot(metallic_mask, texelFetch(source_metallic, ssC << 1, 0)); + + imageStore(ssr_image, ssC, final_color); + + } else { +#ifdef MODE_ROUGH + imageStore(blur_radius_image, ssC, vec4(0.0)); +#endif + imageStore(ssr_image, ssC, vec4(0.0)); + } +} diff --git a/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl new file mode 100644 index 0000000000..671e289ed0 --- /dev/null +++ b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl @@ -0,0 +1,169 @@ +/* clang-format off */ +[compute] + +#version 450 + +VERSION_DEFINES + + + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +/* clang-format on */ + +layout(rgba16f, set = 0, binding = 0) uniform restrict readonly image2D source_ssr; +layout(r8, set = 0, binding = 1) uniform restrict readonly image2D source_radius; +layout(rgba8, set = 1, binding = 0) uniform restrict readonly image2D source_normal; + +layout(rgba16f, set = 2, binding = 0) uniform restrict writeonly image2D dest_ssr; +#ifndef VERTICAL_PASS +layout(r8, set = 2, binding = 1) uniform restrict writeonly image2D dest_radius; +#endif +layout(r32f, set = 3, binding = 0) uniform restrict readonly image2D source_depth; + +layout(push_constant, binding = 2, std430) uniform Params { + + vec4 proj_info; + + bool orthogonal; + float edge_tolerance; + int increment; + uint pad; + + ivec2 screen_size; + bool vertical; + uint steps; +} +params; + +#define GAUSS_TABLE_SIZE 15 + +const float gauss_table[GAUSS_TABLE_SIZE + 1] = float[]( + 0.1847392078702266, + 0.16595854345772326, + 0.12031364177766891, + 0.07038755277896766, + 0.03322925565155569, + 0.012657819729901945, + 0.0038903040680094217, + 0.0009646503390864025, + 0.00019297087402915717, + 0.000031139936308099136, + 0.000004053309048174758, + 4.255228059965837e-7, + 3.602517634249573e-8, + 2.4592560765896795e-9, + 1.3534945386863618e-10, + 0.0 //one more for interpolation +); + +float gauss_weight(float p_val) { + + float idxf; + float c = modf(max(0.0, p_val * float(GAUSS_TABLE_SIZE)), idxf); + int idx = int(idxf); + if (idx >= GAUSS_TABLE_SIZE + 1) { + return 0.0; + } + + return mix(gauss_table[idx], gauss_table[idx + 1], c); +} + +#define GAUSS_WEIGHT(m_val) gauss_table[clamp(int(m_val * float(GAUSS_TABLE_SIZE - 1)), 0, GAUSS_TABLE_SIZE - 1)] + +#define M_PI 3.14159265359 + +vec3 reconstructCSPosition(vec2 S, float z) { + if (params.orthogonal) { + return vec3((S.xy * params.proj_info.xy + params.proj_info.zw), z); + } else { + return vec3((S.xy * params.proj_info.xy + params.proj_info.zw) * z, z); + } +} + +void do_filter(inout vec4 accum, inout float accum_radius, inout float divisor, ivec2 texcoord, ivec2 increment, vec3 p_pos, vec3 normal, float p_limit_radius) { + + for (int i = 1; i < params.steps; i++) { + float d = float(i * params.increment); + ivec2 tc = texcoord + increment * i; + float depth = imageLoad(source_depth, tc).r; + vec3 view_pos = reconstructCSPosition(vec2(tc) + 0.5, depth); + vec3 view_normal = normalize(imageLoad(source_normal, tc).rgb * 2.0 - 1.0); + view_normal.y = -view_normal.y; + + float r = imageLoad(source_radius, tc).r; + float radius = round(r * 255.0); + + float angle_n = 1.0 - abs(dot(normal, view_normal)); + if (angle_n > params.edge_tolerance) { + break; + } + + float angle = abs(dot(normal, normalize(view_pos - p_pos))); + + if (angle > params.edge_tolerance) { + break; + } + + float contrib = 0.0; + if (d < radius) { + contrib += gauss_weight(d / radius); + } + + if (contrib > 0.0) { + accum += imageLoad(source_ssr, tc) * contrib; +#ifndef VERTICAL_PASS + accum_radius += r * contrib; +#endif + divisor += contrib; + } + } +} + +void main() { + + // Pixel being shaded + ivec2 ssC = ivec2(gl_GlobalInvocationID.xy); + + if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing + return; + } + + float base_contrib = gauss_table[0]; + + vec4 accum = imageLoad(source_ssr, ssC); + + float accum_radius = imageLoad(source_radius, ssC).r; + float radius = accum_radius * 255.0; + + float divisor = gauss_table[0]; + accum *= divisor; + accum_radius *= divisor; +#ifdef VERTICAL_PASS + ivec2 direction = ivec2(0, params.increment); +#else + ivec2 direction = ivec2(params.increment, 0); +#endif + float depth = imageLoad(source_depth, ssC).r; + vec3 pos = reconstructCSPosition(vec2(ssC) + 0.5, depth); + vec3 normal = imageLoad(source_normal, ssC).xyz * 2.0 - 1.0; + normal = normalize(normal); + normal.y = -normal.y; + + do_filter(accum, accum_radius, divisor, ssC, direction, pos, normal, radius); + do_filter(accum, accum_radius, divisor, ssC, -direction, pos, normal, radius); + + if (divisor > 0.0) { + accum /= divisor; + accum_radius /= divisor; + } else { + accum = vec4(0.0); + accum_radius = 0.0; + } + + imageStore(dest_ssr, ssC, accum); + +#ifndef VERTICAL_PASS + imageStore(dest_radius, ssC, vec4(accum_radius)); +#endif +} diff --git a/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_scale.glsl b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_scale.glsl new file mode 100644 index 0000000000..cec6c14c76 --- /dev/null +++ b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_scale.glsl @@ -0,0 +1,96 @@ +/* clang-format off */ +[compute] + +#version 450 + +VERSION_DEFINES + + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +/* clang-format on */ + +layout(set = 0, binding = 0) uniform sampler2D source_ssr; +layout(set = 1, binding = 0) uniform sampler2D source_depth; +layout(set = 1, binding = 1) uniform sampler2D source_normal; +layout(rgba16f, set = 2, binding = 0) uniform restrict writeonly image2D dest_ssr; +layout(r32f, set = 3, binding = 0) uniform restrict writeonly image2D dest_depth; +layout(rgba8, set = 3, binding = 1) uniform restrict writeonly image2D dest_normal; + +layout(push_constant, binding = 1, std430) uniform Params { + + ivec2 screen_size; + float camera_z_near; + float camera_z_far; + + bool orthogonal; + bool filtered; + uint pad[2]; +} +params; + +void main() { + + // Pixel being shaded + ivec2 ssC = ivec2(gl_GlobalInvocationID.xy); + + if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing + return; + } + //do not filter, SSR will generate arctifacts if this is done + + float divisor = 0.0; + vec4 color; + float depth; + vec3 normal; + + if (params.filtered) { + + color = vec4(0.0); + depth = 0.0; + normal = vec3(0.0); + + for (int i = 0; i < 4; i++) { + + ivec2 ofs = ssC << 1; + if (bool(i & 1)) { + ofs.x += 1; + } + if (bool(i & 2)) { + ofs.y += 1; + } + color += texelFetch(source_ssr, ofs, 0); + float d = texelFetch(source_depth, ofs, 0).r; + normal += texelFetch(source_normal, ofs, 0).xyz * 2.0 - 1.0; + + d = d * 2.0 - 1.0; + if (params.orthogonal) { + d = ((d + (params.camera_z_far + params.camera_z_near) / (params.camera_z_far - params.camera_z_near)) * (params.camera_z_far - params.camera_z_near)) / 2.0; + } else { + d = 2.0 * params.camera_z_near * params.camera_z_far / (params.camera_z_far + params.camera_z_near - d * (params.camera_z_far - params.camera_z_near)); + } + depth += -d; + } + + color /= 4.0; + depth /= 4.0; + normal = normalize(normal / 4.0) * 0.5 + 0.5; + + } else { + color = texelFetch(source_ssr, ssC << 1, 0); + depth = texelFetch(source_depth, ssC << 1, 0).r; + normal = texelFetch(source_normal, ssC << 1, 0).xyz; + + depth = depth * 2.0 - 1.0; + if (params.orthogonal) { + depth = ((depth + (params.camera_z_far + params.camera_z_near) / (params.camera_z_far - params.camera_z_near)) * (params.camera_z_far - params.camera_z_near)) / 2.0; + } else { + depth = 2.0 * params.camera_z_near * params.camera_z_far / (params.camera_z_far + params.camera_z_near - depth * (params.camera_z_far - params.camera_z_near)); + } + depth = -depth; + } + + imageStore(dest_ssr, ssC, color); + imageStore(dest_depth, ssC, vec4(depth)); + imageStore(dest_normal, ssC, vec4(normal, 0.0)); +} diff --git a/servers/rendering/rasterizer_rd/shaders/specular_merge.glsl b/servers/rendering/rasterizer_rd/shaders/specular_merge.glsl new file mode 100644 index 0000000000..b28250318e --- /dev/null +++ b/servers/rendering/rasterizer_rd/shaders/specular_merge.glsl @@ -0,0 +1,59 @@ +/* clang-format off */ +[vertex] + +#version 450 + +VERSION_DEFINES + +layout(location = 0) out vec2 uv_interp; +/* clang-format on */ + +void main() { + + vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0)); + uv_interp = base_arr[gl_VertexIndex]; + + gl_Position = vec4(uv_interp * 2.0 - 1.0, 0.0, 1.0); +} + +/* clang-format off */ +[fragment] + +#version 450 + +VERSION_DEFINES + +layout(location = 0) in vec2 uv_interp; +/* clang-format on */ + +layout(set = 0, binding = 0) uniform sampler2D specular; + +#ifdef MODE_SSR + +layout(set = 1, binding = 0) uniform sampler2D ssr; + +#endif + +#ifdef MODE_MERGE + +layout(set = 2, binding = 0) uniform sampler2D diffuse; + +#endif + +layout(location = 0) out vec4 frag_color; + +void main() { + + frag_color.rgb = texture(specular, uv_interp).rgb; + frag_color.a = 0.0; +#ifdef MODE_SSR + + vec4 ssr = texture(ssr, uv_interp); + frag_color.rgb = mix(frag_color.rgb, ssr.rgb, ssr.a); +#endif + +#ifdef MODE_MERGE + frag_color += texture(diffuse, uv_interp); +#endif + //added using additive blend +} diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index 3c1795161d..a3799b0e4d 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -30,14 +30,14 @@ #include "rendering_device.h" -RenderingDevice *RenderingDevice::singleton = NULL; +RenderingDevice *RenderingDevice::singleton = nullptr; RenderingDevice *RenderingDevice::get_singleton() { return singleton; } -RenderingDevice::ShaderCompileFunction RenderingDevice::compile_function = NULL; -RenderingDevice::ShaderCacheFunction RenderingDevice::cache_function = NULL; +RenderingDevice::ShaderCompileFunction RenderingDevice::compile_function = nullptr; +RenderingDevice::ShaderCacheFunction RenderingDevice::cache_function = nullptr; void RenderingDevice::shader_set_compile_function(ShaderCompileFunction p_function) { compile_function = p_function; diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h index 4705bcaa75..a639ff3641 100644 --- a/servers/rendering/rendering_device.h +++ b/servers/rendering/rendering_device.h @@ -563,7 +563,7 @@ public: /**** SHADER ****/ /****************/ - virtual Vector<uint8_t> shader_compile_from_source(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language = SHADER_LANGUAGE_GLSL, String *r_error = NULL, bool p_allow_cache = true); + virtual Vector<uint8_t> shader_compile_from_source(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language = SHADER_LANGUAGE_GLSL, String *r_error = nullptr, bool p_allow_cache = true); static void shader_set_compile_function(ShaderCompileFunction p_function); static void shader_set_cache_function(ShaderCacheFunction p_function); diff --git a/servers/rendering/rendering_server_canvas.cpp b/servers/rendering/rendering_server_canvas.cpp index 261bd4c275..5d6dcfd2c1 100644 --- a/servers/rendering/rendering_server_canvas.cpp +++ b/servers/rendering/rendering_server_canvas.cpp @@ -43,14 +43,14 @@ void RenderingServerCanvas::_render_canvas_item_tree(RID p_to_render_target, Can memset(z_last_list, 0, z_range * sizeof(RasterizerCanvas::Item *)); for (int i = 0; i < p_child_item_count; i++) { - _cull_canvas_item(p_child_items[i].item, p_transform, p_clip_rect, Color(1, 1, 1, 1), 0, z_list, z_last_list, NULL, NULL); + _cull_canvas_item(p_child_items[i].item, p_transform, p_clip_rect, Color(1, 1, 1, 1), 0, z_list, z_last_list, nullptr, nullptr); } if (p_canvas_item) { - _cull_canvas_item(p_canvas_item, p_transform, p_clip_rect, Color(1, 1, 1, 1), 0, z_list, z_last_list, NULL, NULL); + _cull_canvas_item(p_canvas_item, p_transform, p_clip_rect, Color(1, 1, 1, 1), 0, z_list, z_last_list, nullptr, nullptr); } - RasterizerCanvas::Item *list = NULL; - RasterizerCanvas::Item *list_end = NULL; + RasterizerCanvas::Item *list = nullptr; + RasterizerCanvas::Item *list_end = nullptr; for (int i = 0; i < z_range; i++) { if (!z_list[i]) @@ -78,7 +78,7 @@ void _collect_ysort_children(RenderingServerCanvas::Item *p_canvas_item, Transfo r_items[r_index] = child_items[i]; child_items[i]->ysort_xform = p_transform; child_items[i]->ysort_pos = p_transform.xform(child_items[i]->xform.elements[2]); - child_items[i]->material_owner = child_items[i]->use_parent_material ? p_material_owner : NULL; + child_items[i]->material_owner = child_items[i]->use_parent_material ? p_material_owner : nullptr; } r_index++; @@ -92,7 +92,7 @@ void _collect_ysort_children(RenderingServerCanvas::Item *p_canvas_item, Transfo void _mark_ysort_dirty(RenderingServerCanvas::Item *ysort_owner, RID_PtrOwner<RenderingServerCanvas::Item> &canvas_item_owner) { do { ysort_owner->ysort_children_count = -1; - ysort_owner = canvas_item_owner.owns(ysort_owner->parent) ? canvas_item_owner.getornull(ysort_owner->parent) : NULL; + ysort_owner = canvas_item_owner.owns(ysort_owner->parent) ? canvas_item_owner.getornull(ysort_owner->parent) : nullptr; } while (ysort_owner && ysort_owner->sort_y); } @@ -118,7 +118,7 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo ci->material_owner = p_material_owner; else { p_material_owner = ci; - ci->material_owner = NULL; + ci->material_owner = nullptr; } Color modulate(ci->modulate.r * p_modulate.r, ci->modulate.g * p_modulate.g, ci->modulate.b * p_modulate.b, ci->modulate.a * p_modulate.a); @@ -130,7 +130,7 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo Item **child_items = ci->child_items.ptrw(); if (ci->clip) { - if (p_canvas_clip != NULL) { + if (p_canvas_clip != nullptr) { ci->final_clip_rect = p_canvas_clip->final_clip_rect.clip(global_rect); } else { ci->final_clip_rect = global_rect; @@ -145,7 +145,7 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo if (ci->ysort_children_count == -1) { ci->ysort_children_count = 0; - _collect_ysort_children(ci, Transform2D(), p_material_owner, NULL, ci->ysort_children_count); + _collect_ysort_children(ci, Transform2D(), p_material_owner, nullptr, ci->ysort_children_count); } child_item_count = ci->ysort_children_count; @@ -183,7 +183,7 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo RenderingServerRaster::redraw_request(); } - if ((ci->commands != NULL && p_clip_rect.intersects(global_rect, true)) || ci->vp_render || ci->copy_back_buffer) { + if ((ci->commands != nullptr && p_clip_rect.intersects(global_rect, true)) || ci->vp_render || ci->copy_back_buffer) { //something to draw? ci->final_transform = xform; ci->final_modulate = Color(modulate.r * ci->self_modulate.r, modulate.g * ci->self_modulate.g, modulate.b * ci->self_modulate.b, modulate.a * ci->self_modulate.a); @@ -204,7 +204,7 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo ci->z_final = p_z; - ci->next = NULL; + ci->next = nullptr; } for (int i = 0; i < child_item_count; i++) { @@ -265,30 +265,30 @@ void RenderingServerCanvas::render_canvas(RID p_render_target, Canvas *p_canvas, if (!has_mirror) { - _render_canvas_item_tree(p_render_target, ci, l, NULL, p_transform, p_clip_rect, p_canvas->modulate, p_lights); + _render_canvas_item_tree(p_render_target, ci, l, nullptr, p_transform, p_clip_rect, p_canvas->modulate, p_lights); } else { //used for parallaxlayer mirroring for (int i = 0; i < l; i++) { const Canvas::ChildItem &ci2 = p_canvas->child_items[i]; - _render_canvas_item_tree(p_render_target, NULL, 0, ci2.item, p_transform, p_clip_rect, p_canvas->modulate, p_lights); + _render_canvas_item_tree(p_render_target, nullptr, 0, ci2.item, p_transform, p_clip_rect, p_canvas->modulate, p_lights); //mirroring (useful for scrolling backgrounds) if (ci2.mirror.x != 0) { Transform2D xform2 = p_transform * Transform2D(0, Vector2(ci2.mirror.x, 0)); - _render_canvas_item_tree(p_render_target, NULL, 0, ci2.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); + _render_canvas_item_tree(p_render_target, nullptr, 0, ci2.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); } if (ci2.mirror.y != 0) { Transform2D xform2 = p_transform * Transform2D(0, Vector2(0, ci2.mirror.y)); - _render_canvas_item_tree(p_render_target, NULL, 0, ci2.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); + _render_canvas_item_tree(p_render_target, nullptr, 0, ci2.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); } if (ci2.mirror.y != 0 && ci2.mirror.x != 0) { Transform2D xform2 = p_transform * Transform2D(0, ci2.mirror); - _render_canvas_item_tree(p_render_target, NULL, 0, ci2.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); + _render_canvas_item_tree(p_render_target, nullptr, 0, ci2.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); } } } @@ -946,12 +946,12 @@ void RenderingServerCanvas::canvas_item_set_copy_to_backbuffer(RID p_item, bool Item *canvas_item = canvas_item_owner.getornull(p_item); ERR_FAIL_COND(!canvas_item); - if (bool(canvas_item->copy_back_buffer != NULL) != p_enable) { + if (bool(canvas_item->copy_back_buffer != nullptr) != p_enable) { if (p_enable) { canvas_item->copy_back_buffer = memnew(RasterizerCanvas::Item::CopyBackBuffer); } else { memdelete(canvas_item->copy_back_buffer); - canvas_item->copy_back_buffer = NULL; + canvas_item->copy_back_buffer = nullptr; } } diff --git a/servers/rendering/rendering_server_canvas.h b/servers/rendering/rendering_server_canvas.h index c79b74f287..9da11462db 100644 --- a/servers/rendering/rendering_server_canvas.h +++ b/servers/rendering/rendering_server_canvas.h @@ -59,7 +59,7 @@ public: Item() { children_order_dirty = true; - E = NULL; + E = nullptr; z_index = 0; modulate = Color(1, 1, 1, 1); self_modulate = Color(1, 1, 1, 1); diff --git a/servers/rendering/rendering_server_globals.cpp b/servers/rendering/rendering_server_globals.cpp index 251cf64184..5a270520a9 100644 --- a/servers/rendering/rendering_server_globals.cpp +++ b/servers/rendering/rendering_server_globals.cpp @@ -30,11 +30,11 @@ #include "rendering_server_globals.h" -RasterizerStorage *RenderingServerGlobals::storage = NULL; -RasterizerCanvas *RenderingServerGlobals::canvas_render = NULL; -RasterizerScene *RenderingServerGlobals::scene_render = NULL; -Rasterizer *RenderingServerGlobals::rasterizer = NULL; +RasterizerStorage *RenderingServerGlobals::storage = nullptr; +RasterizerCanvas *RenderingServerGlobals::canvas_render = nullptr; +RasterizerScene *RenderingServerGlobals::scene_render = nullptr; +Rasterizer *RenderingServerGlobals::rasterizer = nullptr; -RenderingServerCanvas *RenderingServerGlobals::canvas = NULL; -RenderingServerViewport *RenderingServerGlobals::viewport = NULL; -RenderingServerScene *RenderingServerGlobals::scene = NULL; +RenderingServerCanvas *RenderingServerGlobals::canvas = nullptr; +RenderingServerViewport *RenderingServerGlobals::viewport = nullptr; +RenderingServerScene *RenderingServerGlobals::scene = nullptr; diff --git a/servers/rendering/rendering_server_raster.h b/servers/rendering/rendering_server_raster.h index 7c18bf91ce..8480aa30fc 100644 --- a/servers/rendering/rendering_server_raster.h +++ b/servers/rendering/rendering_server_raster.h @@ -523,7 +523,9 @@ public: #if 0 BIND2(environment_set_camera_feed_id, RID, int) #endif - BIND7(environment_set_ssr, RID, bool, int, float, float, float, bool) + BIND6(environment_set_ssr, RID, bool, int, float, float, float) + BIND1(environment_set_ssr_roughness_quality, EnvironmentSSRRoughnessQuality) + BIND9(environment_set_ssao, RID, bool, float, float, float, float, float, EnvironmentSSAOBlur, float) BIND2(environment_set_ssao_quality, EnvironmentSSAOQuality, bool) diff --git a/servers/rendering/rendering_server_scene.cpp b/servers/rendering/rendering_server_scene.cpp index 04e4b8dace..65823e11aa 100644 --- a/servers/rendering/rendering_server_scene.cpp +++ b/servers/rendering/rendering_server_scene.cpp @@ -194,7 +194,7 @@ void *RenderingServerScene::_instance_pair(void *p_self, OctreeElementID, Instan return gi_probe->lights.insert(A); } - return NULL; + return nullptr; } void RenderingServerScene::_instance_unpair(void *p_self, OctreeElementID, Instance *p_A, int, OctreeElementID, Instance *p_B, int, void *udata) { @@ -375,7 +375,7 @@ void RenderingServerScene::instance_set_base(RID p_instance, RID p_base) { #endif if (instance->scenario && light->D) { instance->scenario->directional_lights.erase(light->D); - light->D = NULL; + light->D = nullptr; } RSG::scene_render->free(light->instance); } break; @@ -416,7 +416,7 @@ void RenderingServerScene::instance_set_base(RID p_instance, RID p_base) { Instance *capture = (Instance *)instance->lightmap_capture; InstanceLightmapCaptureData *lightmap_capture = static_cast<InstanceLightmapCaptureData *>(capture->base_data); lightmap_capture->users.erase(instance); - instance->lightmap_capture = NULL; + instance->lightmap_capture = nullptr; instance->lightmap = RID(); } @@ -429,7 +429,7 @@ void RenderingServerScene::instance_set_base(RID p_instance, RID p_base) { if (instance->base_data) { memdelete(instance->base_data); - instance->base_data = NULL; + instance->base_data = nullptr; } instance->blend_values.clear(); @@ -533,7 +533,7 @@ void RenderingServerScene::instance_set_scenario(RID p_instance, RID p_scenario) #endif if (light->D) { instance->scenario->directional_lights.erase(light->D); - light->D = NULL; + light->D = nullptr; } } break; case RS::INSTANCE_REFLECTION_PROBE: { @@ -564,7 +564,7 @@ void RenderingServerScene::instance_set_scenario(RID p_instance, RID p_scenario) } } - instance->scenario = NULL; + instance->scenario = nullptr; } if (p_scenario.is_valid()) { @@ -720,7 +720,7 @@ void RenderingServerScene::instance_set_use_lightmap(RID p_instance, RID p_light InstanceLightmapCaptureData *lightmap_capture = static_cast<InstanceLightmapCaptureData *>(((Instance *)instance->lightmap_capture)->base_data); lightmap_capture->users.erase(instance); instance->lightmap = RID(); - instance->lightmap_capture = NULL; + instance->lightmap_capture = nullptr; } if (p_lightmap_instance.is_valid()) { @@ -744,16 +744,16 @@ void RenderingServerScene::instance_set_custom_aabb(RID p_instance, AABB p_aabb) if (p_aabb != AABB()) { // Set custom AABB - if (instance->custom_aabb == NULL) + if (instance->custom_aabb == nullptr) instance->custom_aabb = memnew(AABB); *instance->custom_aabb = p_aabb; } else { // Clear custom AABB - if (instance->custom_aabb != NULL) { + if (instance->custom_aabb != nullptr) { memdelete(instance->custom_aabb); - instance->custom_aabb = NULL; + instance->custom_aabb = nullptr; } } @@ -2259,7 +2259,7 @@ void RenderingServerScene::render_empty_scene(RID p_render_buffers, RID p_scenar else environment = scenario->fallback_environment; RENDER_TIMESTAMP("Render Empty Scene "); - RSG::scene_render->render_scene(p_render_buffers, Transform(), CameraMatrix(), true, NULL, 0, NULL, 0, NULL, 0, NULL, 0, environment, RID(), p_shadow_atlas, scenario->reflection_atlas, RID(), 0); + RSG::scene_render->render_scene(p_render_buffers, Transform(), CameraMatrix(), true, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, environment, RID(), p_shadow_atlas, scenario->reflection_atlas, RID(), 0); #endif } @@ -2827,7 +2827,7 @@ bool RenderingServerScene::free(RID p_rid) { return true; } -RenderingServerScene *RenderingServerScene::singleton = NULL; +RenderingServerScene *RenderingServerScene::singleton = nullptr; RenderingServerScene::RenderingServerScene() { diff --git a/servers/rendering/rendering_server_scene.h b/servers/rendering/rendering_server_scene.h index 9e09136216..41641b7c75 100644 --- a/servers/rendering/rendering_server_scene.h +++ b/servers/rendering/rendering_server_scene.h @@ -196,7 +196,7 @@ public: update_item(this) { octree_id = 0; - scenario = NULL; + scenario = nullptr; update_aabb = false; update_dependencies = false; @@ -213,9 +213,9 @@ public: last_render_pass = 0; last_frame_pass = 0; version = 1; - base_data = NULL; + base_data = nullptr; - custom_aabb = NULL; + custom_aabb = nullptr; } ~Instance() { @@ -301,9 +301,9 @@ public: InstanceLightData() { shadow_dirty = true; - D = NULL; + D = nullptr; last_version = 0; - baked_light = NULL; + baked_light = nullptr; } }; diff --git a/servers/rendering/rendering_server_viewport.cpp b/servers/rendering/rendering_server_viewport.cpp index f80b914760..aa65101ddf 100644 --- a/servers/rendering/rendering_server_viewport.cpp +++ b/servers/rendering/rendering_server_viewport.cpp @@ -67,7 +67,7 @@ void RenderingServerViewport::_draw_3d(Viewport *p_viewport, ARVRInterface::Eyes RENDER_TIMESTAMP(">Begin Rendering 3D Scene"); Ref<ARVRInterface> arvr_interface; - if (ARVRServer::get_singleton() != NULL) { + if (ARVRServer::get_singleton() != nullptr) { arvr_interface = ARVRServer::get_singleton()->get_primary_interface(); } @@ -128,9 +128,9 @@ void RenderingServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface Map<Viewport::CanvasKey, Viewport::CanvasData *> canvas_map; Rect2 clip_rect(0, 0, p_viewport->size.x, p_viewport->size.y); - RasterizerCanvas::Light *lights = NULL; - RasterizerCanvas::Light *lights_with_shadow = NULL; - RasterizerCanvas::Light *lights_with_mask = NULL; + RasterizerCanvas::Light *lights = nullptr; + RasterizerCanvas::Light *lights_with_shadow = nullptr; + RasterizerCanvas::Light *lights_with_mask = nullptr; Rect2 shadow_rect; int light_count = 0; @@ -160,7 +160,7 @@ void RenderingServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface cl->filter_next_ptr = lights; lights = cl; - // cl->texture_cache = NULL; + // cl->texture_cache = nullptr; Transform2D scale; scale.scale(cl->rect_cache.size); scale.elements[2] = cl->rect_cache.position; @@ -169,7 +169,7 @@ void RenderingServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface if (cl->use_shadow) { cl->shadows_next_ptr = lights_with_shadow; - if (lights_with_shadow == NULL) { + if (lights_with_shadow == nullptr) { shadow_rect = cl->xform_cache.xform(cl->rect_cache); } else { shadow_rect = shadow_rect.merge(cl->xform_cache.xform(cl->rect_cache)); @@ -196,7 +196,7 @@ void RenderingServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface if (lights_with_shadow) { //update shadows if any - RasterizerCanvas::LightOccluderInstance *occluders = NULL; + RasterizerCanvas::LightOccluderInstance *occluders = nullptr; RENDER_TIMESTAMP(">Render 2D Shadows"); RENDER_TIMESTAMP("Cull Occluders"); @@ -249,7 +249,7 @@ void RenderingServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface Transform2D xform = _canvas_get_transform(p_viewport, canvas, E->get(), clip_rect.size); - RasterizerCanvas::Light *canvas_lights = NULL; + RasterizerCanvas::Light *canvas_lights = nullptr; RasterizerCanvas::Light *ptr = lights; while (ptr) { @@ -297,7 +297,7 @@ void RenderingServerViewport::draw_viewports() { // get our arvr interface in case we need it Ref<ARVRInterface> arvr_interface; - if (ARVRServer::get_singleton() != NULL) { + if (ARVRServer::get_singleton() != nullptr) { arvr_interface = ARVRServer::get_singleton()->get_primary_interface(); // process all our active interfaces diff --git a/servers/rendering/rendering_server_wrap_mt.cpp b/servers/rendering/rendering_server_wrap_mt.cpp index 5d6d523901..aa3bf583c7 100644 --- a/servers/rendering/rendering_server_wrap_mt.cpp +++ b/servers/rendering/rendering_server_wrap_mt.cpp @@ -132,7 +132,7 @@ void RenderingServerWrapMT::finish() { Thread::wait_to_finish(thread); memdelete(thread); - thread = NULL; + thread = nullptr; } else { rendering_server->finish(); } @@ -168,7 +168,7 @@ void RenderingServerWrapMT::set_use_vsync_callback(bool p_enable) { singleton_mt->call_set_use_vsync(p_enable); } -RenderingServerWrapMT *RenderingServerWrapMT::singleton_mt = NULL; +RenderingServerWrapMT *RenderingServerWrapMT::singleton_mt = nullptr; RenderingServerWrapMT::RenderingServerWrapMT(RenderingServer *p_contained, bool p_create_thread) : command_queue(p_create_thread) { @@ -178,7 +178,7 @@ RenderingServerWrapMT::RenderingServerWrapMT(RenderingServer *p_contained, bool rendering_server = p_contained; create_thread = p_create_thread; - thread = NULL; + thread = nullptr; draw_pending = 0; draw_thread_up = false; pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc"); diff --git a/servers/rendering/rendering_server_wrap_mt.h b/servers/rendering/rendering_server_wrap_mt.h index bcd1344f44..13dad3ec18 100644 --- a/servers/rendering/rendering_server_wrap_mt.h +++ b/servers/rendering/rendering_server_wrap_mt.h @@ -437,7 +437,9 @@ public: #if 0 FUNC2(environment_set_camera_feed_id, RID, int) #endif - FUNC7(environment_set_ssr, RID, bool, int, float, float, float, bool) + FUNC6(environment_set_ssr, RID, bool, int, float, float, float) + FUNC1(environment_set_ssr_roughness_quality, EnvironmentSSRRoughnessQuality) + FUNC9(environment_set_ssao, RID, bool, float, float, float, float, float, EnvironmentSSAOBlur, float) FUNC2(environment_set_ssao_quality, EnvironmentSSAOQuality, bool) diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 300c38db22..76a81a4a1c 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -328,7 +328,7 @@ const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = { { TK_REPEAT_ENABLE, "repeat_enable" }, { TK_REPEAT_DISABLE, "repeat_disable" }, { TK_SHADER_TYPE, "shader_type" }, - { TK_ERROR, NULL } + { TK_ERROR, nullptr } }; ShaderLanguage::Token ShaderLanguage::_get_token() { @@ -879,7 +879,7 @@ void ShaderLanguage::clear() { current_function = StringName(); completion_type = COMPLETION_NONE; - completion_block = NULL; + completion_block = nullptr; completion_function = StringName(); completion_class = SubClassTag::TAG_GLOBAL; completion_struct = StringName(); @@ -913,7 +913,7 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea return true; } - FunctionNode *function = NULL; + FunctionNode *function = nullptr; while (p_block) { @@ -2107,14 +2107,14 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = { //array { "length", TYPE_INT, { TYPE_VOID }, TAG_ARRAY, true }, - { NULL, TYPE_VOID, { TYPE_VOID }, TAG_GLOBAL, false } + { nullptr, TYPE_VOID, { TYPE_VOID }, TAG_GLOBAL, false } }; const ShaderLanguage::BuiltinFuncOutArgs ShaderLanguage::builtin_func_out_args[] = { //constructors { "modf", 1 }, - { NULL, 0 } + { nullptr, 0 } }; bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, DataType *r_ret_type, StringName *r_ret_type_str) { @@ -3150,7 +3150,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons while (true) { - Node *expr = NULL; + Node *expr = nullptr; TkPos prepos = _get_tkpos(); Token tk = _get_token(); TkPos pos = _get_tkpos(); @@ -3162,14 +3162,14 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons expr = _parse_and_reduce_expression(p_block, p_builtin_types); if (!expr) - return NULL; + return nullptr; tk = _get_token(); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in expression"); - return NULL; + return nullptr; } } else if (tk.type == TK_REAL_CONSTANT) { @@ -3214,7 +3214,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons //make sure void is not used in expression _set_error("Void value not allowed in Expression"); - return NULL; + return nullptr; } else if (is_token_nonvoid_datatype(tk.type)) { //basic type constructor @@ -3234,7 +3234,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after type name"); - return NULL; + return nullptr; } int carg = -1; @@ -3250,11 +3250,11 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } if (!ok) - return NULL; + return nullptr; if (!_validate_function_call(p_block, p_builtin_types, func, &func->return_cache, &func->struct_name)) { _set_error("No matching constructor found for: '" + String(funcname->name) + "'"); - return NULL; + return nullptr; } expr = _reduce_expression(p_block, func); @@ -3265,7 +3265,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons StringName identifier; - StructNode *pstruct = NULL; + StructNode *pstruct = nullptr; bool struct_init = false; _get_completable_identifier(p_block, COMPLETION_IDENTIFIER, identifier); @@ -3317,7 +3317,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } else { if (!is_token_variable_datatype(tk.type)) { _set_error("Invalid data type for array"); - return NULL; + return nullptr; } type2 = get_token_datatype(tk.type); } @@ -3335,7 +3335,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons Node *n = _parse_and_reduce_expression(p_block, p_builtin_types); if (!n || n->type != Node::TYPE_CONSTANT || n->get_datatype() != TYPE_INT) { _set_error("Expected single integer constant > 0"); - return NULL; + return nullptr; } ConstantNode *cnode = (ConstantNode *)n; @@ -3343,24 +3343,24 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons array_size2 = cnode->values[0].sint; if (array_size2 <= 0) { _set_error("Expected single integer constant > 0"); - return NULL; + return nullptr; } } else { _set_error("Expected single integer constant > 0"); - return NULL; + return nullptr; } tk = _get_token(); if (tk.type != TK_BRACKET_CLOSE) { _set_error("Expected ']'"); - return NULL; + return nullptr; } else { tk = _get_token(); } } } else { _set_error("Expected '['"); - return NULL; + return nullptr; } if (type != type2 || struct_name != struct_name2 || array_size != array_size2) { @@ -3383,7 +3383,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons error_str += itos(array_size); error_str += "]'"; _set_error(error_str); - return NULL; + return nullptr; } } @@ -3396,12 +3396,12 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons Node *n = _parse_and_reduce_expression(p_block, p_builtin_types); if (!n) { - return NULL; + return nullptr; } if (type != n->get_datatype() || struct_name != n->get_datatype_name()) { _set_error("Invalid assignment of '" + (n->get_datatype() == TYPE_STRUCT ? n->get_datatype_name() : get_datatype_name(n->get_datatype())) + "' to '" + (type == TYPE_STRUCT ? struct_name : get_datatype_name(type)) + "'"); - return NULL; + return nullptr; } tk = _get_token(); @@ -3419,30 +3419,30 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons _set_error("Expected '}' or ','"); else _set_error("Expected ')' or ','"); - return NULL; + return nullptr; } } if (an->initializer.size() != array_size) { _set_error("Array size mismatch"); - return NULL; + return nullptr; } } else { _set_error("Expected array initialization!"); - return NULL; + return nullptr; } nexpr = an; } else { nexpr = _parse_and_reduce_expression(p_block, p_builtin_types); if (!nexpr) { - return NULL; + return nullptr; } Node *node = pstruct->members[i]; if (!_compare_datatypes_in_nodes(pstruct->members[i], nexpr)) { String type_name = nexpr->get_datatype() == TYPE_STRUCT ? nexpr->get_datatype_name() : get_datatype_name(nexpr->get_datatype()); String type_name2 = node->get_datatype() == TYPE_STRUCT ? node->get_datatype_name() : get_datatype_name(node->get_datatype()); _set_error("Invalid assignment of '" + type_name + "' to '" + type_name2 + "'"); - return NULL; + return nullptr; } } @@ -3450,7 +3450,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons tk = _get_token(); if (tk.type != TK_COMMA) { _set_error("Expected ','"); - return NULL; + return nullptr; } } func->arguments.push_back(nexpr); @@ -3458,7 +3458,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons tk = _get_token(); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')'"); - return NULL; + return nullptr; } expr = func; @@ -3482,7 +3482,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons while (bnode) { if (bnode->variables.has(name)) { _set_error("Expected function name"); - return NULL; + return nullptr; } bnode = bnode->parent_block; } @@ -3514,11 +3514,11 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } if (!ok) - return NULL; + return nullptr; if (!_validate_function_call(p_block, p_builtin_types, func, &func->return_cache, &func->struct_name)) { _set_error("No matching function found for: '" + String(funcname->name) + "'"); - return NULL; + return nullptr; } completion_class = TAG_GLOBAL; // reset sub-class if (function_index >= 0) { @@ -3529,7 +3529,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (call_function) { //get current base function - FunctionNode *base_function = NULL; + FunctionNode *base_function = nullptr; { BlockNode *b = p_block; @@ -3544,7 +3544,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } } - ERR_FAIL_COND_V(!base_function, NULL); //bug, wtf + ERR_FAIL_COND_V(!base_function, nullptr); //bug, wtf for (int i = 0; i < call_function->arguments.size(); i++) { int argidx = i + 1; @@ -3556,7 +3556,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons error = true; } else if (n->type == Node::TYPE_ARRAY) { ArrayNode *an = static_cast<ArrayNode *>(n); - if (an->call_expression != NULL) { + if (an->call_expression != nullptr) { error = true; } } else if (n->type == Node::TYPE_VARIABLE) { @@ -3584,7 +3584,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } if (error) { _set_error(vformat("Constant value cannot be passed for '%s' parameter!", _get_qualifier_str(call_function->arguments[i].qualifier))); - return NULL; + return nullptr; } } if (is_sampler_type(call_function->arguments[i].type)) { @@ -3599,12 +3599,12 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons ERR_CONTINUE(u->type != call_function->arguments[i].type); //this should have been validated previously //propagate if (!_propagate_function_call_sampler_uniform_settings(name, i, u->filter, u->repeat)) { - return NULL; + return nullptr; } } else if (p_builtin_types.has(varname)) { //a built-in if (!_propagate_function_call_sampler_builtin_reference(name, i, varname)) { - return NULL; + return nullptr; } } else { //or this comes from an argument, but nothing else can be a sampler @@ -3653,30 +3653,30 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } if (!found) { _set_error("Unknown identifier in expression: " + String(identifier)); - return NULL; + return nullptr; } } else { if (!_find_identifier(p_block, false, p_builtin_types, identifier, &data_type, &ident_type, &is_const, &array_size, &struct_name)) { _set_error("Unknown identifier in expression: " + String(identifier)); - return NULL; + return nullptr; } if (ident_type == IDENTIFIER_FUNCTION) { _set_error("Can't use function as identifier: " + String(identifier)); - return NULL; + return nullptr; } } - Node *index_expression = NULL; - Node *call_expression = NULL; + Node *index_expression = nullptr; + Node *call_expression = nullptr; if (array_size > 0) { tk = _get_token(); if (tk.type != TK_BRACKET_OPEN && tk.type != TK_PERIOD) { _set_error("Expected '[' or '.'"); - return NULL; + return nullptr; } if (tk.type == TK_PERIOD) { @@ -3685,17 +3685,17 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons call_expression = _parse_and_reduce_expression(p_block, p_builtin_types); p_block->block_tag = SubClassTag::TAG_GLOBAL; if (!call_expression) - return NULL; + return nullptr; data_type = call_expression->get_datatype(); } else { // indexing index_expression = _parse_and_reduce_expression(p_block, p_builtin_types); if (!index_expression) - return NULL; + return nullptr; if (index_expression->get_datatype() != TYPE_INT && index_expression->get_datatype() != TYPE_UINT) { _set_error("Only integer expressions are allowed for indexing"); - return NULL; + return nullptr; } if (index_expression->type == Node::TYPE_CONSTANT) { @@ -3705,7 +3705,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons int value = cnode->values[0].sint; if (value < 0 || value >= array_size) { _set_error(vformat("Index [%s] out of range [%s..%s]", value, 0, array_size - 1)); - return NULL; + return nullptr; } } } @@ -3714,7 +3714,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons tk = _get_token(); if (tk.type != TK_BRACKET_CLOSE) { _set_error("Expected ']'"); - return NULL; + return nullptr; } } @@ -3750,18 +3750,18 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons case TK_OP_BIT_INVERT: e.op = OP_BIT_INVERT; break; case TK_OP_INCREMENT: e.op = OP_INCREMENT; break; case TK_OP_DECREMENT: e.op = OP_DECREMENT; break; - default: ERR_FAIL_V(NULL); + default: ERR_FAIL_V(nullptr); } expression.push_back(e); continue; } else { _set_error("Expected expression, found: " + get_token_text(tk)); - return NULL; + return nullptr; //nothing } - ERR_FAIL_COND_V(!expr, NULL); + ERR_FAIL_COND_V(!expr, nullptr); /* OK now see what's NEXT to the operator.. */ /* OK now see what's NEXT to the operator.. */ @@ -3791,7 +3791,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (identifier == StringName()) { _set_error("Expected identifier as member"); - return NULL; + return nullptr; } String ident = identifier; @@ -4042,12 +4042,12 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (mix_error) { _set_error("Cannot combine symbols from different sets in expression ." + ident); - return NULL; + return nullptr; } if (!ok) { _set_error("Invalid member for " + (dt == TYPE_STRUCT ? st : get_datatype_name(dt)) + " expression: ." + ident); - return NULL; + return nullptr; } MemberNode *mn = alloc_node<MemberNode>(); @@ -4066,16 +4066,16 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons tk = _get_token(); if (tk.type == TK_PERIOD) { _set_error("Nested array length() is not yet implemented"); - return NULL; + return nullptr; } else if (tk.type == TK_BRACKET_OPEN) { Node *index_expression = _parse_and_reduce_expression(p_block, p_builtin_types); if (!index_expression) - return NULL; + return nullptr; if (index_expression->get_datatype() != TYPE_INT && index_expression->get_datatype() != TYPE_UINT) { _set_error("Only integer expressions are allowed for indexing"); - return NULL; + return nullptr; } if (index_expression->type == Node::TYPE_CONSTANT) { @@ -4085,7 +4085,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons int value = cnode->values[0].sint; if (value < 0 || value >= array_size) { _set_error(vformat("Index [%s] out of range [%s..%s]", value, 0, array_size - 1)); - return NULL; + return nullptr; } } } @@ -4094,13 +4094,13 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons tk = _get_token(); if (tk.type != TK_BRACKET_CLOSE) { _set_error("Expected ']'"); - return NULL; + return nullptr; } mn->index_expression = index_expression; } else { _set_error("Expected '[' or '.'"); - return NULL; + return nullptr; } } @@ -4120,11 +4120,11 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons Node *index = _parse_and_reduce_expression(p_block, p_builtin_types); if (!index) - return NULL; + return nullptr; if (index->get_datatype() != TYPE_INT && index->get_datatype() != TYPE_UINT) { _set_error("Only integer datatypes are allowed for indexing"); - return NULL; + return nullptr; } DataType member_type = TYPE_VOID; @@ -4139,7 +4139,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint; if (index_constant >= 2) { _set_error("Index out of range (0-1)"); - return NULL; + return nullptr; } } @@ -4162,7 +4162,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint; if (index_constant >= 3) { _set_error("Index out of range (0-2)"); - return NULL; + return nullptr; } } @@ -4184,7 +4184,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint; if (index_constant >= 4) { _set_error("Index out of range (0-3)"); - return NULL; + return nullptr; } } @@ -4199,7 +4199,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons break; default: { _set_error("Object of type '" + (expr->get_datatype() == TYPE_STRUCT ? expr->get_datatype_name() : get_datatype_name(expr->get_datatype())) + "' can't be indexed"); - return NULL; + return nullptr; } } @@ -4213,7 +4213,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons tk = _get_token(); if (tk.type != TK_BRACKET_CLOSE) { _set_error("Expected ']' after indexing expression"); - return NULL; + return nullptr; } } else if (tk.type == TK_OP_INCREMENT || tk.type == TK_OP_DECREMENT) { @@ -4224,12 +4224,12 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (!_validate_operator(op, &op->return_cache)) { _set_error("Invalid base type for increment/decrement operator"); - return NULL; + return nullptr; } if (!_validate_assign(expr, p_builtin_types)) { _set_error("Invalid use of increment/decrement operator in constant expression."); - return NULL; + return nullptr; } expr = op; } else { @@ -4287,7 +4287,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons case TK_COLON: o.op = OP_SELECT_ELSE; break; default: { _set_error("Invalid token for operator: " + get_token_text(tk)); - return NULL; + return nullptr; } } @@ -4379,7 +4379,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons break; default: - ERR_FAIL_V(NULL); //unexpected operator + ERR_FAIL_V(nullptr); //unexpected operator } if (priority < min_priority) { @@ -4392,7 +4392,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } } - ERR_FAIL_COND_V(next_op == -1, NULL); + ERR_FAIL_COND_V(next_op == -1, nullptr); // OK! create operator.. // OK! create operator.. @@ -4405,7 +4405,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (expr_pos == expression.size()) { //can happen.. _set_error("Unexpected end of expression..."); - return NULL; + return nullptr; } } @@ -4417,7 +4417,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if ((op->op == OP_INCREMENT || op->op == OP_DECREMENT) && !_validate_assign(expression[i + 1].node, p_builtin_types)) { _set_error("Can't use increment/decrement operator in constant expression."); - return NULL; + return nullptr; } op->arguments.push_back(expression[i + 1].node); @@ -4433,7 +4433,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons at += get_datatype_name(op->arguments[j]->get_datatype()); } _set_error("Invalid arguments to unary operator '" + get_operator_text(op->op) + "' :" + at); - return NULL; + return nullptr; } expression.remove(i + 1); } @@ -4442,12 +4442,12 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } if (next_op + 2 >= expression.size() || !expression[next_op + 2].is_op || expression[next_op + 2].op != OP_SELECT_ELSE) { _set_error("Missing matching ':' for select operator"); - return NULL; + return nullptr; } OperatorNode *op = alloc_node<OperatorNode>(); @@ -4467,7 +4467,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons at += get_datatype_name(op->arguments[i]->get_datatype()); } _set_error("Invalid argument to ternary ?: operator: " + at); - return NULL; + return nullptr; } for (int i = 0; i < 4; i++) { @@ -4478,7 +4478,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } OperatorNode *op = alloc_node<OperatorNode>(); @@ -4487,7 +4487,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (expression[next_op - 1].is_op) { _set_error("Parser bug..."); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } if (_is_operator_assign(op->op)) { @@ -4496,7 +4496,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (!_validate_assign(expression[next_op - 1].node, p_builtin_types, &assign_message)) { _set_error(assign_message); - return NULL; + return nullptr; } } @@ -4528,7 +4528,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } } _set_error("Invalid arguments to operator '" + get_operator_text(op->op) + "' :" + at); - return NULL; + return nullptr; } expression.remove(next_op); @@ -4658,7 +4658,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_and_reduce_expression(BlockNode *p_ ShaderLanguage::Node *expr = _parse_expression(p_block, p_builtin_types); if (!expr) //errored - return NULL; + return nullptr; expr = _reduce_expression(p_block, expr); @@ -4741,7 +4741,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui tk = _get_token(); - Node *vardecl = NULL; + Node *vardecl = nullptr; while (true) { @@ -4752,7 +4752,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui StringName name = tk.text; ShaderLanguage::IdentifierType itype; - if (_find_identifier(p_block, true, p_builtin_types, name, (ShaderLanguage::DataType *)0, &itype)) { + if (_find_identifier(p_block, true, p_builtin_types, name, (ShaderLanguage::DataType *)nullptr, &itype)) { if (itype != IDENTIFIER_FUNCTION) { _set_error("Redefinition of '" + String(name) + "'"); return ERR_PARSE_ERROR; @@ -5025,7 +5025,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui VariableDeclarationNode::Declaration decl; decl.name = name; - decl.initializer = NULL; + decl.initializer = nullptr; //variable created with assignment! must parse an expression Node *n = _parse_and_reduce_expression(p_block, p_builtin_types); @@ -5061,7 +5061,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui VariableDeclarationNode::Declaration decl; decl.name = name; - decl.initializer = NULL; + decl.initializer = nullptr; node->declarations.push_back(decl); } @@ -5326,7 +5326,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui // while() {} bool is_do = tk.type == TK_CF_DO; - BlockNode *do_block = NULL; + BlockNode *do_block = nullptr; if (is_do) { do_block = alloc_node<BlockNode>(); @@ -5694,7 +5694,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct while (true) { StringName mode; - _get_completable_identifier(NULL, COMPLETION_RENDER_MODE, mode); + _get_completable_identifier(nullptr, COMPLETION_RENDER_MODE, mode); if (mode == StringName()) { _set_error("Expected identifier for render mode"); @@ -5898,7 +5898,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct name = tk.text; - if (_find_identifier(NULL, false, Map<StringName, BuiltInInfo>(), name)) { + if (_find_identifier(nullptr, false, Map<StringName, BuiltInInfo>(), name)) { _set_error("Redefinition of '" + String(name) + "'"); return ERR_PARSE_ERROR; } @@ -6074,7 +6074,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (tk.type == TK_OP_ASSIGN) { - Node *expr = _parse_and_reduce_expression(NULL, Map<StringName, BuiltInInfo>()); + Node *expr = _parse_and_reduce_expression(nullptr, Map<StringName, BuiltInInfo>()); if (!expr) return ERR_PARSE_ERROR; if (expr->type != Node::TYPE_CONSTANT) { @@ -6191,14 +6191,14 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } _set_tkpos(prev_pos); - _get_completable_identifier(NULL, COMPLETION_MAIN_FUNCTION, name); + _get_completable_identifier(nullptr, COMPLETION_MAIN_FUNCTION, name); if (name == StringName()) { _set_error("Expected function name after datatype"); return ERR_PARSE_ERROR; } - if (_find_identifier(NULL, false, Map<StringName, BuiltInInfo>(), name)) { + if (_find_identifier(nullptr, false, Map<StringName, BuiltInInfo>(), name)) { _set_error("Redefinition of '" + String(name) + "'"); return ERR_PARSE_ERROR; } @@ -6222,7 +6222,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct constant.type = is_struct ? TYPE_STRUCT : type; constant.type_str = struct_name; constant.precision = precision; - constant.initializer = NULL; + constant.initializer = nullptr; if (tk.type == TK_OP_ASSIGN) { @@ -6232,7 +6232,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } //variable created with assignment! must parse an expression - Node *expr = _parse_and_reduce_expression(NULL, Map<StringName, BuiltInInfo>()); + Node *expr = _parse_and_reduce_expression(nullptr, Map<StringName, BuiltInInfo>()); if (!expr) return ERR_PARSE_ERROR; if (expr->type == Node::TYPE_OPERATOR && ((OperatorNode *)expr)->op == OP_CALL) { @@ -6266,7 +6266,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } name = tk.text; - if (_find_identifier(NULL, false, Map<StringName, BuiltInInfo>(), name)) { + if (_find_identifier(nullptr, false, Map<StringName, BuiltInInfo>(), name)) { _set_error("Redefinition of '" + String(name) + "'"); return ERR_PARSE_ERROR; } @@ -6405,7 +6405,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct pname = tk.text; ShaderLanguage::IdentifierType itype; - if (_find_identifier(func_node->body, false, builtin_types, pname, (ShaderLanguage::DataType *)0, &itype)) { + if (_find_identifier(func_node->body, false, builtin_types, pname, (ShaderLanguage::DataType *)nullptr, &itype)) { if (itype != IDENTIFIER_FUNCTION) { _set_error("Redefinition of '" + String(pname) + "'"); return ERR_PARSE_ERROR; @@ -6645,7 +6645,7 @@ Error ShaderLanguage::compile(const String &p_code, const Map<StringName, Functi code = p_code; - nodes = NULL; + nodes = nullptr; shader = alloc_node<ShaderNode>(); Error err = _parse_shader(p_functions, p_render_modes, p_shader_types); @@ -6662,7 +6662,7 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct code = p_code; - nodes = NULL; + nodes = nullptr; shader = alloc_node<ShaderNode>(); _parse_shader(p_functions, p_render_modes, p_shader_types); @@ -7001,7 +7001,7 @@ ShaderLanguage::ShaderNode *ShaderLanguage::get_shader() { ShaderLanguage::ShaderLanguage() { - nodes = NULL; + nodes = nullptr; completion_class = TAG_GLOBAL; } diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index 9124bee633..beabae0dda 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -342,7 +342,7 @@ public: virtual String get_datatype_name() const { return ""; } Node(Type t) : - next(NULL), + next(nullptr), type(t) {} virtual ~Node() {} }; @@ -423,8 +423,8 @@ public: ArrayNode() : Node(TYPE_ARRAY), datatype_cache(TYPE_VOID), - index_expression(NULL), - call_expression(NULL), + index_expression(nullptr), + call_expression(nullptr), is_const(false) {} }; @@ -511,8 +511,8 @@ public: BlockNode() : Node(TYPE_BLOCK), - parent_function(NULL), - parent_block(NULL), + parent_function(nullptr), + parent_block(nullptr), block_type(BLOCK_TYPE_STANDART), block_tag(SubClassTag::TAG_GLOBAL), single_statement(false) {} @@ -550,8 +550,8 @@ public: basetype_const(false), datatype(TYPE_VOID), array_size(0), - owner(NULL), - index_expression(NULL), + owner(nullptr), + index_expression(nullptr), has_swizzling_duplicates(false) {} }; @@ -592,7 +592,7 @@ public: Node(TYPE_FUNCTION), return_type(TYPE_VOID), return_precision(PRECISION_DEFAULT), - body(NULL), + body(nullptr), can_discard(false) {} }; @@ -733,7 +733,7 @@ public: static bool is_token_nonvoid_datatype(TokenType p_type); static bool is_token_operator(TokenType p_type); - static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = NULL); + static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = nullptr); static DataType get_scalar_type(DataType p_type); static int get_cardinality(DataType p_type); static bool is_scalar_type(DataType p_type); @@ -825,10 +825,10 @@ private: IDENTIFIER_CONSTANT, }; - bool _find_identifier(const BlockNode *p_block, bool p_allow_reassign, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type = NULL, IdentifierType *r_type = NULL, bool *r_is_const = NULL, int *r_array_size = NULL, StringName *r_struct_name = NULL); + bool _find_identifier(const BlockNode *p_block, bool p_allow_reassign, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type = nullptr, IdentifierType *r_type = nullptr, bool *r_is_const = nullptr, int *r_array_size = nullptr, StringName *r_struct_name = nullptr); bool _is_operator_assign(Operator p_op) const; - bool _validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types, String *r_message = NULL); - bool _validate_operator(OperatorNode *p_op, DataType *r_ret_type = NULL); + bool _validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types, String *r_message = nullptr); + bool _validate_operator(OperatorNode *p_op, DataType *r_ret_type = nullptr); struct BuiltinFuncDef { enum { MAX_ARGS = 5 }; @@ -861,7 +861,7 @@ private: bool _compare_datatypes_in_nodes(Node *a, Node *b) const; bool _validate_function_call(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, DataType *r_ret_type, StringName *r_ret_type_str); - bool _parse_function_arguments(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, int *r_complete_arg = NULL); + bool _parse_function_arguments(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, int *r_complete_arg = nullptr); bool _propagate_function_call_sampler_uniform_settings(StringName p_name, int p_argument, TextureFilter p_filter, TextureRepeat p_repeat); bool _propagate_function_call_sampler_builtin_reference(StringName p_name, int p_argument, const StringName &p_builtin); diff --git a/servers/rendering/shader_types.cpp b/servers/rendering/shader_types.cpp index b144d6d612..ba7b992e51 100644 --- a/servers/rendering/shader_types.cpp +++ b/servers/rendering/shader_types.cpp @@ -44,7 +44,7 @@ const Set<String> &ShaderTypes::get_types() { return shader_types; } -ShaderTypes *ShaderTypes::singleton = NULL; +ShaderTypes *ShaderTypes::singleton = nullptr; static ShaderLanguage::BuiltInInfo constt(ShaderLanguage::DataType p_type) { diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index a960efb272..55afd78fda 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -33,8 +33,8 @@ #include "core/method_bind_ext.gen.inc" #include "core/project_settings.h" -RenderingServer *RenderingServer::singleton = NULL; -RenderingServer *(*RenderingServer::create_func)() = NULL; +RenderingServer *RenderingServer::singleton = nullptr; +RenderingServer *(*RenderingServer::create_func)() = nullptr; RenderingServer *RenderingServer::get_singleton() { @@ -43,12 +43,12 @@ RenderingServer *RenderingServer::get_singleton() { RenderingServer *RenderingServer::create() { - ERR_FAIL_COND_V(singleton, NULL); + ERR_FAIL_COND_V(singleton, nullptr); if (create_func) return create_func(); - return NULL; + return nullptr; } Array RenderingServer::_texture_debug_usage_bind() { @@ -333,7 +333,7 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint uint8_t *vw = r_vertex_array.ptrw(); - uint8_t *iw = NULL; + uint8_t *iw = nullptr; if (r_index_array.size()) { iw = r_index_array.ptrw(); } @@ -1802,10 +1802,10 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "energy"), &RenderingServer::environment_set_bg_energy); ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &RenderingServer::environment_set_canvas_max_layer); ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "ambient", "energy", "sky_contibution", "reflection_source", "ao_color"), &RenderingServer::environment_set_ambient_light, DEFVAL(RS::ENV_AMBIENT_SOURCE_BG), DEFVAL(1.0), DEFVAL(0.0), DEFVAL(RS::ENV_REFLECTION_SOURCE_BG), DEFVAL(Color())); - ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "level_flags", "intensity", "strength", "mix", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap", "bicubic_upscale"), &RenderingServer::environment_set_glow); + ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "level_flags", "intensity", "strength", "mix", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap"), &RenderingServer::environment_set_glow); ClassDB::bind_method(D_METHOD("environment_set_tonemap", "env", "tone_mapper", "exposure", "white", "auto_exposure", "min_luminance", "max_luminance", "auto_exp_speed", "auto_exp_grey"), &RenderingServer::environment_set_tonemap); ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "ramp"), &RenderingServer::environment_set_adjustment); - ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance", "roughness"), &RenderingServer::environment_set_ssr); + ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance"), &RenderingServer::environment_set_ssr); ClassDB::bind_method(D_METHOD("environment_set_ssao", "env", "enable", "radius", "intensity", "bias", "light_affect", "ao_channel_affect", "blur", "bilateral_sharpness"), &RenderingServer::environment_set_ssao); ClassDB::bind_method(D_METHOD("environment_set_fog", "env", "enable", "color", "sun_color", "sun_amount"), &RenderingServer::environment_set_fog); @@ -2359,9 +2359,12 @@ RenderingServer::RenderingServer() { GLOBAL_DEF("rendering/quality/glow/upscale_mode", 1); ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/glow/upscale_mode", PropertyInfo(Variant::INT, "rendering/quality/glow/upscale_mode", PROPERTY_HINT_ENUM, "Linear (Fast),Bicubic (Slower)")); GLOBAL_DEF("rendering/quality/glow/upscale_mode.mobile", 0); + + GLOBAL_DEF("rendering/quality/screen_space_reflection/roughness_quality", 1); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/screen_space_reflection/roughness_quality", PropertyInfo(Variant::INT, "rendering/quality/screen_space_reflection/roughness_quality", PROPERTY_HINT_ENUM, "Disabled (Fastest),Low, Medium, High (Slowest)")); } RenderingServer::~RenderingServer() { - singleton = NULL; + singleton = nullptr; } diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 702a66405a..9726a71f0c 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -747,7 +747,16 @@ public: virtual void environment_set_tonemap(RID p_env, EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_grey) = 0; virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) = 0; - virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness) = 0; + virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance) = 0; + + enum EnvironmentSSRRoughnessQuality { + ENV_SSR_ROUGNESS_QUALITY_DISABLED, + ENV_SSR_ROUGNESS_QUALITY_LOW, + ENV_SSR_ROUGNESS_QUALITY_MEDIUM, + ENV_SSR_ROUGNESS_QUALITY_HIGH, + }; + + virtual void environment_set_ssr_roughness_quality(EnvironmentSSRRoughnessQuality p_quality) = 0; enum EnvironmentSSAOBlur { ENV_SSAO_BLUR_DISABLED, |