summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/material.cpp6
-rw-r--r--scene/resources/visual_shader_nodes.cpp181
-rw-r--r--scene/resources/visual_shader_nodes.h30
3 files changed, 192 insertions, 25 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 50e2de91f7..3f14c7bb62 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -449,10 +449,10 @@ void BaseMaterial3D::_update_shader() {
texfilter_str = "filter_linear_mipmap";
break;
case TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC:
- texfilter_str = "filter_nearest_mipmap_anisotropy";
+ texfilter_str = "filter_nearest_mipmap_anisotropic";
break;
case TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC:
- texfilter_str = "filter_linear_mipmap_anisotropy";
+ texfilter_str = "filter_linear_mipmap_anisotropic";
break;
case TEXTURE_FILTER_MAX:
break; // Internal value, skip.
@@ -2569,7 +2569,7 @@ void BaseMaterial3D::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv2_world_triplanar"), "set_flag", "get_flag", FLAG_UV2_USE_WORLD_TRIPLANAR);
ADD_GROUP("Sampling", "texture_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropy,Linear Mipmap Anisotropy"), "set_texture_filter", "get_texture_filter");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic"), "set_texture_filter", "get_texture_filter");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "texture_repeat"), "set_flag", "get_flag", FLAG_USE_TEXTURE_REPEAT);
ADD_GROUP("Shadows", "");
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 9e60a1243f..afd46aa461 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -4857,34 +4857,106 @@ String VisualShaderNodeTextureUniform::get_output_port_name(int p_port) const {
}
String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+ bool has_colon = false;
String code = _get_qual_str() + "uniform sampler2D " + get_uniform_name();
- switch (texture_type) {
- case TYPE_DATA:
- if (color_default == COLOR_DEFAULT_BLACK) {
- code += " : hint_black;\n";
+ // type
+ {
+ String type_code;
+
+ switch (texture_type) {
+ case TYPE_DATA:
+ if (color_default == COLOR_DEFAULT_BLACK) {
+ type_code = "hint_black";
+ }
+ break;
+ case TYPE_COLOR:
+ if (color_default == COLOR_DEFAULT_BLACK) {
+ type_code = "hint_black_albedo";
+ } else {
+ type_code = "hint_albedo";
+ }
+ break;
+ case TYPE_NORMAL_MAP:
+ type_code = "hint_normal";
+ break;
+ case TYPE_ANISOTROPY:
+ type_code = "hint_anisotropy";
+ break;
+ default:
+ break;
+ }
+
+ if (!type_code.is_empty()) {
+ code += " : " + type_code;
+ has_colon = true;
+ }
+ }
+
+ // filter
+ {
+ String filter_code;
+
+ switch (texture_filter) {
+ case FILTER_NEAREST:
+ filter_code = "filter_nearest";
+ break;
+ case FILTER_LINEAR:
+ filter_code = "filter_linear";
+ break;
+ case FILTER_NEAREST_MIPMAP:
+ filter_code = "filter_nearest_mipmap";
+ break;
+ case FILTER_LINEAR_MIPMAP:
+ filter_code = "filter_linear_mipmap";
+ break;
+ case FILTER_NEAREST_MIPMAP_ANISOTROPIC:
+ filter_code = "filter_nearest_mipmap_anisotropic";
+ break;
+ case FILTER_LINEAR_MIPMAP_ANISOTROPIC:
+ filter_code = "filter_linear_mipmap_anisotropic";
+ break;
+ default:
+ break;
+ }
+
+ if (!filter_code.is_empty()) {
+ if (!has_colon) {
+ code += " : ";
+ has_colon = true;
} else {
- code += ";\n";
+ code += ", ";
}
- break;
- case TYPE_COLOR:
- if (color_default == COLOR_DEFAULT_BLACK) {
- code += " : hint_black_albedo;\n";
+ code += filter_code;
+ }
+ }
+
+ // repeat
+ {
+ String repeat_code;
+
+ switch (texture_repeat) {
+ case REPEAT_ENABLED:
+ repeat_code = "repeat_enable";
+ break;
+ case REPEAT_DISABLED:
+ repeat_code = "repeat_disable";
+ break;
+ default:
+ break;
+ }
+
+ if (!repeat_code.is_empty()) {
+ if (!has_colon) {
+ code += " : ";
} else {
- code += " : hint_albedo;\n";
+ code += ", ";
}
- break;
- case TYPE_NORMAL_MAP:
- code += " : hint_normal;\n";
- break;
- case TYPE_ANISOTROPY:
- code += " : hint_anisotropy;\n";
- break;
- default:
- code += ";\n";
- break;
+ code += repeat_code;
+ }
}
+ code += ";\n";
return code;
}
@@ -4947,13 +5019,56 @@ VisualShaderNodeTextureUniform::ColorDefault VisualShaderNodeTextureUniform::get
return color_default;
}
+void VisualShaderNodeTextureUniform::set_texture_filter(TextureFilter p_filter) {
+ ERR_FAIL_INDEX(int(p_filter), int(FILTER_MAX));
+ if (texture_filter == p_filter) {
+ return;
+ }
+ texture_filter = p_filter;
+ emit_changed();
+}
+
+VisualShaderNodeTextureUniform::TextureFilter VisualShaderNodeTextureUniform::get_texture_filter() const {
+ return texture_filter;
+}
+
+void VisualShaderNodeTextureUniform::set_texture_repeat(TextureRepeat p_repeat) {
+ ERR_FAIL_INDEX(int(p_repeat), int(REPEAT_MAX));
+ if (texture_repeat == p_repeat) {
+ return;
+ }
+ texture_repeat = p_repeat;
+ emit_changed();
+}
+
+VisualShaderNodeTextureUniform::TextureRepeat VisualShaderNodeTextureUniform::get_texture_repeat() const {
+ return texture_repeat;
+}
+
Vector<StringName> VisualShaderNodeTextureUniform::get_editable_properties() const {
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("texture_type");
- props.push_back("color_default");
+ if (texture_type == TYPE_DATA || texture_type == TYPE_COLOR) {
+ props.push_back("color_default");
+ }
+ props.push_back("texture_filter");
+ props.push_back("texture_repeat");
return props;
}
+bool VisualShaderNodeTextureUniform::is_show_prop_names() const {
+ return true;
+}
+
+Map<StringName, String> VisualShaderNodeTextureUniform::get_editable_properties_names() const {
+ Map<StringName, String> names;
+ names.insert("texture_type", TTR("Type"));
+ names.insert("color_default", TTR("Default Color"));
+ names.insert("texture_filter", TTR("Filter"));
+ names.insert("texture_repeat", TTR("Repeat"));
+ return names;
+}
+
void VisualShaderNodeTextureUniform::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture_type", "type"), &VisualShaderNodeTextureUniform::set_texture_type);
ClassDB::bind_method(D_METHOD("get_texture_type"), &VisualShaderNodeTextureUniform::get_texture_type);
@@ -4961,8 +5076,16 @@ void VisualShaderNodeTextureUniform::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_color_default", "type"), &VisualShaderNodeTextureUniform::set_color_default);
ClassDB::bind_method(D_METHOD("get_color_default"), &VisualShaderNodeTextureUniform::get_color_default);
+ ClassDB::bind_method(D_METHOD("set_texture_filter", "filter"), &VisualShaderNodeTextureUniform::set_texture_filter);
+ ClassDB::bind_method(D_METHOD("get_texture_filter"), &VisualShaderNodeTextureUniform::get_texture_filter);
+
+ ClassDB::bind_method(D_METHOD("set_texture_repeat", "type"), &VisualShaderNodeTextureUniform::set_texture_repeat);
+ ClassDB::bind_method(D_METHOD("get_texture_repeat"), &VisualShaderNodeTextureUniform::get_texture_repeat);
+
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normal Map,Anisotropic"), "set_texture_type", "get_texture_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "color_default", PROPERTY_HINT_ENUM, "White Default,Black Default"), "set_color_default", "get_color_default");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "color_default", PROPERTY_HINT_ENUM, "White,Black"), "set_color_default", "get_color_default");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Default,Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic"), "set_texture_filter", "get_texture_filter");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Default,Enabled,Disabled"), "set_texture_repeat", "get_texture_repeat");
BIND_ENUM_CONSTANT(TYPE_DATA);
BIND_ENUM_CONSTANT(TYPE_COLOR);
@@ -4973,6 +5096,20 @@ void VisualShaderNodeTextureUniform::_bind_methods() {
BIND_ENUM_CONSTANT(COLOR_DEFAULT_WHITE);
BIND_ENUM_CONSTANT(COLOR_DEFAULT_BLACK);
BIND_ENUM_CONSTANT(COLOR_DEFAULT_MAX);
+
+ BIND_ENUM_CONSTANT(FILTER_DEFAULT);
+ BIND_ENUM_CONSTANT(FILTER_NEAREST);
+ BIND_ENUM_CONSTANT(FILTER_LINEAR);
+ BIND_ENUM_CONSTANT(FILTER_NEAREST_MIPMAP);
+ BIND_ENUM_CONSTANT(FILTER_LINEAR_MIPMAP);
+ BIND_ENUM_CONSTANT(FILTER_NEAREST_MIPMAP_ANISOTROPIC);
+ BIND_ENUM_CONSTANT(FILTER_LINEAR_MIPMAP_ANISOTROPIC);
+ BIND_ENUM_CONSTANT(FILTER_MAX);
+
+ BIND_ENUM_CONSTANT(REPEAT_DEFAULT);
+ BIND_ENUM_CONSTANT(REPEAT_ENABLED);
+ BIND_ENUM_CONSTANT(REPEAT_DISABLED);
+ BIND_ENUM_CONSTANT(REPEAT_MAX);
}
String VisualShaderNodeTextureUniform::get_input_port_default_hint(int p_port) const {
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index a9ad762b32..a9fa21f164 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -1953,9 +1953,29 @@ public:
COLOR_DEFAULT_MAX,
};
+ enum TextureFilter {
+ FILTER_DEFAULT,
+ FILTER_NEAREST,
+ FILTER_LINEAR,
+ FILTER_NEAREST_MIPMAP,
+ FILTER_LINEAR_MIPMAP,
+ FILTER_NEAREST_MIPMAP_ANISOTROPIC,
+ FILTER_LINEAR_MIPMAP_ANISOTROPIC,
+ FILTER_MAX,
+ };
+
+ enum TextureRepeat {
+ REPEAT_DEFAULT,
+ REPEAT_ENABLED,
+ REPEAT_DISABLED,
+ REPEAT_MAX,
+ };
+
protected:
TextureType texture_type = TYPE_DATA;
ColorDefault color_default = COLOR_DEFAULT_WHITE;
+ TextureFilter texture_filter = FILTER_DEFAULT;
+ TextureRepeat texture_repeat = REPEAT_DEFAULT;
protected:
static void _bind_methods();
@@ -1975,6 +1995,8 @@ public:
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
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 override;
+ virtual Map<StringName, String> get_editable_properties_names() const override;
+ virtual bool is_show_prop_names() const override;
virtual bool is_code_generated() const override;
Vector<StringName> get_editable_properties() const override;
@@ -1985,6 +2007,12 @@ public:
void set_color_default(ColorDefault p_default);
ColorDefault get_color_default() const;
+ void set_texture_filter(TextureFilter p_filter);
+ TextureFilter get_texture_filter() const;
+
+ void set_texture_repeat(TextureRepeat p_repeat);
+ TextureRepeat get_texture_repeat() const;
+
bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;
@@ -1993,6 +2021,8 @@ public:
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureType)
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::ColorDefault)
+VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureFilter)
+VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureRepeat)
///////////////////////////////////////