You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-14 13:41:12 +00:00
Add texture filtering properties to VisualShaderNodeTextureUniform
This commit is contained in:
@@ -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";
|
||||
} 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_NORMAL_MAP:
|
||||
code += " : hint_normal;\n";
|
||||
break;
|
||||
case TYPE_ANISOTROPY:
|
||||
code += " : hint_anisotropy;\n";
|
||||
break;
|
||||
default:
|
||||
code += ";\n";
|
||||
break;
|
||||
// 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 += ", ";
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user