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.
This commit is contained in:
parent
45a14a20de
commit
ddaeaa4b98
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue