Merge pull request #51572 from Chaosus/vs_fix_transform_instance

Fix printing error about unsupported modifier on `TransformUniform`
This commit is contained in:
Yuri Roubinsky 2021-08-12 21:23:18 +03:00 committed by GitHub
commit b2b33ce4f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 3 deletions

View File

@ -592,6 +592,14 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
} }
if (vsnode->is_use_prop_slots()) { if (vsnode->is_use_prop_slots()) {
String error = vsnode->get_warning(visual_shader->get_mode(), p_type);
if (error != String()) {
Label *error_label = memnew(Label);
error_label->add_theme_color_override("font_color", VisualShaderEditor::get_singleton()->get_theme_color(SNAME("error_color"), SNAME("Editor")));
error_label->set_text(error);
node->add_child(error_label);
}
return; return;
} }
custom_editor = nullptr; custom_editor = nullptr;
@ -2029,6 +2037,8 @@ void VisualShaderEditor::_uniform_line_edit_changed(const String &p_text, int p_
undo_redo->add_undo_method(node.ptr(), "set_uniform_name", node->get_uniform_name()); undo_redo->add_undo_method(node.ptr(), "set_uniform_name", node->get_uniform_name());
undo_redo->add_do_method(graph_plugin.ptr(), "set_uniform_name", type, p_node_id, validated_name); undo_redo->add_do_method(graph_plugin.ptr(), "set_uniform_name", type, p_node_id, validated_name);
undo_redo->add_undo_method(graph_plugin.ptr(), "set_uniform_name", type, p_node_id, node->get_uniform_name()); undo_redo->add_undo_method(graph_plugin.ptr(), "set_uniform_name", type, p_node_id, node->get_uniform_name());
undo_redo->add_do_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
undo_redo->add_undo_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
undo_redo->add_do_method(this, "_update_uniforms", true); undo_redo->add_do_method(this, "_update_uniforms", true);
undo_redo->add_undo_method(this, "_update_uniforms", true); undo_redo->add_undo_method(this, "_update_uniforms", true);

View File

@ -3081,10 +3081,84 @@ String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::T
List<String> keyword_list; List<String> keyword_list;
ShaderLanguage::get_keyword_list(&keyword_list); ShaderLanguage::get_keyword_list(&keyword_list);
if (keyword_list.find(uniform_name)) { if (keyword_list.find(uniform_name)) {
return TTR("Uniform name cannot be equal to a shader keyword. Choose another name."); return TTR("Shader keywords cannot be used as uniform names.\nChoose another name.");
} }
if (!is_qualifier_supported(qualifier)) { if (!is_qualifier_supported(qualifier)) {
return "This uniform type does not support that qualifier."; String qualifier_str;
switch (qualifier) {
case QUAL_NONE:
break;
case QUAL_GLOBAL:
qualifier_str = "global";
break;
case QUAL_INSTANCE:
qualifier_str = "instance";
break;
}
return vformat(TTR("This uniform type does not support the '%s' qualifier."), qualifier_str);
} else if (qualifier == Qualifier::QUAL_GLOBAL) {
RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(uniform_name);
if (gvt == RS::GLOBAL_VAR_TYPE_MAX) {
return vformat(TTR("Global uniform '%s' does not exist.\nCreate it in the Project Settings."), uniform_name);
}
bool incompatible_type = false;
switch (gvt) {
case RS::GLOBAL_VAR_TYPE_FLOAT: {
if (!Object::cast_to<VisualShaderNodeFloatUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_INT: {
if (!Object::cast_to<VisualShaderNodeIntUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_BOOL: {
if (!Object::cast_to<VisualShaderNodeBooleanUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_COLOR: {
if (!Object::cast_to<VisualShaderNodeColorUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_VEC3: {
if (!Object::cast_to<VisualShaderNodeVec3Uniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_TRANSFORM: {
if (!Object::cast_to<VisualShaderNodeTransformUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_SAMPLER2D: {
if (!Object::cast_to<VisualShaderNodeTextureUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_SAMPLER3D: {
if (!Object::cast_to<VisualShaderNodeTexture3DUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_SAMPLER2DARRAY: {
if (!Object::cast_to<VisualShaderNodeTexture2DArrayUniform>(this)) {
incompatible_type = true;
}
} break;
case RS::GLOBAL_VAR_TYPE_SAMPLERCUBE: {
if (!Object::cast_to<VisualShaderNodeCubemapUniform>(this)) {
incompatible_type = true;
}
} break;
default:
break;
}
if (incompatible_type) {
return vformat(TTR("Global uniform '%s' has an incompatible type for this kind of node.\nChange it in the Project Settings."), uniform_name);
}
} }
return String(); return String();

View File

@ -4575,7 +4575,10 @@ bool VisualShaderNodeTransformUniform::is_use_prop_slots() const {
} }
bool VisualShaderNodeTransformUniform::is_qualifier_supported(Qualifier p_qual) const { bool VisualShaderNodeTransformUniform::is_qualifier_supported(Qualifier p_qual) const {
return true; // all qualifiers are supported if (p_qual == Qualifier::QUAL_INSTANCE) {
return false;
}
return true;
} }
bool VisualShaderNodeTransformUniform::is_convertible_to_constant() const { bool VisualShaderNodeTransformUniform::is_convertible_to_constant() const {