You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Merge pull request #55982 from Chaosus/vs_texture_filtering
This commit is contained in:
@@ -12,6 +12,12 @@
|
|||||||
<member name="color_default" type="int" setter="set_color_default" getter="get_color_default" enum="VisualShaderNodeTextureUniform.ColorDefault" default="0">
|
<member name="color_default" type="int" setter="set_color_default" getter="get_color_default" enum="VisualShaderNodeTextureUniform.ColorDefault" default="0">
|
||||||
Sets the default color if no texture is assigned to the uniform.
|
Sets the default color if no texture is assigned to the uniform.
|
||||||
</member>
|
</member>
|
||||||
|
<member name="texture_filter" type="int" setter="set_texture_filter" getter="get_texture_filter" enum="VisualShaderNodeTextureUniform.TextureFilter" default="0">
|
||||||
|
Sets the texture filtering mode. See [enum TextureFilter] for options.
|
||||||
|
</member>
|
||||||
|
<member name="texture_repeat" type="int" setter="set_texture_repeat" getter="get_texture_repeat" enum="VisualShaderNodeTextureUniform.TextureRepeat" default="0">
|
||||||
|
Sets the texture repeating mode. See [enum TextureRepeat] for options.
|
||||||
|
</member>
|
||||||
<member name="texture_type" type="int" setter="set_texture_type" getter="get_texture_type" enum="VisualShaderNodeTextureUniform.TextureType" default="0">
|
<member name="texture_type" type="int" setter="set_texture_type" getter="get_texture_type" enum="VisualShaderNodeTextureUniform.TextureType" default="0">
|
||||||
Defines the type of data provided by the source texture. See [enum TextureType] for options.
|
Defines the type of data provided by the source texture. See [enum TextureType] for options.
|
||||||
</member>
|
</member>
|
||||||
@@ -41,5 +47,31 @@
|
|||||||
<constant name="COLOR_DEFAULT_MAX" value="2" enum="ColorDefault">
|
<constant name="COLOR_DEFAULT_MAX" value="2" enum="ColorDefault">
|
||||||
Represents the size of the [enum ColorDefault] enum.
|
Represents the size of the [enum ColorDefault] enum.
|
||||||
</constant>
|
</constant>
|
||||||
|
<constant name="FILTER_DEFAULT" value="0" enum="TextureFilter">
|
||||||
|
</constant>
|
||||||
|
<constant name="FILTER_NEAREST" value="1" enum="TextureFilter">
|
||||||
|
</constant>
|
||||||
|
<constant name="FILTER_LINEAR" value="2" enum="TextureFilter">
|
||||||
|
</constant>
|
||||||
|
<constant name="FILTER_NEAREST_MIPMAP" value="3" enum="TextureFilter">
|
||||||
|
</constant>
|
||||||
|
<constant name="FILTER_LINEAR_MIPMAP" value="4" enum="TextureFilter">
|
||||||
|
</constant>
|
||||||
|
<constant name="FILTER_NEAREST_MIPMAP_ANISOTROPIC" value="5" enum="TextureFilter">
|
||||||
|
</constant>
|
||||||
|
<constant name="FILTER_LINEAR_MIPMAP_ANISOTROPIC" value="6" enum="TextureFilter">
|
||||||
|
</constant>
|
||||||
|
<constant name="FILTER_MAX" value="7" enum="TextureFilter">
|
||||||
|
Represents the size of the [enum TextureFilter] enum.
|
||||||
|
</constant>
|
||||||
|
<constant name="REPEAT_DEFAULT" value="0" enum="TextureRepeat">
|
||||||
|
</constant>
|
||||||
|
<constant name="REPEAT_ENABLED" value="1" enum="TextureRepeat">
|
||||||
|
</constant>
|
||||||
|
<constant name="REPEAT_DISABLED" value="2" enum="TextureRepeat">
|
||||||
|
</constant>
|
||||||
|
<constant name="REPEAT_MAX" value="3" enum="TextureRepeat">
|
||||||
|
Represents the size of the [enum TextureRepeat] enum.
|
||||||
|
</constant>
|
||||||
</constants>
|
</constants>
|
||||||
</class>
|
</class>
|
||||||
|
|||||||
@@ -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 {
|
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();
|
String code = _get_qual_str() + "uniform sampler2D " + get_uniform_name();
|
||||||
|
|
||||||
switch (texture_type) {
|
// type
|
||||||
case TYPE_DATA:
|
{
|
||||||
if (color_default == COLOR_DEFAULT_BLACK) {
|
String type_code;
|
||||||
code += " : hint_black;\n";
|
|
||||||
} else {
|
switch (texture_type) {
|
||||||
code += ";\n";
|
case TYPE_DATA:
|
||||||
}
|
if (color_default == COLOR_DEFAULT_BLACK) {
|
||||||
break;
|
type_code = "hint_black";
|
||||||
case TYPE_COLOR:
|
}
|
||||||
if (color_default == COLOR_DEFAULT_BLACK) {
|
break;
|
||||||
code += " : hint_black_albedo;\n";
|
case TYPE_COLOR:
|
||||||
} else {
|
if (color_default == COLOR_DEFAULT_BLACK) {
|
||||||
code += " : hint_albedo;\n";
|
type_code = "hint_black_albedo";
|
||||||
}
|
} else {
|
||||||
break;
|
type_code = "hint_albedo";
|
||||||
case TYPE_NORMAL_MAP:
|
}
|
||||||
code += " : hint_normal;\n";
|
break;
|
||||||
break;
|
case TYPE_NORMAL_MAP:
|
||||||
case TYPE_ANISOTROPY:
|
type_code = "hint_normal";
|
||||||
code += " : hint_anisotropy;\n";
|
break;
|
||||||
break;
|
case TYPE_ANISOTROPY:
|
||||||
default:
|
type_code = "hint_anisotropy";
|
||||||
code += ";\n";
|
break;
|
||||||
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 += ", ";
|
||||||
|
}
|
||||||
|
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 += ", ";
|
||||||
|
}
|
||||||
|
code += repeat_code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
code += ";\n";
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4947,13 +5019,56 @@ VisualShaderNodeTextureUniform::ColorDefault VisualShaderNodeTextureUniform::get
|
|||||||
return color_default;
|
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> VisualShaderNodeTextureUniform::get_editable_properties() const {
|
||||||
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
|
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
|
||||||
props.push_back("texture_type");
|
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;
|
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() {
|
void VisualShaderNodeTextureUniform::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_texture_type", "type"), &VisualShaderNodeTextureUniform::set_texture_type);
|
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);
|
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("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("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, "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_DATA);
|
||||||
BIND_ENUM_CONSTANT(TYPE_COLOR);
|
BIND_ENUM_CONSTANT(TYPE_COLOR);
|
||||||
@@ -4973,6 +5096,20 @@ void VisualShaderNodeTextureUniform::_bind_methods() {
|
|||||||
BIND_ENUM_CONSTANT(COLOR_DEFAULT_WHITE);
|
BIND_ENUM_CONSTANT(COLOR_DEFAULT_WHITE);
|
||||||
BIND_ENUM_CONSTANT(COLOR_DEFAULT_BLACK);
|
BIND_ENUM_CONSTANT(COLOR_DEFAULT_BLACK);
|
||||||
BIND_ENUM_CONSTANT(COLOR_DEFAULT_MAX);
|
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 {
|
String VisualShaderNodeTextureUniform::get_input_port_default_hint(int p_port) const {
|
||||||
|
|||||||
@@ -1953,9 +1953,29 @@ public:
|
|||||||
COLOR_DEFAULT_MAX,
|
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:
|
protected:
|
||||||
TextureType texture_type = TYPE_DATA;
|
TextureType texture_type = TYPE_DATA;
|
||||||
ColorDefault color_default = COLOR_DEFAULT_WHITE;
|
ColorDefault color_default = COLOR_DEFAULT_WHITE;
|
||||||
|
TextureFilter texture_filter = FILTER_DEFAULT;
|
||||||
|
TextureRepeat texture_repeat = REPEAT_DEFAULT;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
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_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 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;
|
virtual bool is_code_generated() const override;
|
||||||
|
|
||||||
Vector<StringName> get_editable_properties() const override;
|
Vector<StringName> get_editable_properties() const override;
|
||||||
@@ -1985,6 +2007,12 @@ public:
|
|||||||
void set_color_default(ColorDefault p_default);
|
void set_color_default(ColorDefault p_default);
|
||||||
ColorDefault get_color_default() const;
|
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_qualifier_supported(Qualifier p_qual) const override;
|
||||||
bool is_convertible_to_constant() const override;
|
bool is_convertible_to_constant() const override;
|
||||||
|
|
||||||
@@ -1993,6 +2021,8 @@ public:
|
|||||||
|
|
||||||
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureType)
|
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureType)
|
||||||
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::ColorDefault)
|
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::ColorDefault)
|
||||||
|
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureFilter)
|
||||||
|
VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::TextureRepeat)
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user