diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/light_3d.cpp | 7 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 3 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 3 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 15 | ||||
-rw-r--r-- | scene/gui/file_dialog.h | 7 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 13 | ||||
-rw-r--r-- | scene/gui/graph_edit.h | 10 | ||||
-rw-r--r-- | scene/gui/tool_button.cpp | 35 | ||||
-rw-r--r-- | scene/gui/tool_button.h | 43 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 3 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 6 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 24 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.cpp | 245 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.h | 87 |
14 files changed, 385 insertions, 116 deletions
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp index ef24676d69..9270b548b7 100644 --- a/scene/3d/light_3d.cpp +++ b/scene/3d/light_3d.cpp @@ -424,9 +424,11 @@ DirectionalLight3D::DirectionalLight3D() : Light3D(RenderingServer::LIGHT_DIRECTIONAL) { set_param(PARAM_SHADOW_MAX_DISTANCE, 100); set_param(PARAM_SHADOW_FADE_START, 0.8); + // Increase the default shadow bias to better suit most scenes. + // Leave normal bias untouched as it doesn't benefit DirectionalLight3D as much as OmniLight3D. + set_param(PARAM_SHADOW_BIAS, 0.05); set_shadow_mode(SHADOW_PARALLEL_4_SPLITS); set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE); - blend_splits = false; } @@ -468,6 +470,9 @@ void OmniLight3D::_bind_methods() { OmniLight3D::OmniLight3D() : Light3D(RenderingServer::LIGHT_OMNI) { set_shadow_mode(SHADOW_CUBE); + // Increase the default shadow biases to better suit most scenes. + set_param(PARAM_SHADOW_BIAS, 0.1); + set_param(PARAM_SHADOW_NORMAL_BIAS, 2.0); } String SpotLight3D::get_configuration_warning() const { diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 84170a65d1..fafbb298b7 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -758,7 +758,8 @@ ColorPicker::ColorPicker() : sample->set_h_size_flags(SIZE_EXPAND_FILL); sample->connect("draw", callable_mp(this, &ColorPicker::_sample_draw)); - btn_pick = memnew(ToolButton); + btn_pick = memnew(Button); + btn_pick->set_flat(true); hb_smpl->add_child(btn_pick); btn_pick->set_toggle_mode(true); btn_pick->set_tooltip(TTR("Pick a color from the editor window.")); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 31ae92f4e4..b2e8263e7f 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -41,7 +41,6 @@ #include "scene/gui/slider.h" #include "scene/gui/spin_box.h" #include "scene/gui/texture_rect.h" -#include "scene/gui/tool_button.h" class ColorPicker : public BoxContainer { GDCLASS(ColorPicker, BoxContainer); @@ -57,7 +56,7 @@ private: HSeparator *preset_separator; Button *bt_add_preset; List<Color> presets; - ToolButton *btn_pick; + Button *btn_pick; CheckButton *btn_hsv; CheckButton *btn_raw; HSlider *scroll[4]; diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 630f3c8ff6..41ca6458af 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -45,9 +45,9 @@ VBoxContainer *FileDialog::get_vbox() { } void FileDialog::_theme_changed() { - Color font_color = vbox->get_theme_color("font_color", "ToolButton"); - Color font_color_hover = vbox->get_theme_color("font_color_hover", "ToolButton"); - Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "ToolButton"); + Color font_color = vbox->get_theme_color("font_color", "Button"); + Color font_color_hover = vbox->get_theme_color("font_color_hover", "Button"); + Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "Button"); dir_up->add_theme_color_override("icon_color_normal", font_color); dir_up->add_theme_color_override("icon_color_hover", font_color_hover); @@ -859,7 +859,8 @@ FileDialog::FileDialog() { HBoxContainer *hbc = memnew(HBoxContainer); - dir_up = memnew(ToolButton); + dir_up = memnew(Button); + dir_up->set_flat(true); dir_up->set_tooltip(RTR("Go to parent folder.")); hbc->add_child(dir_up); dir_up->connect("pressed", callable_mp(this, &FileDialog::_go_up)); @@ -877,12 +878,14 @@ FileDialog::FileDialog() { hbc->add_child(dir); dir->set_h_size_flags(Control::SIZE_EXPAND_FILL); - refresh = memnew(ToolButton); + refresh = memnew(Button); + refresh->set_flat(true); refresh->set_tooltip(RTR("Refresh files.")); refresh->connect("pressed", callable_mp(this, &FileDialog::update_file_list)); hbc->add_child(refresh); - show_hidden = memnew(ToolButton); + show_hidden = memnew(Button); + show_hidden->set_flat(true); show_hidden->set_toggle_mode(true); show_hidden->set_pressed(is_showing_hidden_files()); show_hidden->set_tooltip(RTR("Toggle the visibility of hidden files.")); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 8bc536d576..44050a2376 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -36,7 +36,6 @@ #include "scene/gui/dialogs.h" #include "scene/gui/line_edit.h" #include "scene/gui/option_button.h" -#include "scene/gui/tool_button.h" #include "scene/gui/tree.h" class FileDialog : public ConfirmationDialog { @@ -87,10 +86,10 @@ private: DirAccess *dir_access; ConfirmationDialog *confirm_save; - ToolButton *dir_up; + Button *dir_up; - ToolButton *refresh; - ToolButton *show_hidden; + Button *refresh; + Button *show_hidden; Vector<String> filters; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 5080ba74e2..2b0e084db4 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -33,6 +33,7 @@ #include "core/input/input.h" #include "core/os/keyboard.h" #include "scene/gui/box_container.h" +#include "scene/gui/button.h" #ifdef TOOLS_ENABLED #include "editor/editor_scale.h" @@ -1310,25 +1311,29 @@ GraphEdit::GraphEdit() { top_layer->add_child(zoom_hb); zoom_hb->set_position(Vector2(10, 10)); - zoom_minus = memnew(ToolButton); + zoom_minus = memnew(Button); + zoom_minus->set_flat(true); zoom_hb->add_child(zoom_minus); zoom_minus->set_tooltip(RTR("Zoom Out")); zoom_minus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus)); zoom_minus->set_focus_mode(FOCUS_NONE); - zoom_reset = memnew(ToolButton); + zoom_reset = memnew(Button); + zoom_reset->set_flat(true); zoom_hb->add_child(zoom_reset); zoom_reset->set_tooltip(RTR("Zoom Reset")); zoom_reset->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset)); zoom_reset->set_focus_mode(FOCUS_NONE); - zoom_plus = memnew(ToolButton); + zoom_plus = memnew(Button); + zoom_plus->set_flat(true); zoom_hb->add_child(zoom_plus); zoom_plus->set_tooltip(RTR("Zoom In")); zoom_plus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus)); zoom_plus->set_focus_mode(FOCUS_NONE); - snap_button = memnew(ToolButton); + snap_button = memnew(Button); + snap_button->set_flat(true); snap_button->set_toggle_mode(true); snap_button->set_tooltip(RTR("Enable snap and show grid.")); snap_button->connect("pressed", callable_mp(this, &GraphEdit::_snap_toggled)); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index c632490855..a627a8eec8 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -32,12 +32,12 @@ #define GRAPH_EDIT_H #include "scene/gui/box_container.h" +#include "scene/gui/button.h" #include "scene/gui/graph_node.h" #include "scene/gui/scroll_bar.h" #include "scene/gui/slider.h" #include "scene/gui/spin_box.h" #include "scene/gui/texture_rect.h" -#include "scene/gui/tool_button.h" class GraphEdit; @@ -65,11 +65,11 @@ public: }; private: - ToolButton *zoom_minus; - ToolButton *zoom_reset; - ToolButton *zoom_plus; + Button *zoom_minus; + Button *zoom_reset; + Button *zoom_plus; - ToolButton *snap_button; + Button *snap_button; SpinBox *snap_amount; void _zoom_minus(); diff --git a/scene/gui/tool_button.cpp b/scene/gui/tool_button.cpp deleted file mode 100644 index c9f87f0015..0000000000 --- a/scene/gui/tool_button.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************/ -/* tool_button.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "tool_button.h" - -ToolButton::ToolButton() { - set_flat(true); -} diff --git a/scene/gui/tool_button.h b/scene/gui/tool_button.h deleted file mode 100644 index 9848b21381..0000000000 --- a/scene/gui/tool_button.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************/ -/* tool_button.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TOOL_BUTTON_H -#define TOOL_BUTTON_H - -#include "scene/gui/button.h" - -class ToolButton : public Button { - GDCLASS(ToolButton, Button); - -public: - ToolButton(); -}; - -#endif // TOOL_BUTTON_H diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index a0e10f30c0..3c3c7533a3 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -170,6 +170,7 @@ void SceneTree::_flush_ugc() { v[i] = E->get()[i]; } + static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5"); call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4]); unique_group_calls.erase(E); @@ -907,6 +908,7 @@ Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Cal v[i] = *p_args[i + 3]; } + static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5"); call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4]); return Variant(); } @@ -926,6 +928,7 @@ Variant SceneTree::_call_group(const Variant **p_args, int p_argcount, Callable: v[i] = *p_args[i + 2]; } + static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5"); call_group_flags(0, group, method, v[0], v[1], v[2], v[3], v[4]); return Variant(); } diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 2d0e2daf41..54112ef2bd 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -117,7 +117,6 @@ #include "scene/gui/texture_button.h" #include "scene/gui/texture_progress.h" #include "scene/gui/texture_rect.h" -#include "scene/gui/tool_button.h" #include "scene/gui/tree.h" #include "scene/gui/video_player.h" #include "scene/main/canvas_item.h" @@ -306,7 +305,6 @@ void register_scene_types() { ClassDB::register_class<MenuButton>(); ClassDB::register_class<CheckBox>(); ClassDB::register_class<CheckButton>(); - ClassDB::register_class<ToolButton>(); ClassDB::register_class<LinkButton>(); ClassDB::register_class<Panel>(); ClassDB::register_virtual_class<Range>(); @@ -541,6 +539,8 @@ void register_scene_types() { ClassDB::register_class<VisualShaderNodeVectorDecompose>(); ClassDB::register_class<VisualShaderNodeTransformDecompose>(); ClassDB::register_class<VisualShaderNodeTexture>(); + ClassDB::register_virtual_class<VisualShaderNodeSample3D>(); + ClassDB::register_class<VisualShaderNodeTexture2DArray>(); ClassDB::register_class<VisualShaderNodeCubemap>(); ClassDB::register_virtual_class<VisualShaderNodeUniform>(); ClassDB::register_class<VisualShaderNodeFloatUniform>(); @@ -551,6 +551,7 @@ void register_scene_types() { ClassDB::register_class<VisualShaderNodeTransformUniform>(); ClassDB::register_class<VisualShaderNodeTextureUniform>(); ClassDB::register_class<VisualShaderNodeTextureUniformTriplanar>(); + ClassDB::register_class<VisualShaderNodeTexture2DArrayUniform>(); ClassDB::register_class<VisualShaderNodeCubemapUniform>(); ClassDB::register_class<VisualShaderNodeIf>(); ClassDB::register_class<VisualShaderNodeSwitch>(); @@ -764,6 +765,7 @@ void register_scene_types() { #ifndef DISABLE_DEPRECATED // Dropped in 4.0, near approximation. ClassDB::add_compatibility_class("AnimationTreePlayer", "AnimationTree"); + ClassDB::add_compatibility_class("ToolButton", "Button"); // Renamed in 4.0. // Keep alphabetical ordering to easily locate classes and avoid duplicates. diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index fd5c861eb5..aebb0d7ba4 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -219,21 +219,21 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_constant("hseparation", "ColorPickerButton", 2 * scale); - // ToolButton + // Button - theme->set_stylebox("normal", "ToolButton", make_empty_stylebox(6, 4, 6, 4)); - theme->set_stylebox("pressed", "ToolButton", make_stylebox(button_pressed_png, 4, 4, 4, 4, 6, 4, 6, 4)); - theme->set_stylebox("hover", "ToolButton", make_stylebox(button_normal_png, 4, 4, 4, 4, 6, 4, 6, 4)); - theme->set_stylebox("disabled", "ToolButton", make_empty_stylebox(6, 4, 6, 4)); - theme->set_stylebox("focus", "ToolButton", focus); - theme->set_font("font", "ToolButton", default_font); + theme->set_stylebox("normal", "Button", make_empty_stylebox(6, 4, 6, 4)); + theme->set_stylebox("pressed", "Button", make_stylebox(button_pressed_png, 4, 4, 4, 4, 6, 4, 6, 4)); + theme->set_stylebox("hover", "Button", make_stylebox(button_normal_png, 4, 4, 4, 4, 6, 4, 6, 4)); + theme->set_stylebox("disabled", "Button", make_empty_stylebox(6, 4, 6, 4)); + theme->set_stylebox("focus", "Button", focus); + theme->set_font("font", "Button", default_font); - theme->set_color("font_color", "ToolButton", control_font_color); - theme->set_color("font_color_pressed", "ToolButton", control_font_color_pressed); - theme->set_color("font_color_hover", "ToolButton", control_font_color_hover); - theme->set_color("font_color_disabled", "ToolButton", Color(0.9, 0.95, 1, 0.3)); + theme->set_color("font_color", "Button", control_font_color); + theme->set_color("font_color_pressed", "Button", control_font_color_pressed); + theme->set_color("font_color_hover", "Button", control_font_color_hover); + theme->set_color("font_color_disabled", "Button", Color(0.9, 0.95, 1, 0.3)); - theme->set_constant("hseparation", "ToolButton", 3); + theme->set_constant("hseparation", "Button", 3); // OptionButton diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 87720cf110..5c6b13a527 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -781,6 +781,183 @@ VisualShaderNodeTexture::VisualShaderNodeTexture() { source = SOURCE_TEXTURE; } +////////////// Sample3D + +int VisualShaderNodeSample3D::get_input_port_count() const { + return 3; +} + +VisualShaderNodeSample3D::PortType VisualShaderNodeSample3D::get_input_port_type(int p_port) const { + switch (p_port) { + case 0: + return PORT_TYPE_VECTOR; + case 1: + return PORT_TYPE_SCALAR; + case 2: + return PORT_TYPE_SAMPLER; + default: + return PORT_TYPE_SCALAR; + } +} + +String VisualShaderNodeSample3D::get_input_port_name(int p_port) const { + switch (p_port) { + case 0: + return "uvw"; + case 1: + return "lod"; + default: + return ""; + } +} + +int VisualShaderNodeSample3D::get_output_port_count() const { + return 2; +} + +VisualShaderNodeSample3D::PortType VisualShaderNodeSample3D::get_output_port_type(int p_port) const { + return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; +} + +String VisualShaderNodeSample3D::get_output_port_name(int p_port) const { + return p_port == 0 ? "rgb" : "alpha"; +} + +String VisualShaderNodeSample3D::get_input_port_default_hint(int p_port) const { + if (p_port == 0) { + return "vec3(UV.xy, 0.0)"; + } + return ""; +} + +String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { + String code; + if (source == SOURCE_TEXTURE || source == SOURCE_PORT) { + String id; + code += "\t{\n"; + if (source == SOURCE_TEXTURE) { + id = make_unique_id(p_type, p_id, "tex3d"); + } else { + id = p_input_vars[2]; + } + if (id != String()) { + if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[1] == String()) { + code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", vec3(UV.xy, 0.0));\n"; + } else { + code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", vec3(UV.xy, 0.0), " + p_input_vars[1] + ");\n"; + } + } else if (p_input_vars[1] == String()) { + //no lod + code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; + } else { + code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + } + } else { + code += "\t\tvec4 " + id + "_tex_read = vec4(0.0);\n"; + } + + code += "\t\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n"; + code += "\t\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n"; + code += "\t}\n"; + return code; + } + code += "\t" + p_output_vars[0] + " = vec3(0.0);\n"; + code += "\t" + p_output_vars[1] + " = 1.0;\n"; + return code; +} + +void VisualShaderNodeSample3D::set_source(Source p_source) { + source = p_source; + emit_changed(); + emit_signal("editor_refresh_request"); +} + +VisualShaderNodeSample3D::Source VisualShaderNodeSample3D::get_source() const { + return source; +} + +void VisualShaderNodeSample3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_source", "value"), &VisualShaderNodeSample3D::set_source); + ClassDB::bind_method(D_METHOD("get_source"), &VisualShaderNodeSample3D::get_source); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "source", PROPERTY_HINT_ENUM, "Texture,SamplerPort"), "set_source", "get_source"); + + BIND_ENUM_CONSTANT(SOURCE_TEXTURE); + BIND_ENUM_CONSTANT(SOURCE_PORT); +} + +String VisualShaderNodeSample3D::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { + if (source == SOURCE_TEXTURE) { + return String(); // all good + } + if (source == SOURCE_PORT) { + return String(); // all good + } + return TTR("Invalid source for shader."); +} + +VisualShaderNodeSample3D::VisualShaderNodeSample3D() { + source = SOURCE_TEXTURE; + simple_decl = false; +} + +////////////// Texture2DArray + +String VisualShaderNodeTexture2DArray::get_caption() const { + return "Texture2DArray"; +} + +String VisualShaderNodeTexture2DArray::get_input_port_name(int p_port) const { + if (p_port == 2) { + return "sampler2DArray"; + } + return VisualShaderNodeSample3D::get_input_port_name(p_port); +} + +Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture2DArray::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const { + VisualShader::DefaultTextureParam dtp; + dtp.name = make_unique_id(p_type, p_id, "tex3d"); + dtp.param = texture; + Vector<VisualShader::DefaultTextureParam> ret; + ret.push_back(dtp); + return ret; +} + +String VisualShaderNodeTexture2DArray::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { + if (source == SOURCE_TEXTURE) { + return "uniform sampler2DArray " + make_unique_id(p_type, p_id, "tex3d") + ";\n"; + } + return String(); +} + +void VisualShaderNodeTexture2DArray::set_texture_array(Ref<Texture2DArray> p_value) { + texture = p_value; + emit_changed(); +} + +Ref<Texture2DArray> VisualShaderNodeTexture2DArray::get_texture_array() const { + return texture; +} + +Vector<StringName> VisualShaderNodeTexture2DArray::get_editable_properties() const { + Vector<StringName> props; + props.push_back("source"); + if (source == SOURCE_TEXTURE) { + props.push_back("texture_array"); + } + return props; +} + +void VisualShaderNodeTexture2DArray::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_texture_array", "value"), &VisualShaderNodeTexture2DArray::set_texture_array); + ClassDB::bind_method(D_METHOD("get_texture_array"), &VisualShaderNodeTexture2DArray::get_texture_array); + + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_array", PROPERTY_HINT_RESOURCE_TYPE, "Texture2DArray"), "set_texture_array", "get_texture_array"); +} + +VisualShaderNodeTexture2DArray::VisualShaderNodeTexture2DArray() { +} ////////////// Cubemap String VisualShaderNodeCubemap::get_caption() const { @@ -3926,6 +4103,74 @@ String VisualShaderNodeTextureUniformTriplanar::get_input_port_default_hint(int VisualShaderNodeTextureUniformTriplanar::VisualShaderNodeTextureUniformTriplanar() { } +////////////// Texture2DArray Uniform + +String VisualShaderNodeTexture2DArrayUniform::get_caption() const { + return "Texture2DArrayUniform"; +} + +int VisualShaderNodeTexture2DArrayUniform::get_output_port_count() const { + return 1; +} + +VisualShaderNodeTexture2DArrayUniform::PortType VisualShaderNodeTexture2DArrayUniform::get_output_port_type(int p_port) const { + return PORT_TYPE_SAMPLER; +} + +String VisualShaderNodeTexture2DArrayUniform::get_output_port_name(int p_port) const { + return "sampler2DArray"; +} + +int VisualShaderNodeTexture2DArrayUniform::get_input_port_count() const { + return 0; +} + +VisualShaderNodeTexture2DArrayUniform::PortType VisualShaderNodeTexture2DArrayUniform::get_input_port_type(int p_port) const { + return PORT_TYPE_SCALAR; +} + +String VisualShaderNodeTexture2DArrayUniform::get_input_port_name(int p_port) const { + return ""; +} + +String VisualShaderNodeTexture2DArrayUniform::get_input_port_default_hint(int p_port) const { + return ""; +} + +String VisualShaderNodeTexture2DArrayUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { + String code = _get_qual_str() + "uniform sampler2DArray " + get_uniform_name(); + + switch (texture_type) { + case TYPE_DATA: + if (color_default == COLOR_DEFAULT_BLACK) + code += " : hint_black;\n"; + else + code += ";\n"; + break; + case TYPE_COLOR: + if (color_default == COLOR_DEFAULT_BLACK) + code += " : hint_black_albedo;\n"; + else + code += " : hint_albedo;\n"; + break; + case TYPE_NORMALMAP: + code += " : hint_normal;\n"; + break; + case TYPE_ANISO: + code += " : hint_aniso;\n"; + break; + } + + return code; +} + +String VisualShaderNodeTexture2DArrayUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { + return String(); +} + +VisualShaderNodeTexture2DArrayUniform::VisualShaderNodeTexture2DArrayUniform() { +} + ////////////// Cubemap Uniform String VisualShaderNodeCubemapUniform::get_caption() const { diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index 69f42f621a..28a9de6819 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -236,7 +236,7 @@ public: enum TextureType { TYPE_DATA, TYPE_COLOR, - TYPE_NORMALMAP + TYPE_NORMALMAP, }; private: @@ -284,6 +284,68 @@ VARIANT_ENUM_CAST(VisualShaderNodeTexture::Source) /////////////////////////////////////// +class VisualShaderNodeSample3D : public VisualShaderNode { + GDCLASS(VisualShaderNodeSample3D, VisualShaderNode); + +public: + enum Source { + SOURCE_TEXTURE, + SOURCE_PORT, + }; + +protected: + Source source; + + static void _bind_methods(); + +public: + virtual String get_caption() const = 0; + + virtual int get_input_port_count() const; + virtual PortType get_input_port_type(int p_port) const; + virtual String get_input_port_name(int p_port) const; + virtual String get_input_port_default_hint(int p_port) const; + + virtual int get_output_port_count() const; + virtual PortType get_output_port_type(int p_port) const; + virtual String get_output_port_name(int p_port) const; + + virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const = 0; + virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty + + void set_source(Source p_source); + Source get_source() const; + + virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const; + + VisualShaderNodeSample3D(); +}; + +VARIANT_ENUM_CAST(VisualShaderNodeSample3D::Source) + +class VisualShaderNodeTexture2DArray : public VisualShaderNodeSample3D { + GDCLASS(VisualShaderNodeTexture2DArray, VisualShaderNodeSample3D); + Ref<Texture2DArray> texture; + +protected: + static void _bind_methods(); + +public: + virtual String get_caption() const; + + virtual String get_input_port_name(int p_port) const; + + virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const; + virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const; + + void set_texture_array(Ref<Texture2DArray> p_value); + Ref<Texture2DArray> get_texture_array() const; + + virtual Vector<StringName> get_editable_properties() const; + + VisualShaderNodeTexture2DArray(); +}; + class VisualShaderNodeCubemap : public VisualShaderNode { GDCLASS(VisualShaderNodeCubemap, VisualShaderNode); Ref<Cubemap> cube_map; @@ -1695,6 +1757,29 @@ public: /////////////////////////////////////// +class VisualShaderNodeTexture2DArrayUniform : public VisualShaderNodeTextureUniform { + GDCLASS(VisualShaderNodeTexture2DArrayUniform, VisualShaderNodeTextureUniform); + +public: + virtual String get_caption() const; + + virtual int get_input_port_count() const; + virtual PortType get_input_port_type(int p_port) const; + virtual String get_input_port_name(int p_port) const; + + virtual int get_output_port_count() const; + virtual PortType get_output_port_type(int p_port) const; + virtual String get_output_port_name(int p_port) const; + + virtual String get_input_port_default_hint(int p_port) const; + virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const; + virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty + + VisualShaderNodeTexture2DArrayUniform(); +}; + +/////////////////////////////////////// + class VisualShaderNodeCubemapUniform : public VisualShaderNodeTextureUniform { GDCLASS(VisualShaderNodeCubemapUniform, VisualShaderNodeTextureUniform); |