Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-05-18 18:00:19 +0300
committerJacques Lucke <jacques@blender.org>2022-05-18 18:00:38 +0300
commit2e70af5cd527e2c1f40e6f3af22adc3337714744 (patch)
treec5e55df22f2e53d044e541c8d5b1392de30786f5 /source/blender/blenkernel/BKE_attribute_math.hh
parent342e12d6d92198bba8355562600a2f97bb45fed5 (diff)
Fix T97761: incorrect mixing of integers
Sometimes integers are mixed using float weights. In those cases the mixed result has to be converted from into float again. Previously, this was done using a simple cast, which was unexpected because e.g. 14.999 would be cast to 14 instead of 15. Now, the values are rounded properly. This can affect existing files unfortunately without a good option for versioning. Gladly, very few files seem to depend on the details of the old behavior. Differential Revision: https://developer.blender.org/D14892
Diffstat (limited to 'source/blender/blenkernel/BKE_attribute_math.hh')
-rw-r--r--source/blender/blenkernel/BKE_attribute_math.hh12
1 files changed, 6 insertions, 6 deletions
diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh
index 4482e13e1cf..3d194ba77dc 100644
--- a/source/blender/blenkernel/BKE_attribute_math.hh
+++ b/source/blender/blenkernel/BKE_attribute_math.hh
@@ -56,7 +56,7 @@ template<typename T> T mix3(const float3 &weights, const T &v0, const T &v1, con
template<>
inline int8_t mix3(const float3 &weights, const int8_t &v0, const int8_t &v1, const int8_t &v2)
{
- return static_cast<int8_t>(weights.x * v0 + weights.y * v1 + weights.z * v2);
+ return static_cast<int8_t>(std::round(weights.x * v0 + weights.y * v1 + weights.z * v2));
}
template<> inline bool mix3(const float3 &weights, const bool &v0, const bool &v1, const bool &v2)
@@ -66,7 +66,7 @@ template<> inline bool mix3(const float3 &weights, const bool &v0, const bool &v
template<> inline int mix3(const float3 &weights, const int &v0, const int &v1, const int &v2)
{
- return static_cast<int>(weights.x * v0 + weights.y * v1 + weights.z * v2);
+ return static_cast<int>(std::round(weights.x * v0 + weights.y * v1 + weights.z * v2));
}
template<>
@@ -131,12 +131,12 @@ template<> inline bool mix2(const float factor, const bool &a, const bool &b)
template<> inline int8_t mix2(const float factor, const int8_t &a, const int8_t &b)
{
- return static_cast<int8_t>((1.0f - factor) * a + factor * b);
+ return static_cast<int8_t>(std::round((1.0f - factor) * a + factor * b));
}
template<> inline int mix2(const float factor, const int &a, const int &b)
{
- return static_cast<int>((1.0f - factor) * a + factor * b);
+ return static_cast<int>(std::round((1.0f - factor) * a + factor * b));
}
template<> inline float mix2(const float factor, const float &a, const float &b)
@@ -356,7 +356,7 @@ template<> struct DefaultMixerStruct<ColorGeometry4b> {
template<> struct DefaultMixerStruct<int> {
static int double_to_int(const double &value)
{
- return static_cast<int>(value);
+ return static_cast<int>(std::round(value));
}
/* Store interpolated ints in a double temporarily, so that weights are handled correctly. It
* uses double instead of float so that it is accurate for all 32 bit integers. */
@@ -375,7 +375,7 @@ template<> struct DefaultMixerStruct<bool> {
template<> struct DefaultMixerStruct<int8_t> {
static int8_t float_to_int8_t(const float &value)
{
- return static_cast<int8_t>(value);
+ return static_cast<int8_t>(std::round(value));
}
/* Store interpolated 8 bit integers in a float temporarily to increase accuracy. */
using type = SimpleMixerWithAccumulationType<int8_t, float, float_to_int8_t>;