From 1e128c80c65fdcacd6e6fc98ffc3a195a2ea373a Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Thu, 22 Jul 2021 08:43:12 +0300 Subject: [PATCH] Backport latest varying fixes to 3.x --- servers/visual/shader_language.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index b1595eeccdb..e0dea5b06c1 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2180,6 +2180,11 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p } StringName var_name = static_cast(p_func->arguments[arg_idx + 1])->name; + if (shader->varyings.has(var_name)) { + _set_error(vformat("Varyings cannot be passed for '%s' parameter!", "out")); + return false; + } + const BlockNode *b = p_block; bool valid = false; while (b) { @@ -2776,8 +2781,8 @@ bool ShaderLanguage::_is_operator_assign(Operator p_op) const { } bool ShaderLanguage::_validate_varying_assign(ShaderNode::Varying &p_varying, String *r_message) { - if (current_function == String("light")) { - *r_message = RTR("Varying may not be assigned in the 'light' function."); + if (current_function != String("vertex") && current_function != String("fragment")) { + *r_message = vformat(RTR("Varying may not be assigned in the '%s' function."), current_function); return false; } switch (p_varying.stage) { @@ -2788,12 +2793,15 @@ bool ShaderLanguage::_validate_varying_assign(ShaderNode::Varying &p_varying, St p_varying.stage = ShaderNode::Varying::STAGE_FRAGMENT; } break; + case ShaderNode::Varying::STAGE_VERTEX_TO_FRAGMENT: + case ShaderNode::Varying::STAGE_VERTEX_TO_LIGHT: case ShaderNode::Varying::STAGE_VERTEX: if (current_function == String("fragment")) { *r_message = RTR("Varyings which assigned in 'vertex' function may not be reassigned in 'fragment' or 'light'."); return false; } break; + case ShaderNode::Varying::STAGE_FRAGMENT_TO_LIGHT: case ShaderNode::Varying::STAGE_FRAGMENT: if (current_function == String("vertex")) { *r_message = RTR("Varyings which assigned in 'fragment' function may not be reassigned in 'vertex' or 'light'."); @@ -3429,6 +3437,10 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } else if (shader->uniforms.has(varname)) { error = true; } else { + if (shader->varyings.has(varname)) { + _set_error(vformat("Varyings cannot be passed for '%s' parameter!", _get_qualifier_str(call_function->arguments[i].qualifier))); + return nullptr; + } if (p_builtin_types.has(varname)) { BuiltInInfo info = p_builtin_types[varname]; if (info.constant) { @@ -6335,14 +6347,6 @@ Error ShaderLanguage::_parse_shader(const Map &p_funct tk = _get_token(); } - for (Map::Element *E = shader->varyings.front(); E; E = E->next()) { - if (E->get().stage == ShaderNode::Varying::STAGE_VERTEX || E->get().stage == ShaderNode::Varying::STAGE_FRAGMENT) { - _set_tkpos(E->get().tkpos); - _set_error(RTR("Varying must only be used in two different stages, which can be 'vertex' 'fragment' and 'light'")); - return ERR_PARSE_ERROR; - } - } - return OK; }