[Bf-blender-cvs] [ddaeaa4b981] master: Geometry Nodes: Add a template utility to mix two attribute values
Hans Goudey
noreply at git.blender.org
Fri Apr 30 04:52:47 CEST 2021
Commit: ddaeaa4b981d38393fcbb6ca6cc27e81f55da900
Author: Hans Goudey
Date: Thu Apr 29 21:52:34 2021 -0500
Branches: master
https://developer.blender.org/rBddaeaa4b981d38393fcbb6ca6cc27e81f55da900
Geometry Nodes: Add a template utility to mix two attribute values
This is just linear interpolation, but it's nice to have an equivalent
to `mix3` for only two values. It will be used for interpolation of
values between bezier spline control points.
===================================================================
M source/blender/blenkernel/BKE_attribute_math.hh
===================================================================
diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh
index 65ac5b5bfa8..fc7498951f9 100644
--- a/source/blender/blenkernel/BKE_attribute_math.hh
+++ b/source/blender/blenkernel/BKE_attribute_math.hh
@@ -130,6 +130,48 @@ inline Color4f mix3(const float3 &weights, const Color4f &v0, const Color4f &v1,
/** \} */
+/* -------------------------------------------------------------------- */
+/** \name Mix two values of the same type.
+ *
+ * This is just basic linear interpolation.
+ * \{ */
+
+template<typename T> T mix2(const float factor, const T &a, const T &b);
+
+template<> inline bool mix2(const float factor, const bool &a, const bool &b)
+{
+ return ((1.0f - factor) * a + factor * b) >= 0.5f;
+}
+
+template<> inline int mix2(const float factor, const int &a, const int &b)
+{
+ return static_cast<int>((1.0f - factor) * a + factor * b);
+}
+
+template<> inline float mix2(const float factor, const float &a, const float &b)
+{
+ return (1.0f - factor) * a + factor * b;
+}
+
+template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b)
+{
+ return float2::interpolate(a, b, factor);
+}
+
+template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b)
+{
+ return float3::interpolate(a, b, factor);
+}
+
+template<> inline Color4f mix2(const float factor, const Color4f &a, const Color4f &b)
+{
+ Color4f result;
+ interp_v4_v4v4(result, a, b, factor);
+ return result;
+}
+
+/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Mix a dynamic amount of values with weights for many elements.
*
More information about the Bf-blender-cvs
mailing list