From 65465f309c5666bf98976829e223f5a6d3e5cd27 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sat, 17 Dec 2022 23:30:16 +0100 Subject: [PATCH] Add a project setting to make the root viewport transparent This allows creating a project with a transparent window without having to write any script. --- doc/classes/OS.xml | 2 +- doc/classes/ProjectSettings.xml | 7 ++++++- editor/plugins/spatial_editor_plugin.cpp | 5 ++++- scene/main/scene_tree.cpp | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index a743e89364c..776f71a0e70 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -1204,7 +1204,7 @@ If [code]true[/code], the window background is transparent and the window frame is removed. - Use [code]get_tree().get_root().set_transparent_background(true)[/code] to disable main viewport background rendering. + Enable [member ProjectSettings.rendering/viewport/transparent_background] or call [code]get_tree().get_root().set_transparent_background(true)[/code] to disable background rendering on the root [Viewport]. [b]Note:[/b] This property has no effect if [member ProjectSettings.display/window/per_pixel_transparency/allowed] setting is disabled. [b]Note:[/b] This property is implemented on HTML5, Linux, macOS, Windows, and Android. It can't be changed at runtime for Android. Use [member ProjectSettings.display/window/per_pixel_transparency/enabled] to set it at startup instead. diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index bfe1e528959..daf7b55e5c3 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -494,13 +494,15 @@ [b]Note:[/b] This setting has no effect on the home indicator if [code]hide_home_indicator[/code] is [code]true[/code]. - If [code]true[/code], allows per-pixel transparency for the window background. This affects performance, so leave it on [code]false[/code] unless you need it. + If [code]true[/code], allows per-pixel transparency for the window background. This affects performance, so leave it on [code]false[/code] unless you need it. See also [member display/window/per_pixel_transparency/enabled] and [member rendering/viewport/transparent_background]. + [b]Note:[/b] Enabling [member display/window/per_pixel_transparency/allowed] does not make the background actually transparent. For the background to be transparent, the root viewport must also be made transparent by enabling [member rendering/viewport/transparent_background]. [member display/window/per_pixel_transparency/enabled] must also be enabled. See [member OS.window_per_pixel_transparency_enabled] for more details. [b]Note:[/b] This feature is implemented on HTML5, Linux, macOS, Windows, and Android. Sets the window background to transparent when it starts. See [member OS.window_per_pixel_transparency_enabled] for more details. + [b]Note:[/b] Enabling [member display/window/per_pixel_transparency/enabled] does not make the background actually transparent. For the background to be transparent, the root viewport must also be made transparent by enabling [member rendering/viewport/transparent_background]. [member display/window/per_pixel_transparency/allowed] must also be enabled. [b]Note:[/b] This feature is implemented on HTML5, Linux, macOS, Windows, and Android. @@ -1835,6 +1837,9 @@ If [code]true[/code], a thread safe version of BVH (bounding volume hierarchy) will be used in rendering and Godot physics. Try enabling this option if you see any visual anomalies in 3D (such as incorrect object visibility). + + If [code]true[/code], enables [member Viewport.transparent_bg] on the root viewport. This allows per-pixel transparency to be effective after also enabling [member display/window/per_pixel_transparency/allowed] and [member display/window/per_pixel_transparency/enabled]. + If [code]true[/code], the texture importer will import VRAM-compressed textures using the BPTC algorithm. This texture compression algorithm is only supported on desktop platforms, and only when using the GLES3 renderer. [b]Note:[/b] Changing this setting does [i]not[/i] impact textures that were already imported before. To make this setting apply to textures that were already imported, exit the editor, remove the [code].import/[/code] folder located inside the project folder then restart the editor (see [member application/config/use_hidden_project_data_directory]). diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 9a9d177944e..5cc509d1922 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2691,13 +2691,16 @@ void SpatialEditorViewport::_project_settings_changed() { viewport->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2)); viewport->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3)); - // Update MSAA, FXAA, debanding and HDR if changed. + // Update MSAA, FXAA, transparent background, debanding, sharpening and HDR if changed. int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/filters/msaa"); viewport->set_msaa(Viewport::MSAA(msaa_mode)); bool use_fxaa = ProjectSettings::get_singleton()->get("rendering/quality/filters/use_fxaa"); viewport->set_use_fxaa(use_fxaa); + const bool transparent_background = GLOBAL_GET("rendering/viewport/transparent_background"); + viewport->set_transparent_background(transparent_background); + bool use_debanding = ProjectSettings::get_singleton()->get("rendering/quality/filters/use_debanding"); viewport->set_use_debanding(use_debanding); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 774ed869e7f..975d7018414 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -2250,6 +2250,9 @@ SceneTree::SceneTree() { const bool use_fxaa = GLOBAL_DEF("rendering/quality/filters/use_fxaa", false); root->set_use_fxaa(use_fxaa); + const bool transparent_background = GLOBAL_DEF("rendering/viewport/transparent_background", false); + root->set_transparent_background(transparent_background); + const bool use_debanding = GLOBAL_DEF("rendering/quality/filters/use_debanding", false); root->set_use_debanding(use_debanding);