diff options
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | servers/visual/shader_language.cpp | 128 | ||||
-rw-r--r-- | servers/visual/shader_language.h | 4 |
3 files changed, 131 insertions, 3 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index ebd7b4edf6..7d59b8e20d 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2179,7 +2179,7 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da _add_custom_node(arr[i]); j++; } - } else if (ClassDB::get_parent_class(type) == "Texture") { + } else if (ClassDB::get_parent_class(type) == "Texture2D") { saved_node_pos = p_point + Vector2(0, j * 210 * EDSCALE); saved_node_pos_dirty = true; _add_texture_node(arr[i]); diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index a5b028b15b..76348373c9 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2933,6 +2933,13 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI } else if (p_node->type == Node::TYPE_MEMBER) { MemberNode *member = static_cast<MemberNode *>(p_node); + + if (member->has_swizzling_duplicates) { + if (r_message) + *r_message = RTR("Swizzling assignment contains duplicates."); + return false; + } + return _validate_assign(member->owner, p_builtin_types, r_message); } else if (p_node->type == Node::TYPE_VARIABLE) { @@ -3710,9 +3717,17 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons String ident = identifier; bool ok = true; + bool repeated = false; DataType member_type = TYPE_VOID; StringName member_struct_name = ""; int array_size = 0; + + Set<char> position_symbols; + Set<char> color_symbols; + Set<char> texture_symbols; + + bool mix_error = false; + switch (dt) { case TYPE_STRUCT: { ok = false; @@ -3758,8 +3773,39 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons switch (c[i]) { case 'r': case 'g': + if (position_symbols.size() > 0 || texture_symbols.size() > 0) { + mix_error = true; + break; + } + if (!color_symbols.has(c[i])) { + color_symbols.insert(c[i]); + } else { + repeated = true; + } + break; case 'x': case 'y': + if (color_symbols.size() > 0 || texture_symbols.size() > 0) { + mix_error = true; + break; + } + if (!position_symbols.has(c[i])) { + position_symbols.insert(c[i]); + } else { + repeated = true; + } + break; + case 's': + case 't': + if (color_symbols.size() > 0 || position_symbols.size() > 0) { + mix_error = true; + break; + } + if (!texture_symbols.has(c[i])) { + texture_symbols.insert(c[i]); + } else { + repeated = true; + } break; default: ok = false; @@ -3794,9 +3840,41 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons case 'r': case 'g': case 'b': + if (position_symbols.size() > 0 || texture_symbols.size() > 0) { + mix_error = true; + break; + } + if (!color_symbols.has(c[i])) { + color_symbols.insert(c[i]); + } else { + repeated = true; + } + break; case 'x': case 'y': case 'z': + if (color_symbols.size() > 0 || texture_symbols.size() > 0) { + mix_error = true; + break; + } + if (!position_symbols.has(c[i])) { + position_symbols.insert(c[i]); + } else { + repeated = true; + } + break; + case 's': + case 't': + case 'p': + if (color_symbols.size() > 0 || position_symbols.size() > 0) { + mix_error = true; + break; + } + if (!texture_symbols.has(c[i])) { + texture_symbols.insert(c[i]); + } else { + repeated = true; + } break; default: ok = false; @@ -3832,10 +3910,43 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons case 'g': case 'b': case 'a': + if (position_symbols.size() > 0 || texture_symbols.size() > 0) { + mix_error = true; + break; + } + if (!color_symbols.has(c[i])) { + color_symbols.insert(c[i]); + } else { + repeated = true; + } + break; case 'x': case 'y': case 'z': case 'w': + if (color_symbols.size() > 0 || texture_symbols.size() > 0) { + mix_error = true; + break; + } + if (!position_symbols.has(c[i])) { + position_symbols.insert(c[i]); + } else { + repeated = true; + } + break; + case 's': + case 't': + case 'p': + case 'q': + if (color_symbols.size() > 0 || position_symbols.size() > 0) { + mix_error = true; + break; + } + if (!texture_symbols.has(c[i])) { + texture_symbols.insert(c[i]); + } else { + repeated = true; + } break; default: ok = false; @@ -3850,8 +3961,12 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } } - if (!ok) { + if (mix_error) { + _set_error("Cannot combine symbols from different sets in expression ." + ident); + return NULL; + } + if (!ok) { _set_error("Invalid member for " + (dt == TYPE_STRUCT ? st : get_datatype_name(dt)) + " expression: ." + ident); return NULL; } @@ -3865,6 +3980,8 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons mn->array_size = array_size; mn->name = ident; mn->owner = expr; + mn->has_swizzling_duplicates = repeated; + if (array_size > 0) { tk = _get_token(); @@ -6156,6 +6273,13 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } + if (qualifier == ARGUMENT_QUALIFIER_OUT || qualifier == ARGUMENT_QUALIFIER_INOUT) { + if (is_sampler_type(get_token_datatype(tk.type))) { + _set_error("Opaque types cannot be output parameters."); + return ERR_PARSE_ERROR; + } + } + if (is_struct) { ptype = TYPE_STRUCT; } else { @@ -6684,6 +6808,7 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct const char colv[4] = { 'r', 'g', 'b', 'a' }; const char coordv[4] = { 'x', 'y', 'z', 'w' }; + const char coordt[4] = { 's', 't', 'p', 'q' }; int limit = 0; @@ -6721,6 +6846,7 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct for (int i = 0; i < limit; i++) { r_options->push_back(ScriptCodeCompletionOption(String::chr(colv[i]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT)); r_options->push_back(ScriptCodeCompletionOption(String::chr(coordv[i]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT)); + r_options->push_back(ScriptCodeCompletionOption(String::chr(coordt[i]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT)); } } break; diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index e56fb35a8b..5a69a84650 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -538,6 +538,7 @@ public: StringName name; Node *owner; Node *index_expression; + bool has_swizzling_duplicates; virtual DataType get_datatype() const { return datatype; } virtual String get_datatype_name() const { return String(struct_name); } @@ -549,7 +550,8 @@ public: datatype(TYPE_VOID), array_size(0), owner(NULL), - index_expression(NULL) {} + index_expression(NULL), + has_swizzling_duplicates(false) {} }; struct StructNode : public Node { |