Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Add implicit conversion of bool constants to float, int, and uint

jvron0b7b9a0b46ee
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp
index a636ecbad51..9fa1281cb65 100644
--- a/servers/rendering/shader_language.cpp
+++ b/servers/rendering/shader_language.cpp
@@ -4265,6 +4265,21 @@ bool ShaderLanguage::convert_constant(ConstantNode *p_constant, DataType p_to_ty
p_value->sint = p_constant->values[0].uint;
}
return true;
+ } else if (p_constant->datatype == TYPE_BOOL && p_to_type == TYPE_FLOAT) {
+ if (p_value) {
+ p_value->real = p_constant->values[0].boolean ? 1.0f : 0.0f;
+ }
+ return true;
+ } else if (p_constant->datatype == TYPE_BOOL && p_to_type == TYPE_UINT) {
+ if (p_value) {
+ p_value->uint = p_constant->values[0].boolean ? 1U : 0U;
+ }
+ return true;
+ } else if (p_constant->datatype == TYPE_BOOL && p_to_type == TYPE_INT) {
+ if (p_value) {
+ p_value->sint = p_constant->values[0].boolean ? 1 : 0;
+ }
+ return true;
} else {
return false;
}
@@ -4295,6 +4310,7 @@ bool ShaderLanguage::is_float_type(DataType p_type) {
}
}
}
+
bool ShaderLanguage::is_sampler_type(DataType p_type) {
return p_type > TYPE_MAT4 && p_type < TYPE_STRUCT;
}