Skip to content

Commit 74de05a

Browse files
authored
Merge pull request godotengine#96912 from Chaosus/shader_fix_sky
Fix broken sky shader
2 parents d5d6c73 + 4a16a0d commit 74de05a

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

servers/rendering/shader_compiler.cpp

+24-17
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static String f2sp0(float p_float) {
185185
return num;
186186
}
187187

188-
static String get_constant_text(SL::DataType p_type, const Vector<SL::Scalar> &p_values, bool p_is_op) {
188+
static String get_constant_text(SL::DataType p_type, const Vector<SL::Scalar> &p_values) {
189189
switch (p_type) {
190190
case SL::TYPE_BOOL:
191191
return p_values[0].boolean ? "true" : "false";
@@ -205,7 +205,7 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::Scalar> &p
205205
}
206206

207207
case SL::TYPE_INT:
208-
return itos(p_is_op ? Math::abs(p_values[0].sint) : p_values[0].sint); // To prevent writing unary minus twice in operator expression parsing.
208+
return itos(p_values[0].sint);
209209
case SL::TYPE_IVEC2:
210210
case SL::TYPE_IVEC3:
211211
case SL::TYPE_IVEC4: {
@@ -238,7 +238,7 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::Scalar> &p
238238
return text;
239239
} break;
240240
case SL::TYPE_FLOAT:
241-
return f2sp0(p_is_op ? Math::abs(p_values[0].real) : p_values[0].real); // To prevent writing unary minus twice in operator expression parsing.
241+
return f2sp0(p_values[0].real);
242242
case SL::TYPE_VEC2:
243243
case SL::TYPE_VEC3:
244244
case SL::TYPE_VEC4: {
@@ -446,7 +446,7 @@ static String _get_global_shader_uniform_from_type_and_index(const String &p_buf
446446
}
447447
}
448448

449-
String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope, bool p_is_op) {
449+
String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope) {
450450
String code;
451451

452452
switch (p_node->type) {
@@ -1090,7 +1090,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
10901090
SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
10911091

10921092
if (cnode->array_size == 0) {
1093-
return get_constant_text(cnode->datatype, cnode->values, p_is_op);
1093+
return get_constant_text(cnode->datatype, cnode->values);
10941094
} else {
10951095
if (cnode->get_datatype() == SL::TYPE_STRUCT) {
10961096
code += _mkid(cnode->struct_name);
@@ -1128,18 +1128,25 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
11281128
case SL::OP_ASSIGN_BIT_AND:
11291129
case SL::OP_ASSIGN_BIT_OR:
11301130
case SL::OP_ASSIGN_BIT_XOR:
1131-
code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, true, true, true) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1131+
code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, true) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
11321132
break;
11331133
case SL::OP_BIT_INVERT:
11341134
case SL::OP_NEGATE:
11351135
case SL::OP_NOT:
11361136
case SL::OP_DECREMENT:
1137-
case SL::OP_INCREMENT:
1138-
code = _opstr(onode->op) + _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1139-
break;
1137+
case SL::OP_INCREMENT: {
1138+
const String node_code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
1139+
1140+
if (onode->op == SL::OP_NEGATE && node_code.begins_with("-")) { // To prevent writing unary minus twice.
1141+
code = node_code;
1142+
} else {
1143+
code = _opstr(onode->op) + node_code;
1144+
}
1145+
1146+
} break;
11401147
case SL::OP_POST_DECREMENT:
11411148
case SL::OP_POST_INCREMENT:
1142-
code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true) + _opstr(onode->op);
1149+
code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + _opstr(onode->op);
11431150
break;
11441151
case SL::OP_CALL:
11451152
case SL::OP_STRUCT:
@@ -1235,7 +1242,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
12351242
}
12361243
}
12371244

1238-
String node_code = _dump_node_code(onode->arguments[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1245+
String node_code = _dump_node_code(onode->arguments[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
12391246
if (is_texture_func && i == 1) {
12401247
// If we're doing a texture lookup we need to check our texture argument
12411248
StringName texture_uniform;
@@ -1352,19 +1359,19 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
13521359
}
13531360
} break;
13541361
case SL::OP_INDEX: {
1355-
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1362+
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
13561363
code += "[";
1357-
code += _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1364+
code += _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
13581365
code += "]";
13591366

13601367
} break;
13611368
case SL::OP_SELECT_IF: {
13621369
code += "(";
1363-
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1370+
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
13641371
code += "?";
1365-
code += _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1372+
code += _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
13661373
code += ":";
1367-
code += _dump_node_code(onode->arguments[2], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1374+
code += _dump_node_code(onode->arguments[2], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
13681375
code += ")";
13691376

13701377
} break;
@@ -1376,7 +1383,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
13761383
if (p_use_scope) {
13771384
code += "(";
13781385
}
1379-
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + " " + _opstr(onode->op) + " " + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning, true, true);
1386+
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + " " + _opstr(onode->op) + " " + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
13801387
if (p_use_scope) {
13811388
code += ")";
13821389
}

servers/rendering/shader_compiler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ShaderCompiler {
109109
String _get_sampler_name(ShaderLanguage::TextureFilter p_filter, ShaderLanguage::TextureRepeat p_repeat);
110110

111111
void _dump_function_deps(const ShaderLanguage::ShaderNode *p_node, const StringName &p_for_func, const HashMap<StringName, String> &p_func_code, String &r_to_add, HashSet<StringName> &added);
112-
String _dump_node_code(const ShaderLanguage::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_scope = true, bool p_is_op = false);
112+
String _dump_node_code(const ShaderLanguage::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_scope = true);
113113

114114
const ShaderLanguage::ShaderNode *shader = nullptr;
115115
const ShaderLanguage::FunctionNode *function = nullptr;

0 commit comments

Comments
 (0)