summaryrefslogtreecommitdiffstats
path: root/servers/rendering/shader_language.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/rendering/shader_language.cpp')
-rw-r--r--servers/rendering/shader_language.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp
index fef1a205d6..99b3f54379 100644
--- a/servers/rendering/shader_language.cpp
+++ b/servers/rendering/shader_language.cpp
@@ -5029,6 +5029,10 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
Vector<Expression> expression;
//Vector<TokenType> operators;
+#ifdef DEBUG_ENABLED
+ bool check_position_write = check_warnings && HAS_WARNING(ShaderWarning::MAGIC_POSITION_WRITE_FLAG);
+ check_position_write = check_position_write && String(shader_type_identifier) == "spatial" && current_function == "vertex";
+#endif
while (true) {
Node *expr = nullptr;
@@ -5589,6 +5593,24 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
_set_error(vformat(RTR("Can't use function as identifier: '%s'."), String(identifier)));
return nullptr;
}
+#ifdef DEBUG_ENABLED
+ if (check_position_write && ident_type == IDENTIFIER_BUILTIN_VAR) {
+ if (String(identifier) == "POSITION") {
+ // Check if the user wrote "POSITION = vec4(VERTEX," and warn if they did.
+ TkPos prev_pos = _get_tkpos();
+ if (_get_token().type == TK_OP_ASSIGN &&
+ _get_token().type == TK_TYPE_VEC4 &&
+ _get_token().type == TK_PARENTHESIS_OPEN &&
+ _get_token().text == "VERTEX" &&
+ _get_token().type == TK_COMMA) {
+ _add_line_warning(ShaderWarning::MAGIC_POSITION_WRITE);
+ }
+
+ // Reset the position so compiling can continue as normal.
+ _set_tkpos(prev_pos);
+ }
+ }
+#endif
if (is_const) {
last_type = IDENTIFIER_CONSTANT;
} else {
@@ -8361,7 +8383,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
}
}
#endif // DEBUG_ENABLED
- if (String(shader_type_identifier) != "spatial") {
+ if (shader_type_identifier != StringName() && String(shader_type_identifier) != "spatial") {
_set_error(vformat(RTR("Uniform instances are not yet implemented for '%s' shaders."), shader_type_identifier));
return ERR_PARSE_ERROR;
}
@@ -8848,7 +8870,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
_set_error(RTR("'hint_normal_roughness_texture' is only available when using the Forward+ backend."));
return ERR_PARSE_ERROR;
}
- if (String(shader_type_identifier) != "spatial") {
+ if (shader_type_identifier != StringName() && String(shader_type_identifier) != "spatial") {
_set_error(vformat(RTR("'hint_normal_roughness_texture' is not supported in '%s' shaders."), shader_type_identifier));
return ERR_PARSE_ERROR;
}
@@ -8857,7 +8879,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
new_hint = ShaderNode::Uniform::HINT_DEPTH_TEXTURE;
--texture_uniforms;
--texture_binding;
- if (String(shader_type_identifier) != "spatial") {
+ if (shader_type_identifier != StringName() && String(shader_type_identifier) != "spatial") {
_set_error(vformat(RTR("'hint_depth_texture' is not supported in '%s' shaders."), shader_type_identifier));
return ERR_PARSE_ERROR;
}