diff options
52 files changed, 560 insertions, 225 deletions
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index c4981b954b..c36070e47f 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -145,7 +145,7 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_ f3 *= p_oversample; // always apply KEEP_WIDTH aspect ratio - f3 *= p_aspect; + f3 /= p_aspect; switch (p_eye) { case 1: { // left eye diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml index 8587acade3..d495be2ffd 100644 --- a/doc/classes/Color.xml +++ b/doc/classes/Color.xml @@ -5,7 +5,8 @@ </brief_description> <description> A color is represented by red, green, and blue [code](r, g, b)[/code] components. Additionally, [code]a[/code] represents the alpha component, often used for transparency. Values are in floating-point and usually range from 0 to 1. Some properties (such as [member CanvasItem.modulate]) may accept values greater than 1. - You can also create a color from standardized color names by using [method @GDScript.ColorN] or directly using the color constants defined here. The standardized color set is based on the [url=https://en.wikipedia.org/wiki/X11_color_names]X11 color names[/url]. + You can also create a color from standardized color names by using [method @GDScript.ColorN] or directly using the color constants defined here. The standardized color set is based on the [url=https://en.wikipedia.org/wiki/X11_color_names]X11 color names[/url]. + If you want to supply values in a range of 0 to 255, you should use [method @GDScript.Color8]. </description> <tutorials> </tutorials> diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index d7bff83575..8c588f0373 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -238,7 +238,7 @@ <return type="int"> </return> <description> - Returns the node's index, i.e. its position among the siblings of its parent. + Returns the node's order in the scene tree branch. For example, if called on the first child node the position is [code]0[/code]. </description> </method> <method name="get_network_master" qualifiers="const"> @@ -331,13 +331,6 @@ Returns the time elapsed since the last physics-bound frame (see [method _physics_process]). This is always a constant value in physics processing unless the frames per second is changed via [member Engine.iterations_per_second]. </description> </method> - <method name="get_position_in_parent" qualifiers="const"> - <return type="int"> - </return> - <description> - Returns the node's order in the scene tree branch. For example, if called on the first child node the position is [code]0[/code]. - </description> - </method> <method name="get_process_delta_time" qualifiers="const"> <return type="float"> </return> diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index 69957d9939..01da97cfd5 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "rendering_device_vulkan.h" + #include "core/hashfuncs.h" #include "core/os/file_access.h" #include "core/os/os.h" @@ -1265,7 +1266,7 @@ Error RenderingDeviceVulkan::_buffer_free(Buffer *p_buffer) { ERR_FAIL_COND_V(p_buffer->size == 0, ERR_INVALID_PARAMETER); vmaDestroyBuffer(allocator, p_buffer->buffer, p_buffer->allocation); - p_buffer->buffer = nullptr; + p_buffer->buffer = VK_NULL_HANDLE; p_buffer->allocation = nullptr; p_buffer->size = 0; @@ -4250,7 +4251,7 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, VkWriteDescriptorSet write; //common header write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; write.pNext = nullptr; - write.dstSet = nullptr; //will assign afterwards when everything is valid + write.dstSet = VK_NULL_HANDLE; //will assign afterwards when everything is valid write.dstBinding = set_uniform.binding; uint32_t type_size = 1; @@ -4363,7 +4364,7 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, "Texture (binding: " + itos(uniform.binding) + ", index " + itos(j) + ") needs the TEXTURE_USAGE_SAMPLING_BIT usage flag set in order to be used as uniform."); VkDescriptorImageInfo img_info; - img_info.sampler = nullptr; + img_info.sampler = VK_NULL_HANDLE; img_info.imageView = texture->view; if (texture->usage_flags & (TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | TEXTURE_USAGE_RESOLVE_ATTACHMENT_BIT)) { @@ -4416,7 +4417,7 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, "Image (binding: " + itos(uniform.binding) + ", index " + itos(j) + ") needs the TEXTURE_USAGE_STORAGE_BIT usage flag set in order to be used as uniform."); VkDescriptorImageInfo img_info; - img_info.sampler = nullptr; + img_info.sampler = VK_NULL_HANDLE; img_info.imageView = texture->view; if (texture->owner.is_valid()) { @@ -5048,11 +5049,11 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma graphics_pipeline_create_info.renderPass = fb_format.render_pass; graphics_pipeline_create_info.subpass = 0; - graphics_pipeline_create_info.basePipelineHandle = nullptr; + graphics_pipeline_create_info.basePipelineHandle = VK_NULL_HANDLE; graphics_pipeline_create_info.basePipelineIndex = 0; RenderPipeline pipeline; - VkResult err = vkCreateGraphicsPipelines(device, nullptr, 1, &graphics_pipeline_create_info, nullptr, &pipeline.pipeline); + VkResult err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &graphics_pipeline_create_info, nullptr, &pipeline.pipeline); ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateGraphicsPipelines failed with error " + itos(err) + "."); pipeline.set_formats = shader->set_formats; @@ -5121,11 +5122,11 @@ RID RenderingDeviceVulkan::compute_pipeline_create(RID p_shader) { compute_pipeline_create_info.stage = shader->pipeline_stages[0]; compute_pipeline_create_info.layout = shader->pipeline_layout; - compute_pipeline_create_info.basePipelineHandle = nullptr; + compute_pipeline_create_info.basePipelineHandle = VK_NULL_HANDLE; compute_pipeline_create_info.basePipelineIndex = 0; ComputePipeline pipeline; - VkResult err = vkCreateComputePipelines(device, nullptr, 1, &compute_pipeline_create_info, nullptr, &pipeline.pipeline); + VkResult err = vkCreateComputePipelines(device, VK_NULL_HANDLE, 1, &compute_pipeline_create_info, nullptr, &pipeline.pipeline); ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateComputePipelines failed with error " + itos(err) + "."); pipeline.set_formats = shader->set_formats; @@ -7048,6 +7049,14 @@ void RenderingDeviceVulkan::finalize() { for (int i = 0; i < staging_buffer_blocks.size(); i++) { vmaDestroyBuffer(allocator, staging_buffer_blocks[i].buffer, staging_buffer_blocks[i].allocation); } + vmaDestroyAllocator(allocator); + + while (vertex_formats.size()) { + Map<VertexFormatID, VertexDescriptionCache>::Element *temp = vertex_formats.front(); + memdelete_arr(temp->get().bindings); + memdelete_arr(temp->get().attributes); + vertex_formats.erase(temp); + } //all these should be clear at this point ERR_FAIL_COND(descriptor_pools.size()); diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 208109bba3..a46b80e2f4 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -207,7 +207,7 @@ class RenderingDeviceVulkan : public RenderingDevice { VkDescriptorBufferInfo buffer_info; //used for binding Buffer() { size = 0; - buffer = nullptr; + buffer = VK_NULL_HANDLE; allocation = nullptr; } }; diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index d3666bca52..68b4cdf4a4 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -937,7 +937,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { /*compositeAlpha*/ compositeAlpha, /*presentMode*/ swapchainPresentMode, /*clipped*/ true, - /*oldSwapchain*/ nullptr, + /*oldSwapchain*/ VK_NULL_HANDLE, }; err = fpCreateSwapchainKHR(device, &swapchain_ci, nullptr, &window->swapchain); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 157a9cdca7..77e20b971c 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -226,6 +226,10 @@ void FindReplaceBar::_replace_all() { text_edit->begin_complex_operation(); + if (selection_enabled && is_selection_only()) { + text_edit->cursor_set_line(selection_begin.width); + text_edit->cursor_set_column(selection_begin.height); + } if (search_current()) { do { // replace area @@ -243,7 +247,7 @@ void FindReplaceBar::_replace_all() { if (selection_enabled && is_selection_only()) { if (match_from < selection_begin || match_to > selection_end) { - continue; + break; // Done. } // Replace but adjust selection bounds. @@ -289,6 +293,10 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col) { r_line = text_edit->cursor_get_line(); r_col = text_edit->cursor_get_column(); + if (text_edit->is_selection_active() && is_selection_only()) { + return; + } + if (r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) { r_col = result_col; } diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index ed628ff620..6917b2b775 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -48,8 +48,6 @@ void EditorAutoloadSettings::_notification(int p_what) { ResourceLoader::get_recognized_extensions_for_type("Script", &afn); ResourceLoader::get_recognized_extensions_for_type("PackedScene", &afn); - EditorFileDialog *file_dialog = autoload_add_path->get_file_dialog(); - for (List<String>::Element *E = afn.front(); E; E = E->next()) { file_dialog->add_filter("*." + E->get()); @@ -61,6 +59,9 @@ void EditorAutoloadSettings::_notification(int p_what) { get_tree()->get_root()->call_deferred("add_child", info.node); } } + browse_button->set_icon(get_theme_icon("Folder", "EditorIcons")); + } else if (p_what == NOTIFICATION_THEME_CHANGED) { + browse_button->set_icon(get_theme_icon("Folder", "EditorIcons")); } } @@ -116,8 +117,8 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin void EditorAutoloadSettings::_autoload_add() { - if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_line_edit()->get_text())) - autoload_add_path->get_line_edit()->set_text(""); + if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_text())) + autoload_add_path->set_text(""); autoload_add_name->set_text(""); add_autoload->set_disabled(true); @@ -326,7 +327,7 @@ void EditorAutoloadSettings::_autoload_file_callback(const String &p_path) { void EditorAutoloadSettings::_autoload_text_entered(const String p_name) { - if (autoload_add_path->get_line_edit()->get_text() != "" && _autoload_name_is_valid(p_name, nullptr)) { + if (autoload_add_path->get_text() != "" && _autoload_name_is_valid(p_name, nullptr)) { _autoload_add(); } } @@ -340,7 +341,7 @@ void EditorAutoloadSettings::_autoload_path_text_changed(const String p_path) { void EditorAutoloadSettings::_autoload_text_changed(const String p_name) { add_autoload->set_disabled( - autoload_add_path->get_line_edit()->get_text() == "" || !_autoload_name_is_valid(p_name, nullptr)); + autoload_add_path->get_text() == "" || !_autoload_name_is_valid(p_name, nullptr)); } Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { @@ -823,13 +824,24 @@ EditorAutoloadSettings::EditorAutoloadSettings() { l->set_text(TTR("Path:")); hbc->add_child(l); - autoload_add_path = memnew(EditorLineEditFileChooser); - autoload_add_path->set_h_size_flags(SIZE_EXPAND_FILL); - autoload_add_path->get_file_dialog()->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); - autoload_add_path->get_file_dialog()->connect("file_selected", callable_mp(this, &EditorAutoloadSettings::_autoload_file_callback)); - autoload_add_path->get_line_edit()->connect("text_changed", callable_mp(this, &EditorAutoloadSettings::_autoload_path_text_changed)); - + autoload_add_path = memnew(LineEdit); hbc->add_child(autoload_add_path); + autoload_add_path->set_h_size_flags(Control::SIZE_EXPAND_FILL); + autoload_add_path->connect("text_changed", callable_mp(this, &EditorAutoloadSettings::_autoload_path_text_changed)); + + browse_button = memnew(Button); + hbc->add_child(browse_button); + browse_button->connect("pressed", callable_mp(this, &EditorAutoloadSettings::_browse_autoload_add_path)); + + file_dialog = memnew(EditorFileDialog); + hbc->add_child(file_dialog); + file_dialog->connect("file_selected", callable_mp(this, &EditorAutoloadSettings::_set_autoload_add_path)); + file_dialog->connect("dir_selected", callable_mp(this, &EditorAutoloadSettings::_set_autoload_add_path)); + file_dialog->connect("files_selected", callable_mp(this, &EditorAutoloadSettings::_set_autoload_add_path)); + + hbc->set_h_size_flags(SIZE_EXPAND_FILL); + file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); + file_dialog->connect("file_selected", callable_mp(this, &EditorAutoloadSettings::_autoload_file_callback)); l = memnew(Label); l->set_text(TTR("Node Name:")); @@ -890,3 +902,14 @@ EditorAutoloadSettings::~EditorAutoloadSettings() { } } } + +void EditorAutoloadSettings::_set_autoload_add_path(const String &p_text) { + + autoload_add_path->set_text(p_text); + autoload_add_path->emit_signal("text_entered", p_text); +} + +void EditorAutoloadSettings::_browse_autoload_add_path() { + + file_dialog->popup_centered_ratio(); +}
\ No newline at end of file diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h index 2716442ec9..94a581401c 100644 --- a/editor/editor_autoload_settings.h +++ b/editor/editor_autoload_settings.h @@ -74,9 +74,11 @@ class EditorAutoloadSettings : public VBoxContainer { String selected_autoload; Tree *tree; - EditorLineEditFileChooser *autoload_add_path; LineEdit *autoload_add_name; Button *add_autoload; + LineEdit *autoload_add_path; + Button *browse_button; + EditorFileDialog *file_dialog; bool _autoload_name_is_valid(const String &p_name, String *r_error = nullptr); @@ -96,6 +98,9 @@ class EditorAutoloadSettings : public VBoxContainer { bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control); + void _set_autoload_add_path(const String &p_text); + void _browse_autoload_add_path(); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 71ade56e39..6a06c6657e 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -1579,6 +1579,7 @@ EditorFileDialog::EditorFileDialog() { drives = memnew(OptionButton); drives->connect("item_selected", callable_mp(this, &EditorFileDialog::_select_drive)); + pathhb->add_child(drives); makedir = memnew(Button); makedir->set_text(TTR("Create Folder")); @@ -1733,42 +1734,3 @@ EditorFileDialog::~EditorFileDialog() { unregister_func(this); memdelete(dir_access); } - -void EditorLineEditFileChooser::_notification(int p_what) { - - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) - button->set_icon(get_theme_icon("Folder", "EditorIcons")); -} - -void EditorLineEditFileChooser::_bind_methods() { - - ClassDB::bind_method(D_METHOD("get_button"), &EditorLineEditFileChooser::get_button); - ClassDB::bind_method(D_METHOD("get_line_edit"), &EditorLineEditFileChooser::get_line_edit); - ClassDB::bind_method(D_METHOD("get_file_dialog"), &EditorLineEditFileChooser::get_file_dialog); -} - -void EditorLineEditFileChooser::_chosen(const String &p_text) { - - line_edit->set_text(p_text); - line_edit->emit_signal("text_entered", p_text); -} - -void EditorLineEditFileChooser::_browse() { - - dialog->popup_centered_ratio(); -} - -EditorLineEditFileChooser::EditorLineEditFileChooser() { - - line_edit = memnew(LineEdit); - add_child(line_edit); - line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); - button = memnew(Button); - add_child(button); - button->connect("pressed", callable_mp(this, &EditorLineEditFileChooser::_browse)); - dialog = memnew(EditorFileDialog); - add_child(dialog); - dialog->connect("file_selected", callable_mp(this, &EditorLineEditFileChooser::_chosen)); - dialog->connect("dir_selected", callable_mp(this, &EditorLineEditFileChooser::_chosen)); - dialog->connect("files_selected", callable_mp(this, &EditorLineEditFileChooser::_chosen)); -} diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h index ed23f14ebe..8efb8f5368 100644 --- a/editor/editor_file_dialog.h +++ b/editor/editor_file_dialog.h @@ -245,28 +245,6 @@ public: ~EditorFileDialog(); }; -class EditorLineEditFileChooser : public HBoxContainer { - - GDCLASS(EditorLineEditFileChooser, HBoxContainer); - Button *button; - LineEdit *line_edit; - EditorFileDialog *dialog; - - void _chosen(const String &p_text); - void _browse(); - -protected: - void _notification(int p_what); - static void _bind_methods(); - -public: - Button *get_button() { return button; } - LineEdit *get_line_edit() { return line_edit; } - EditorFileDialog *get_file_dialog() { return dialog; } - - EditorLineEditFileChooser(); -}; - VARIANT_ENUM_CAST(EditorFileDialog::FileMode); VARIANT_ENUM_CAST(EditorFileDialog::Access); VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode); diff --git a/editor/editor_help.h b/editor/editor_help.h index d9c7194003..2e053e674f 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -192,9 +192,9 @@ public: ~EditorHelp(); }; -class EditorHelpBit : public PanelContainer { +class EditorHelpBit : public MarginContainer { - GDCLASS(EditorHelpBit, PanelContainer); + GDCLASS(EditorHelpBit, MarginContainer); RichTextLabel *rich_text; void _go_to_help(String p_what); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 205d5f2944..e7c1eaf777 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -369,6 +369,11 @@ void EditorNode::_notification(int p_what) { RS::get_singleton()->environment_glow_set_use_bicubic_upscale(glow_bicubic); RS::EnvironmentSSRRoughnessQuality ssr_roughness_quality = RS::EnvironmentSSRRoughnessQuality(int(GLOBAL_GET("rendering/quality/screen_space_reflection/roughness_quality"))); RS::get_singleton()->environment_set_ssr_roughness_quality(ssr_roughness_quality); + RS::SubSurfaceScatteringQuality sss_quality = RS::SubSurfaceScatteringQuality(int(GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_quality"))); + RS::get_singleton()->sub_surface_scattering_set_quality(sss_quality); + float sss_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_scale"); + float sss_depth_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_depth_scale"); + RS::get_singleton()->sub_surface_scattering_set_scale(sss_scale, sss_depth_scale); } ResourceImporterTexture::get_singleton()->update_imports(); @@ -3973,8 +3978,9 @@ void EditorNode::_dock_make_float() { Control *dock = dock_slot[dock_popup_selected]->get_current_tab_control(); ERR_FAIL_COND(!dock); - Size2 dock_size = dock->get_size(); //remember size - Point2 dock_screen_pos = dock->get_global_position() + get_tree()->get_root()->get_position(); + const Size2i borders = Size2i(4, 4) * EDSCALE; + Size2 dock_size = dock->get_size() + borders * 2; //remember size + Point2 dock_screen_pos = dock->get_global_position() + get_tree()->get_root()->get_position() - borders; print_line("dock pos: " + dock->get_global_position() + " window pos: " + get_tree()->get_root()->get_position()); int dock_index = dock->get_index(); @@ -3988,10 +3994,10 @@ void EditorNode::_dock_make_float() { window->add_child(p); MarginContainer *margin = memnew(MarginContainer); margin->set_anchors_and_margins_preset(Control::PRESET_WIDE); - margin->add_theme_constant_override("margin_right", 4 * EDSCALE); - margin->add_theme_constant_override("margin_top", 4 * EDSCALE); - margin->add_theme_constant_override("margin_left", 4 * EDSCALE); - margin->add_theme_constant_override("margin_bottom", 4 * EDSCALE); + margin->add_theme_constant_override("margin_right", borders.width); + margin->add_theme_constant_override("margin_top", borders.height); + margin->add_theme_constant_override("margin_left", borders.width); + margin->add_theme_constant_override("margin_bottom", borders.height); window->add_child(margin); dock->set_anchors_and_margins_preset(Control::PRESET_WIDE); margin->add_child(dock); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 1f3ff1b332..cf478f20e5 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2196,7 +2196,7 @@ void EditorPropertyResource::_menu_option(int p_which) { file_system_dock->navigate_to_path(res->get_path()); // Ensure that the FileSystem dock is visible. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control(); - tab_container->set_current_tab(file_system_dock->get_position_in_parent()); + tab_container->set_current_tab(file_system_dock->get_index()); } break; default: { diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 663068b2b5..37bca661dd 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -977,8 +977,6 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox()); theme->set_stylebox("normal", "RichTextLabel", style_tree_bg); - theme->set_stylebox("panel", "EditorHelpBit", make_flat_stylebox(dark_color_1, 6, 4, 6, 4)); - theme->set_color("headline_color", "EditorHelp", mono_color); // Panel @@ -997,6 +995,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // LinkButton theme->set_stylebox("focus", "LinkButton", style_empty); theme->set_color("font_color", "LinkButton", font_color); + theme->set_color("font_color_hover", "LinkButton", font_color_hl); + theme->set_color("font_color_pressed", "LinkButton", accent_color); + theme->set_color("font_color_disabled", "LinkButton", font_color_disabled); // TooltipPanel Ref<StyleBoxFlat> style_tooltip = style_popup->duplicate(); diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 23be42aaea..22f6aedeaa 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -450,8 +450,8 @@ void ImportDock::_reimport() { String importer_name = params->importer->get_importer_name(); - if (params->checking) { - //update only what edited (checkboxes) + if (params->checking && config->get_value("remap", "importer") == params->importer->get_importer_name()) { + //update only what is edited (checkboxes) if the importer is the same for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { if (params->checked.has(E->get().name)) { config->set_value("params", E->get().name, params->values[E->get().name]); @@ -558,7 +558,7 @@ ImportDock::ImportDock() { hb->add_spacer(); reimport_confirm = memnew(ConfirmationDialog); - reimport_confirm->get_ok()->set_text(TTR("Save scenes, re-import and restart")); + reimport_confirm->get_ok()->set_text(TTR("Save Scenes, Re-Import, and Restart")); add_child(reimport_confirm); reimport_confirm->connect("confirmed", callable_mp(this, &ImportDock::_reimport_and_restart)); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index dd80fff008..0b97ade278 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1243,7 +1243,7 @@ void ScriptEditor::_menu_option(int p_option) { file_system_dock->navigate_to_path(path); // Ensure that the FileSystem dock is visible. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control(); - tab_container->set_current_tab(file_system_dock->get_position_in_parent()); + tab_container->set_current_tab(file_system_dock->get_index()); } } break; case CLOSE_DOCS: { diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index cd69c1e6f9..8892d13f51 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -1030,6 +1030,7 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) { hscroll->connect("value_changed", callable_mp(this, &TextureRegionEditor::_scroll_changed)); updating_scroll = false; + autoslice_is_dirty = true; } void TextureRegionEditorPlugin::edit(Object *p_object) { diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index b1bd6392d8..294ce2c4cd 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -556,6 +556,17 @@ void VisualShaderEditor::_update_graph() { uniform_name->connect("text_entered", callable_mp(this, &VisualShaderEditor::_line_edit_changed), varray(uniform_name, nodes[n_i])); uniform_name->connect("focus_exited", callable_mp(this, &VisualShaderEditor::_line_edit_focus_out), varray(uniform_name, nodes[n_i])); + String error = vsnode->get_warning(visual_shader->get_mode(), type); + if (error != String()) { + offset = memnew(Control); + offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE)); + node->add_child(offset); + Label *error_label = memnew(Label); + error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); + error_label->set_text(error); + node->add_child(error_label); + } + if (vsnode->get_input_port_count() == 0 && vsnode->get_output_port_count() == 1 && vsnode->get_output_port_name(0) == "") { //shortcut VisualShaderNode::PortType port_right = vsnode->get_output_port_type(0); diff --git a/editor/project_export.cpp b/editor/project_export.cpp index b30cd89c96..04ec5ae043 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -1205,12 +1205,9 @@ ProjectExportDialog::ProjectExportDialog() { custom_features = memnew(LineEdit); custom_features->connect("text_changed", callable_mp(this, &ProjectExportDialog::_custom_features_changed)); feature_vb->add_margin_child(TTR("Custom (comma-separated):"), custom_features); - Panel *features_panel = memnew(Panel); custom_feature_display = memnew(RichTextLabel); - features_panel->add_child(custom_feature_display); - custom_feature_display->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 10 * EDSCALE); custom_feature_display->set_v_size_flags(Control::SIZE_EXPAND_FILL); - feature_vb->add_margin_child(TTR("Feature List:"), features_panel, true); + feature_vb->add_margin_child(TTR("Feature List:"), custom_feature_display, true); sections->add_child(feature_vb); // Script export parameters. diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 444cae42c5..978c95b9c8 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -257,7 +257,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { file_system_dock->navigate_to_path(r->get_path()); // Ensure that the FileSystem dock is visible. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control(); - tab_container->set_current_tab(file_system_dock->get_position_in_parent()); + tab_container->set_current_tab(file_system_dock->get_index()); } break; default: { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index eaefd04c6b..a729f62123 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1535,7 +1535,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V if (p_nodes[ni] == p_new_parent) return; // Attempt to reparent to itself. - if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_position_in_parent()) + if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index()) no_change = false; } @@ -1644,7 +1644,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V owners.push_back(E->get()); } - int child_pos = node->get_position_in_parent(); + int child_pos = node->get_index(); editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node); editor_data->get_undo_redo().add_undo_method(node->get_parent(), "move_child", node, child_pos); @@ -1918,7 +1918,7 @@ Node *SceneTreeDock::_get_selection_group_tail(Node *p_node, List<Node *> p_list Node *tail = p_node; Node *parent = tail->get_parent(); - for (int i = p_node->get_position_in_parent(); i < parent->get_child_count(); i++) { + for (int i = p_node->get_index(); i < parent->get_child_count(); i++) { Node *sibling = parent->get_child(i); if (p_list.find(sibling)) diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 30522930c7..ab528fac30 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1262,7 +1262,7 @@ void VisualScriptEditor::_add_func_input() { } func_input_vbox->add_child(hbox); - hbox->set_meta("id", hbox->get_position_in_parent()); + hbox->set_meta("id", hbox->get_index()); delete_button->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_func_input), varray(hbox)); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 775f863a4f..b4dc37c74f 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1893,7 +1893,7 @@ static Control *_next_control(Control *p_from) { return nullptr; } - int next = p_from->get_position_in_parent(); + int next = p_from->get_index(); ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr); for (int i = (next + 1); i < parent->get_child_count(); i++) { @@ -2032,7 +2032,7 @@ Control *Control::find_prev_valid_focus() const { } else { - for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) { + for (int i = (from->get_index() - 1); i >= 0; i--) { Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i)); diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 2e87a92969..5654219a3e 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -322,7 +322,6 @@ AcceptDialog::AcceptDialog() { label->set_end(Point2(-margin, -button_margin - 10)); add_child(label); - hbc = memnew(HBoxContainer); add_child(hbc); hbc->add_spacer(); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 8ddf86cc68..89d13ecd7f 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -73,9 +73,9 @@ void FileDialog::_notification(int p_what) { } if (p_what == NOTIFICATION_ENTER_TREE) { - dir_up->set_icon(vbox->get_theme_icon("parent_folder")); - refresh->set_icon(vbox->get_theme_icon("reload")); - show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden")); + dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog")); + refresh->set_icon(vbox->get_theme_icon("reload", "FileDialog")); + show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "FileDialog")); _theme_changed(); } } @@ -429,8 +429,8 @@ void FileDialog::update_file_list() { dir_access->list_dir_begin(); TreeItem *root = tree->create_item(); - Ref<Texture2D> folder = vbox->get_theme_icon("folder"); - const Color folder_color = vbox->get_theme_color("folder_icon_modulate"); + Ref<Texture2D> folder = vbox->get_theme_icon("folder", "FileDialog"); + const Color folder_color = vbox->get_theme_color("folder_icon_modulate", "FileDialog"); List<String> files; List<String> dirs; @@ -528,7 +528,7 @@ void FileDialog::update_file_list() { } if (mode == FILE_MODE_OPEN_DIR) { - ti->set_custom_color(0, vbox->get_theme_color("files_disabled")); + ti->set_custom_color(0, vbox->get_theme_color("files_disabled", "FileDialog")); ti->set_selectable(0, false); } Dictionary d; @@ -909,6 +909,7 @@ FileDialog::FileDialog() { drives = memnew(OptionButton); drives->connect("item_selected", callable_mp(this, &FileDialog::_select_drive)); + hbc->add_child(drives); dir = memnew(LineEdit); hbc->add_child(dir); @@ -1005,37 +1006,3 @@ FileDialog::~FileDialog() { unregister_func(this); memdelete(dir_access); } - -void LineEditFileChooser::_bind_methods() { - - ClassDB::bind_method(D_METHOD("get_button"), &LineEditFileChooser::get_button); - ClassDB::bind_method(D_METHOD("get_line_edit"), &LineEditFileChooser::get_line_edit); - ClassDB::bind_method(D_METHOD("get_file_dialog"), &LineEditFileChooser::get_file_dialog); -} - -void LineEditFileChooser::_chosen(const String &p_text) { - - line_edit->set_text(p_text); - line_edit->emit_signal("text_entered", p_text); -} - -void LineEditFileChooser::_browse() { - - dialog->popup_centered_ratio(); -} - -LineEditFileChooser::LineEditFileChooser() { - - line_edit = memnew(LineEdit); - add_child(line_edit); - line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); - button = memnew(Button); - button->set_text(" .. "); - add_child(button); - button->connect("pressed", callable_mp(this, &LineEditFileChooser::_browse)); - dialog = memnew(FileDialog); - add_child(dialog); - dialog->connect("file_selected", callable_mp(this, &LineEditFileChooser::_chosen)); - dialog->connect("dir_selected", callable_mp(this, &LineEditFileChooser::_chosen)); - dialog->connect("files_selected", callable_mp(this, &LineEditFileChooser::_chosen)); -} diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 6faf02d55d..ac0e733abc 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -177,27 +177,6 @@ public: ~FileDialog(); }; -class LineEditFileChooser : public HBoxContainer { - - GDCLASS(LineEditFileChooser, HBoxContainer); - Button *button; - LineEdit *line_edit; - FileDialog *dialog; - - void _chosen(const String &p_text); - void _browse(); - -protected: - static void _bind_methods(); - -public: - Button *get_button() { return button; } - LineEdit *get_line_edit() { return line_edit; } - FileDialog *get_file_dialog() { return dialog; } - - LineEditFileChooser(); -}; - VARIANT_ENUM_CAST(FileDialog::FileMode); VARIANT_ENUM_CAST(FileDialog::Access); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 5fb2243aff..2a05207a0f 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -582,13 +582,14 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } else { cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color); } - } else if (previously_visible) { + } else if (previously_visible && c[i] != '\t') { backtrack += font->get_char_size(fx_char, c[i + 1]).x; } p_char_count++; if (c[i] == '\t') { cw = tab_size * font->get_char_size(' ').width; + backtrack = MAX(0, backtrack - cw); } ofs += cw; @@ -607,7 +608,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } else if (strikethrough) { Color uc = color; uc.a *= 0.5; - int uy = y + lh / 2 - line_descent + 2; + int uy = y + lh - (line_ascent + line_descent) / 2; float strikethrough_width = 1.0; #ifdef TOOLS_ENABLED strikethrough_width *= EDSCALE; diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp index baa138847f..92f3c5b5d9 100644 --- a/scene/gui/texture_rect.cpp +++ b/scene/gui/texture_rect.cpp @@ -95,6 +95,15 @@ void TextureRect::_notification(int p_what) { } break; } + Ref<AtlasTexture> p_atlas = texture; + + if (p_atlas.is_valid() && region.has_no_area()) { + Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height()); + + offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0; + offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0; + } + size.width *= hflip ? -1.0f : 1.0f; size.height *= vflip ? -1.0f : 1.0f; diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index 15f64390de..c1caa943e3 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -35,7 +35,7 @@ void CanvasLayer::set_layer(int p_xform) { layer = p_xform; if (viewport.is_valid()) - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } int CanvasLayer::get_layer() const { @@ -151,7 +151,7 @@ void CanvasLayer::_notification(int p_what) { viewport = vp->get_viewport_rid(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); _update_follow_viewport(); @@ -167,7 +167,7 @@ void CanvasLayer::_notification(int p_what) { case NOTIFICATION_MOVED_IN_PARENT: { if (is_inside_tree()) - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } break; } @@ -214,7 +214,7 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) { viewport = vp->get_viewport_rid(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } } diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index 78958a7a1c..062b221c84 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -95,7 +95,7 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene if (!scene) return nullptr; scene->set_name(get_name()); - int pos = get_position_in_parent(); + int pos = get_index(); for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) { scene->set(E->get().name, E->get().value); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 6b46ffd8ad..50f3bf834f 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1268,7 +1268,7 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq add_child(p_child, p_legible_unique_name); if (is_a_parent_of(p_node)) { - move_child(p_child, p_node->get_position_in_parent() + 1); + move_child(p_child, p_node->get_index() + 1); } else { WARN_PRINT("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent."); } @@ -1918,6 +1918,7 @@ int Node::get_index() const { return data.pos; } + void Node::remove_and_skip() { ERR_FAIL_COND(!data.parent); @@ -2042,11 +2043,6 @@ bool Node::get_scene_instance_load_placeholder() const { return data.use_placeholder; } -int Node::get_position_in_parent() const { - - return data.pos; -} - Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const { Node *node = nullptr; @@ -2215,7 +2211,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const } parent->add_child(dup); - int pos = E->get()->get_position_in_parent(); + int pos = E->get()->get_index(); if (pos < parent->get_child_count() - 1) { @@ -2860,7 +2856,6 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_pause_mode"), &Node::get_pause_mode); ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process); ClassDB::bind_method(D_METHOD("print_stray_nodes"), &Node::_print_stray_nodes); - ClassDB::bind_method(D_METHOD("get_position_in_parent"), &Node::get_position_in_parent); ClassDB::bind_method(D_METHOD("set_display_folded", "fold"), &Node::set_display_folded); ClassDB::bind_method(D_METHOD("is_displayed_folded"), &Node::is_displayed_folded); diff --git a/scene/main/node.h b/scene/main/node.h index 292ec0e291..5de07d506e 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -369,8 +369,6 @@ public: void set_process_unhandled_key_input(bool p_enable); bool is_processing_unhandled_key_input() const; - int get_position_in_parent() const; - Node *duplicate(int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS) const; Node *duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const; #ifdef TOOLS_ENABLED diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 84c1c9d734..85adc8c5f1 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -444,6 +444,9 @@ void BaseMaterial3D::_update_shader() { case DEPTH_DRAW_DISABLED: code += ",depth_draw_never"; break; } + if (features[FEATURE_SUBSURACE_SCATTERING] && flags[FLAG_SUBSURFACE_MODE_SKIN]) { + code += ",sss_mode_skin"; + } if (transparency == TRANSPARENCY_ALPHA_DEPTH_PRE_PASS) { code += ",depth_prepass_alpha"; } @@ -2284,6 +2287,7 @@ void BaseMaterial3D::_bind_methods() { ADD_GROUP("Subsurf Scatter", "subsurf_scatter_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "subsurf_scatter_enabled"), "set_feature", "get_feature", FEATURE_SUBSURACE_SCATTERING); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_subsurface_scattering_strength", "get_subsurface_scattering_strength"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "subsurf_scatter_skin_mode"), "set_flag", "get_flag", FLAG_SUBSURFACE_MODE_SKIN); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "subsurf_scatter_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_SUBSURFACE_SCATTERING); ADD_GROUP("Transmission", "transmission_"); @@ -2436,6 +2440,7 @@ void BaseMaterial3D::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_USE_SHADOW_TO_OPACITY); BIND_ENUM_CONSTANT(FLAG_USE_TEXTURE_REPEAT); BIND_ENUM_CONSTANT(FLAG_INVERT_HEIGHTMAP); + BIND_ENUM_CONSTANT(FLAG_SUBSURFACE_MODE_SKIN); BIND_ENUM_CONSTANT(FLAG_MAX); BIND_ENUM_CONSTANT(DIFFUSE_BURLEY); diff --git a/scene/resources/material.h b/scene/resources/material.h index 0c9352baf4..57f9038bf5 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -218,6 +218,7 @@ public: FLAG_USE_SHADOW_TO_OPACITY, FLAG_USE_TEXTURE_REPEAT, FLAG_INVERT_HEIGHTMAP, + FLAG_SUBSURFACE_MODE_SKIN, FLAG_MAX }; diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index f70f54412b..310a7ef4e4 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -2164,6 +2164,17 @@ void VisualShaderNodeUniform::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "uniform_name"), "set_uniform_name", "get_uniform_name"); } +String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { + + List<String> keyword_list; + ShaderLanguage::get_keyword_list(&keyword_list); + if (keyword_list.find(uniform_name)) { + return TTR("Uniform name cannot be equal to a shader keyword. Choose another name."); + } + + return String(); +} + VisualShaderNodeUniform::VisualShaderNodeUniform() { } diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index 450dcfa081..ecf3f93fbb 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -379,6 +379,8 @@ public: void set_uniform_name(const String &p_name); String get_uniform_name() const; + virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const; + VisualShaderNodeUniform(); }; diff --git a/servers/rendering/rasterizer.h b/servers/rendering/rasterizer.h index 6676b00723..d77963b3dd 100644 --- a/servers/rendering/rasterizer.h +++ b/servers/rendering/rasterizer.h @@ -266,6 +266,9 @@ public: virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) = 0; virtual bool screen_space_roughness_limiter_is_active() const = 0; + virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) = 0; + virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) = 0; + virtual bool free(RID p_rid) = 0; virtual void update() = 0; diff --git a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp index 3b22cb4d9d..2d881dbd37 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp @@ -461,6 +461,53 @@ void RasterizerEffectsRD::screen_space_reflection(RID p_diffuse, RID p_normal, R RD::get_singleton()->compute_list_end(); } +void RasterizerEffectsRD::sub_surface_scattering(RID p_diffuse, RID p_diffuse2, RID p_depth, const CameraMatrix &p_camera, const Size2i &p_screen_size, float p_scale, float p_depth_scale, RenderingServer::SubSurfaceScatteringQuality p_quality) { + + 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; + + Plane p = p_camera.xform4(Plane(1, 0, -1, 1)); + p.normal /= p.d; + float unit_size = p.normal.x; + + { //scale color and depth to half + sss.push_constant.camera_z_far = p_camera.get_z_far(); + sss.push_constant.camera_z_near = p_camera.get_z_near(); + sss.push_constant.orthogonal = p_camera.is_orthogonal(); + sss.push_constant.unit_size = unit_size; + sss.push_constant.screen_size[0] = p_screen_size.x; + sss.push_constant.screen_size[1] = p_screen_size.y; + sss.push_constant.vertical = false; + sss.push_constant.scale = p_scale; + sss.push_constant.depth_scale = p_depth_scale; + + RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, sss.pipelines[p_quality - 1]); + + 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_uniform_set_from_image(p_diffuse2), 1); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth), 2); + + RD::get_singleton()->compute_list_set_push_constant(compute_list, &sss.push_constant, sizeof(SubSurfaceScatteringPushConstant)); + + 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_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_diffuse2), 0); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_diffuse), 1); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth), 2); + + sss.push_constant.vertical = true; + RD::get_singleton()->compute_list_set_push_constant(compute_list, &sss.push_constant, sizeof(SubSurfaceScatteringPushConstant)); + + 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>()); @@ -1063,8 +1110,7 @@ void RasterizerEffectsRD::render_sky(RD::DrawListID p_list, float p_time, RID p_ RasterizerEffectsRD::RasterizerEffectsRD() { - { - // Initialize blur + { // Initialize blur Vector<String> blur_modes; blur_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n"); blur_modes.push_back("\n#define MODE_GAUSSIAN_GLOW\n"); @@ -1356,6 +1402,21 @@ RasterizerEffectsRD::RasterizerEffectsRD() { ssr_scale.pipeline = RD::get_singleton()->compute_pipeline_create(ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0)); } + { + Vector<String> sss_modes; + sss_modes.push_back("\n#define USE_11_SAMPLES\n"); + sss_modes.push_back("\n#define USE_17_SAMPLES\n"); + sss_modes.push_back("\n#define USE_25_SAMPLES\n"); + + sss.shader.initialize(sss_modes); + + sss.shader_version = sss.shader.version_create(); + + for (int i = 0; i < sss_modes.size(); i++) { + sss.pipelines[i] = RD::get_singleton()->compute_pipeline_create(sss.shader.version_get_shader(sss.shader_version, i)); + } + } + RD::SamplerState sampler; sampler.mag_filter = RD::SAMPLER_FILTER_LINEAR; sampler.min_filter = RD::SAMPLER_FILTER_LINEAR; @@ -1400,16 +1461,22 @@ RasterizerEffectsRD::~RasterizerEffectsRD() { RD::get_singleton()->free(default_mipmap_sampler); RD::get_singleton()->free(index_buffer); //array gets freed as dependency RD::get_singleton()->free(filter.coefficient_buffer); + blur.shader.version_free(blur.shader_version); - roughness.shader.version_free(roughness.shader_version); - tonemap.shader.version_free(tonemap.shader_version); - luminance_reduce.shader.version_free(luminance_reduce.shader_version); - copy.shader.version_free(copy.shader_version); bokeh.shader.version_free(bokeh.shader_version); - ssao.minify_shader.version_free(ssao.minify_shader_version); - ssao.gather_shader.version_free(ssao.gather_shader_version); - ssao.blur_shader.version_free(ssao.blur_shader_version); - roughness_limiter.shader.version_free(roughness_limiter.shader_version); + copy.shader.version_free(copy.shader_version); cubemap_downsampler.shader.version_free(cubemap_downsampler.shader_version); filter.shader.version_free(filter.shader_version); + luminance_reduce.shader.version_free(luminance_reduce.shader_version); + roughness.shader.version_free(roughness.shader_version); + roughness_limiter.shader.version_free(roughness_limiter.shader_version); + specular_merge.shader.version_free(specular_merge.shader_version); + ssao.blur_shader.version_free(ssao.blur_shader_version); + ssao.gather_shader.version_free(ssao.gather_shader_version); + ssao.minify_shader.version_free(ssao.minify_shader_version); + ssr.shader.version_free(ssr.shader_version); + ssr_filter.shader.version_free(ssr_filter.shader_version); + ssr_scale.shader.version_free(ssr_scale.shader_version); + sss.shader.version_free(sss.shader_version); + tonemap.shader.version_free(tonemap.shader_version); } diff --git a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h index 32eb8c8cda..27f051d194 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.h @@ -48,6 +48,7 @@ #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" +#include "servers/rendering/rasterizer_rd/shaders/subsurface_scattering.glsl.gen.h" #include "servers/rendering/rasterizer_rd/shaders/tonemap.glsl.gen.h" #include "servers/rendering_server.h" @@ -480,6 +481,29 @@ class RasterizerEffectsRD { RID pipeline; } ssr_scale; + struct SubSurfaceScatteringPushConstant { + + int32_t screen_size[2]; + float camera_z_far; + float camera_z_near; + + uint32_t vertical; + uint32_t orthogonal; + float unit_size; + float scale; + + float depth_scale; + uint32_t pad[3]; + }; + + struct SubSurfaceScattering { + + SubSurfaceScatteringPushConstant push_constant; + SubsurfaceScatteringShaderRD shader; + RID shader_version; + RID pipelines[3]; //3 quality levels + } sss; + RID default_sampler; RID default_mipmap_sampler; RID index_buffer; @@ -571,6 +595,7 @@ public: 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); + void sub_surface_scattering(RID p_diffuse, RID p_diffuse2, RID p_depth, const CameraMatrix &p_camera, const Size2i &p_screen_size, float p_scale, float p_depth_scale, RS::SubSurfaceScatteringQuality p_quality); 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 6094fbb36f..685c30b5b8 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp @@ -1795,6 +1795,14 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor render_list.clear(); _fill_render_list(p_cull_result, p_cull_count, PASS_MODE_COLOR, render_buffer == nullptr); + bool using_sss = render_buffer && scene_state.used_sss && sub_surface_scattering_get_quality() != RS::SUB_SURFACE_SCATTERING_QUALITY_DISABLED; + + if (using_sss) { + using_separate_specular = true; + render_buffer->ensure_specular(); + using_separate_specular = true; + opaque_specular_framebuffer = render_buffer->color_specular_fb; + } RID radiance_uniform_set; bool draw_sky = false; @@ -1894,8 +1902,8 @@ 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 can_continue_color = !scene_state.used_screen_texture && !using_ssr && !using_sss; + bool can_continue_depth = !scene_state.used_depth_texture && !using_ssr && !using_sss; { @@ -1904,10 +1912,15 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor //regular forward for now Vector<Color> c; - c.push_back(clear_color.to_linear()); if (using_separate_specular) { + Color cc = clear_color.to_linear(); + cc.a = 0; //subsurf scatter must be 0 + c.push_back(cc); c.push_back(Color(0, 0, 0, 0)); + } else { + c.push_back(clear_color.to_linear()); } + 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); @@ -1950,10 +1963,9 @@ void RasterizerSceneHighEndRD::_render_scene(RID p_render_buffer, const Transfor if (using_separate_specular) { - if (scene_state.used_sss) { + if (using_sss) { RENDER_TIMESTAMP("Sub Surface Scattering"); - - //_process_sss() + _process_sss(p_render_buffer, p_cam_projection); } if (using_ssr) { @@ -2620,6 +2632,8 @@ RasterizerSceneHighEndRD::RasterizerSceneHighEndRD(RasterizerStorageRD *p_storag actions.render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n"; actions.render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n"; + actions.render_mode_defines["sss_mode_skin"] = "#define SSS_MODE_SKIN\n"; + bool force_blinn = GLOBAL_GET("rendering/quality/shading/force_blinn_over_ggx"); if (!force_blinn) { diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp index af86d145ad..e4c5f1c984 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp @@ -3203,6 +3203,26 @@ void RasterizerSceneRD::_free_render_buffer_data(RenderBuffers *rb) { } } +void RasterizerSceneRD::_process_sss(RID p_render_buffers, const CameraMatrix &p_camera) { + + 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 + return; + } + + if (rb->blur[0].texture.is_null()) { + _allocate_blur_textures(rb); + _render_buffers_uniform_set_changed(p_render_buffers); + } + + storage->get_effects()->sub_surface_scattering(rb->texture, rb->blur[0].mipmaps[0].texture, rb->depth_texture, p_camera, Size2i(rb->width, rb->height), sss_scale, sss_depth_scale, sss_quality); +} + 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); @@ -3547,6 +3567,19 @@ void RasterizerSceneRD::render_buffers_configure(RID p_render_buffers, RID p_ren _render_buffers_uniform_set_changed(p_render_buffers); } +void RasterizerSceneRD::sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) { + sss_quality = p_quality; +} + +RS::SubSurfaceScatteringQuality RasterizerSceneRD::sub_surface_scattering_get_quality() const { + return sss_quality; +} + +void RasterizerSceneRD::sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) { + sss_scale = p_scale; + sss_depth_scale = p_depth_scale; +} + int RasterizerSceneRD::get_roughness_layers() const { return roughness_layers; } @@ -4101,6 +4134,9 @@ RasterizerSceneRD::RasterizerSceneRD(RasterizerStorageRD *p_storage) { 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"))); + sss_quality = RS::SubSurfaceScatteringQuality(int(GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_quality"))); + sss_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_scale"); + sss_depth_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_depth_scale"); } RasterizerSceneRD::~RasterizerSceneRD() { diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h index 11a8555d22..3f71f7dbc1 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h @@ -93,6 +93,7 @@ protected: 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 _process_sss(RID p_render_buffers, const CameraMatrix &p_camera); 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); @@ -698,6 +699,9 @@ private: RS::DOFBlurQuality dof_blur_quality = RS::DOF_BLUR_QUALITY_MEDIUM; RS::DOFBokehShape dof_blur_bokeh_shape = RS::DOF_BOKEH_HEXAGON; bool dof_blur_use_jitter = false; + RS::SubSurfaceScatteringQuality sss_quality = RS::SUB_SURFACE_SCATTERING_QUALITY_MEDIUM; + float sss_scale = 0.05; + float sss_depth_scale = 0.01; mutable RID_Owner<CameraEffects> camera_effects_owner; @@ -1110,6 +1114,10 @@ public: virtual bool screen_space_roughness_limiter_is_active() const; virtual float screen_space_roughness_limiter_get_curve() const; + virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality); + RS::SubSurfaceScatteringQuality sub_surface_scattering_get_quality() const; + virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale); + int get_roughness_layers() const; bool is_using_radiance_cubemap_array() const; diff --git a/servers/rendering/rasterizer_rd/shaders/SCsub b/servers/rendering/rasterizer_rd/shaders/SCsub index ade0418bd2..04a43e3251 100644 --- a/servers/rendering/rasterizer_rd/shaders/SCsub +++ b/servers/rendering/rasterizer_rd/shaders/SCsub @@ -25,4 +25,5 @@ if "RD_GLSL" in env["BUILDERS"]: 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("subsurface_scattering.glsl") env.RD_GLSL("specular_merge.glsl") diff --git a/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl b/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl index 07f4770b14..955ae2e588 100644 --- a/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl +++ b/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl @@ -1697,6 +1697,9 @@ FRAGMENT_SHADER_CODE #else +#ifdef SSS_MODE_SKIN + sss_strength = -sss_strength; +#endif diffuse_buffer = vec4(emission + diffuse_light + ambient_light, sss_strength); specular_buffer = vec4(specular_light, metallic); diff --git a/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl index 671e289ed0..1a5dd5ab55 100644 --- a/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl +++ b/servers/rendering/rasterizer_rd/shaders/screen_space_reflection_filter.glsl @@ -69,8 +69,6 @@ float gauss_weight(float p_val) { 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) { @@ -105,17 +103,14 @@ void do_filter(inout vec4 accum, inout float accum_radius, inout float divisor, break; } - float contrib = 0.0; if (d < radius) { - contrib += gauss_weight(d / radius); - } - if (contrib > 0.0) { - accum += imageLoad(source_ssr, tc) * contrib; + float w = gauss_weight(d / radius); + accum += imageLoad(source_ssr, tc) * w; #ifndef VERTICAL_PASS - accum_radius += r * contrib; + accum_radius += r * w; #endif - divisor += contrib; + divisor += w; } } } diff --git a/servers/rendering/rasterizer_rd/shaders/subsurface_scattering.glsl b/servers/rendering/rasterizer_rd/shaders/subsurface_scattering.glsl new file mode 100644 index 0000000000..41f8fde3ca --- /dev/null +++ b/servers/rendering/rasterizer_rd/shaders/subsurface_scattering.glsl @@ -0,0 +1,198 @@ +/* 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 */ + +#ifdef USE_25_SAMPLES +const int kernel_size = 13; + +const vec2 kernel[kernel_size] = vec2[]( + vec2(0.530605, 0.0), + vec2(0.0211412, 0.0208333), + vec2(0.0402784, 0.0833333), + vec2(0.0493588, 0.1875), + vec2(0.0410172, 0.333333), + vec2(0.0263642, 0.520833), + vec2(0.017924, 0.75), + vec2(0.0128496, 1.02083), + vec2(0.0094389, 1.33333), + vec2(0.00700976, 1.6875), + vec2(0.00500364, 2.08333), + vec2(0.00333804, 2.52083), + vec2(0.000973794, 3.0)); + +const vec4 skin_kernel[kernel_size] = vec4[]( + vec4(0.530605, 0.613514, 0.739601, 0), + vec4(0.0211412, 0.0459286, 0.0378196, 0.0208333), + vec4(0.0402784, 0.0657244, 0.04631, 0.0833333), + vec4(0.0493588, 0.0367726, 0.0219485, 0.1875), + vec4(0.0410172, 0.0199899, 0.0118481, 0.333333), + vec4(0.0263642, 0.0119715, 0.00684598, 0.520833), + vec4(0.017924, 0.00711691, 0.00347194, 0.75), + vec4(0.0128496, 0.00356329, 0.00132016, 1.02083), + vec4(0.0094389, 0.00139119, 0.000416598, 1.33333), + vec4(0.00700976, 0.00049366, 0.000151938, 1.6875), + vec4(0.00500364, 0.00020094, 5.28848e-005, 2.08333), + vec4(0.00333804, 7.85443e-005, 1.2945e-005, 2.52083), + vec4(0.000973794, 1.11862e-005, 9.43437e-007, 3)); + +#endif //USE_25_SAMPLES + +#ifdef USE_17_SAMPLES +const int kernel_size = 9; +const vec2 kernel[kernel_size] = vec2[]( + vec2(0.536343, 0.0), + vec2(0.0324462, 0.03125), + vec2(0.0582416, 0.125), + vec2(0.0571056, 0.28125), + vec2(0.0347317, 0.5), + vec2(0.0216301, 0.78125), + vec2(0.0144609, 1.125), + vec2(0.0100386, 1.53125), + vec2(0.00317394, 2.0)); + +const vec4 skin_kernel[kernel_size] = vec4[]( + vec4(0.536343, 0.624624, 0.748867, 0), + vec4(0.0324462, 0.0656718, 0.0532821, 0.03125), + vec4(0.0582416, 0.0659959, 0.0411329, 0.125), + vec4(0.0571056, 0.0287432, 0.0172844, 0.28125), + vec4(0.0347317, 0.0151085, 0.00871983, 0.5), + vec4(0.0216301, 0.00794618, 0.00376991, 0.78125), + vec4(0.0144609, 0.00317269, 0.00106399, 1.125), + vec4(0.0100386, 0.000914679, 0.000275702, 1.53125), + vec4(0.00317394, 0.000134823, 3.77269e-005, 2)); +#endif //USE_17_SAMPLES + +#ifdef USE_11_SAMPLES +const int kernel_size = 6; +const vec2 kernel[kernel_size] = vec2[]( + vec2(0.560479, 0.0), + vec2(0.0771802, 0.08), + vec2(0.0821904, 0.32), + vec2(0.03639, 0.72), + vec2(0.0192831, 1.28), + vec2(0.00471691, 2.0)); + +const vec4 skin_kernel[kernel_size] = vec4[]( + + vec4(0.560479, 0.669086, 0.784728, 0), + vec4(0.0771802, 0.113491, 0.0793803, 0.08), + vec4(0.0821904, 0.0358608, 0.0209261, 0.32), + vec4(0.03639, 0.0130999, 0.00643685, 0.72), + vec4(0.0192831, 0.00282018, 0.00084214, 1.28), + vec4(0.00471691, 0.000184771, 5.07565e-005, 2)); + +#endif //USE_11_SAMPLES + +layout(push_constant, binding = 1, std430) uniform Params { + + ivec2 screen_size; + float camera_z_far; + float camera_z_near; + + bool vertical; + bool orthogonal; + float unit_size; + float scale; + + float depth_scale; + uint pad[3]; +} +params; + +layout(set = 0, binding = 0) uniform sampler2D source_image; +layout(rgba16f, set = 1, binding = 0) uniform restrict writeonly image2D dest_image; +layout(set = 2, binding = 0) uniform sampler2D source_depth; + +void do_filter(inout vec3 color_accum, inout vec3 divisor, vec2 uv, vec2 step, bool p_skin) { + + // Accumulate the other samples: + for (int i = 1; i < kernel_size; i++) { + // Fetch color and depth for current sample: + vec2 offset = uv + kernel[i].y * step; + vec4 color = texture(source_image, offset); + + if (abs(color.a) < 0.001) { + break; //mix no more + } + + vec3 w; + if (p_skin) { + //skin + w = skin_kernel[i].rgb; + } else { + w = vec3(kernel[i].x); + } + + color_accum += color.rgb * w; + divisor += w; + } +} + +void main() { + + // Pixel being shaded + ivec2 ssC = ivec2(gl_GlobalInvocationID.xy); + + if (any(greaterThan(ssC, params.screen_size))) { //too large, do nothing + return; + } + + vec2 uv = (vec2(ssC) + 0.5) / vec2(params.screen_size); + + // Fetch color of current pixel: + vec4 base_color = texture(source_image, uv); + float strength = abs(base_color.a); + + if (strength > 0.0) { + + vec2 dir = params.vertical ? vec2(0.0, 1.0) : vec2(1.0, 0.0); + + // Fetch linear depth of current pixel: + float depth = texture(source_depth, uv).r * 2.0 - 1.0; + float depth_scale; + + 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; + depth_scale = params.unit_size; //remember depth is negative by default in OpenGL + } 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_scale = params.unit_size / depth; //remember depth is negative by default in OpenGL + } + + float scale = mix(params.scale, depth_scale, params.depth_scale); + + // Calculate the final step to fetch the surrounding pixels: + vec2 step = scale * dir; + step *= strength; + step /= 3.0; + // Accumulate the center sample: + + vec3 divisor; + bool skin = bool(base_color.a < 0.0); + + if (skin) { + //skin + divisor = skin_kernel[0].rgb; + } else { + divisor = vec3(kernel[0].x); + } + + vec3 color = base_color.rgb * divisor; + + do_filter(color, divisor, uv, step, skin); + do_filter(color, divisor, uv, -step, skin); + + base_color.rgb = color / divisor; + } + + imageStore(dest_image, ssC, base_color); +} diff --git a/servers/rendering/rendering_server_raster.h b/servers/rendering/rendering_server_raster.h index 8480aa30fc..267efdbacb 100644 --- a/servers/rendering/rendering_server_raster.h +++ b/servers/rendering/rendering_server_raster.h @@ -541,6 +541,8 @@ public: BIND5(environment_set_fog_height, RID, bool, float, float, float) BIND2(screen_space_roughness_limiter_set_active, bool, float) + BIND1(sub_surface_scattering_set_quality, SubSurfaceScatteringQuality) + BIND2(sub_surface_scattering_set_scale, float, float) /* CAMERA EFFECTS */ diff --git a/servers/rendering/rendering_server_wrap_mt.h b/servers/rendering/rendering_server_wrap_mt.h index 13dad3ec18..d0f711838c 100644 --- a/servers/rendering/rendering_server_wrap_mt.h +++ b/servers/rendering/rendering_server_wrap_mt.h @@ -456,6 +456,8 @@ public: FUNC5(environment_set_fog_height, RID, bool, float, float, float) FUNC2(screen_space_roughness_limiter_set_active, bool, float) + FUNC1(sub_surface_scattering_set_quality, SubSurfaceScatteringQuality) + FUNC2(sub_surface_scattering_set_scale, float, float) FUNCRID(camera_effects) diff --git a/servers/rendering/shader_types.cpp b/servers/rendering/shader_types.cpp index ba7b992e51..78fa2c2690 100644 --- a/servers/rendering/shader_types.cpp +++ b/servers/rendering/shader_types.cpp @@ -168,6 +168,8 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_SPATIAL].modes.push_back("depth_test_disabled"); + shader_modes[RS::SHADER_SPATIAL].modes.push_back("sss_mode_skin"); + shader_modes[RS::SHADER_SPATIAL].modes.push_back("cull_back"); shader_modes[RS::SHADER_SPATIAL].modes.push_back("cull_front"); shader_modes[RS::SHADER_SPATIAL].modes.push_back("cull_disabled"); diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 55afd78fda..d417567a23 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2362,6 +2362,13 @@ RenderingServer::RenderingServer() { 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)")); + + GLOBAL_DEF("rendering/quality/subsurface_scattering/subsurface_scattering_quality", 1); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/subsurface_scattering/subsurface_scattering_quality", PropertyInfo(Variant::INT, "rendering/quality/subsurface_scattering/subsurface_scattering_quality", PROPERTY_HINT_ENUM, "Disabled, Low (Fastest),Medium, High (Slowest)")); + GLOBAL_DEF("rendering/quality/subsurface_scattering/subsurface_scattering_scale", 0.05); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/subsurface_scattering/subsurface_scattering_scale", PropertyInfo(Variant::FLOAT, "rendering/quality/subsurface_scattering/subsurface_scattering_scale", PROPERTY_HINT_RANGE, "0.001,1,0.001")); + GLOBAL_DEF("rendering/quality/subsurface_scattering/subsurface_scattering_depth_scale", 0.01); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/subsurface_scattering/subsurface_scattering_depth_scale", PropertyInfo(Variant::FLOAT, "rendering/quality/subsurface_scattering/subsurface_scattering_depth_scale", PROPERTY_HINT_RANGE, "0.001,1,0.001")); } RenderingServer::~RenderingServer() { diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 9726a71f0c..ac8e92be59 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -782,6 +782,16 @@ public: virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) = 0; + enum SubSurfaceScatteringQuality { + SUB_SURFACE_SCATTERING_QUALITY_DISABLED, + SUB_SURFACE_SCATTERING_QUALITY_LOW, + SUB_SURFACE_SCATTERING_QUALITY_MEDIUM, + SUB_SURFACE_SCATTERING_QUALITY_HIGH, + }; + + virtual void sub_surface_scattering_set_quality(SubSurfaceScatteringQuality p_quality) = 0; + virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) = 0; + /* CAMERA EFFECTS */ virtual RID camera_effects_create() = 0; |