From 3f095ca2c275a4dcd50890a7acfed60ee1a84706 Mon Sep 17 00:00:00 2001 From: matheusmdx Date: Thu, 24 Oct 2024 21:39:55 -0300 Subject: [PATCH] Print a warning when using sky with transparent background active --- scene/3d/world_environment.cpp | 37 +++++++++++++++++++++++++++++---- scene/3d/world_environment.h | 2 ++ scene/resources/environment.cpp | 4 ++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp index 82b7c160a4cc..3c3d038333d2 100644 --- a/scene/3d/world_environment.cpp +++ b/scene/3d/world_environment.cpp @@ -30,6 +30,7 @@ #include "world_environment.h" +#include "core/config/project_settings.h" #include "scene/3d/node_3d.h" #include "scene/main/window.h" @@ -37,6 +38,8 @@ void WorldEnvironment::_notification(int p_what) { switch (p_what) { case Node3D::NOTIFICATION_ENTER_WORLD: case Node3D::NOTIFICATION_ENTER_TREE: { + _check_sky_warning(); + if (environment.is_valid()) { add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); _update_current_environment(); @@ -110,14 +113,20 @@ void WorldEnvironment::set_environment(const Ref &p_environment) { if (environment == p_environment) { return; } - if (is_inside_tree() && environment.is_valid()) { - remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + if (environment.is_valid()) { + environment->disconnect(StringName("sky_changed"), callable_mp(this, &WorldEnvironment::_check_sky_warning)); + if (is_inside_tree()) { + remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + } } environment = p_environment; - if (is_inside_tree() && environment.is_valid()) { - add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + if (environment.is_valid()) { + environment->connect(StringName("sky_changed"), callable_mp(this, &WorldEnvironment::_check_sky_warning)); + if (is_inside_tree()) { + add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + } } if (is_inside_tree()) { @@ -207,6 +216,20 @@ PackedStringArray WorldEnvironment::get_configuration_warnings() const { return warnings; } +void WorldEnvironment::_check_sky_warning() { + if ((environment.is_valid() && !environment->get_sky().is_valid()) || !is_inside_tree()) { + return; + } + Viewport *viewport = get_viewport(); + if (viewport->get_parent_viewport() == get_tree()->get_root() || String(get_name()).begins_with("@")) { + if (GLOBAL_GET("rendering/viewport/transparent_background")) { + WARN_PRINT("Environment sky will not render when transparent background is active in project settings."); + } + } else if (viewport->has_transparent_background()) { + WARN_PRINT("Environment sky will not render when transparent background is active in subviewport."); + } +} + void WorldEnvironment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_environment", "env"), &WorldEnvironment::set_environment); ClassDB::bind_method(D_METHOD("get_environment"), &WorldEnvironment::get_environment); @@ -223,3 +246,9 @@ void WorldEnvironment::_bind_methods() { WorldEnvironment::WorldEnvironment() { } + +WorldEnvironment::~WorldEnvironment() { + if (environment.is_valid() && !environment->get_sky().is_valid()) { + environment->disconnect(StringName("sky_changed"), callable_mp(this, &WorldEnvironment::_check_sky_warning)); + } +} diff --git a/scene/3d/world_environment.h b/scene/3d/world_environment.h index 53a695d7de4f..f17d161bd8a4 100644 --- a/scene/3d/world_environment.h +++ b/scene/3d/world_environment.h @@ -46,6 +46,7 @@ class WorldEnvironment : public Node { void _update_current_environment(); void _update_current_camera_attributes(); void _update_current_compositor(); + void _check_sky_warning(); protected: void _notification(int p_what); @@ -64,6 +65,7 @@ class WorldEnvironment : public Node { PackedStringArray get_configuration_warnings() const override; WorldEnvironment(); + ~WorldEnvironment(); }; #endif // WORLD_ENVIRONMENT_H diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index f8c70c3002aa..3182788fb652 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -59,6 +59,7 @@ void Environment::set_sky(const Ref &p_sky) { if (bg_sky.is_valid()) { sb_rid = bg_sky->get_rid(); } + emit_signal(StringName("sky_changed")); RS::get_singleton()->environment_set_sky(environment, sb_rid); } @@ -1596,6 +1597,9 @@ void Environment::_bind_methods() { BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_50_PERCENT); BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_75_PERCENT); BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_100_PERCENT); + + // Signals + ADD_SIGNAL(MethodInfo("sky_changed")); } Environment::Environment() {