summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/default_theme/default_theme.cpp24
-rw-r--r--scene/resources/visual_shader_nodes.cpp245
-rw-r--r--scene/resources/visual_shader_nodes.h87
3 files changed, 343 insertions, 13 deletions
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);