diff options
author | Charlie Jolly <charlie> | 2021-03-26 19:12:32 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2021-03-26 19:29:48 +0300 |
commit | 70061c69b79721a6b69475dd296b10a5c9658f1c (patch) | |
tree | 904e12adb325c3b053abeeab8e35beb462479f72 /source/blender/nodes | |
parent | 1e855149b2cec794059f8119cd22052ad701ef64 (diff) |
Geometry Nodes: Implicit conversion change for float/int/color to bool
Change `float to boolean` and `int32 to boolean` to return false for zero and negative values.
This aligns with how artists would expect these values to work. This is in contrast to what a coder would expect. It was determined on blender.chat that this was a better default. This means that a negative float value would give a boolean false.
Change `Color4f to boolean` to return false for zero and negative grayscale values.
Likewise, for color to boolean, to account for negative value colors, the grayscale value would be used for determining if a colour was false or not.
See {T86454}
Reviewed By: JacquesLucke
Differential Revision: https://developer.blender.org/D10685
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/intern/node_tree_multi_function.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/source/blender/nodes/intern/node_tree_multi_function.cc b/source/blender/nodes/intern/node_tree_multi_function.cc index b973350becd..c77a6b42f97 100644 --- a/source/blender/nodes/intern/node_tree_multi_function.cc +++ b/source/blender/nodes/intern/node_tree_multi_function.cc @@ -164,7 +164,8 @@ static DataTypeConversions create_implicit_conversions() add_implicit_conversion<float, float2>(conversions); add_implicit_conversion<float, float3>(conversions); add_implicit_conversion<float, int32_t>(conversions); - add_implicit_conversion<float, bool>(conversions); + add_implicit_conversion<float, bool>( + conversions, "float to boolean", [](float a) { return a > 0.0f; }); add_implicit_conversion<float, Color4f>( conversions, "float to Color4f", [](float a) { return Color4f(a, a, a, 1.0f); }); @@ -189,7 +190,8 @@ static DataTypeConversions create_implicit_conversions() add_implicit_conversion<float3, Color4f>( conversions, "float3 to Color4f", [](float3 a) { return Color4f(a.x, a.y, a.z, 1.0f); }); - add_implicit_conversion<int32_t, bool>(conversions); + add_implicit_conversion<int32_t, bool>( + conversions, "int32 to boolean", [](int32_t a) { return a > 0; }); add_implicit_conversion<int32_t, float>(conversions); add_implicit_conversion<int32_t, float2>( conversions, "int32 to float2", [](int32_t a) { return float2((float)a); }); @@ -209,9 +211,8 @@ static DataTypeConversions create_implicit_conversions() return (a) ? Color4f(1.0f, 1.0f, 1.0f, 1.0f) : Color4f(0.0f, 0.0f, 0.0f, 1.0f); }); - add_implicit_conversion<Color4f, bool>(conversions, "Color4f to boolean", [](Color4f a) { - return a.r != 0.0f && a.g != 0.0f && a.b != 0.0f; - }); + add_implicit_conversion<Color4f, bool>( + conversions, "Color4f to boolean", [](Color4f a) { return rgb_to_grayscale(a) > 0.0f; }); add_implicit_conversion<Color4f, float>( conversions, "Color4f to float", [](Color4f a) { return rgb_to_grayscale(a); }); add_implicit_conversion<Color4f, float2>( |