diff options
author | Charlie Jolly <charlie> | 2021-10-15 17:27:16 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2021-10-15 17:28:20 +0300 |
commit | 104887800c0f221fbcffa84bb360dd9ff001d7f1 (patch) | |
tree | 743a308c6eda1918e4e97df0d8ba32b7046bedf7 /source/blender/blenlib/BLI_float4.hh | |
parent | 6e4ab5b761b03b52177985ecbeb2c2f576159c74 (diff) |
Geometry Nodes: Add Voronoi Texture
Port shader Voronoi to GN
Reviewed By: JacquesLucke
Differential Revision: https://developer.blender.org/D12725
Diffstat (limited to 'source/blender/blenlib/BLI_float4.hh')
-rw-r--r-- | source/blender/blenlib/BLI_float4.hh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_float4.hh b/source/blender/blenlib/BLI_float4.hh index b1feee3121b..5b487f6d029 100644 --- a/source/blender/blenlib/BLI_float4.hh +++ b/source/blender/blenlib/BLI_float4.hh @@ -44,6 +44,11 @@ struct float4 { return &x; } + friend float4 operator+(const float4 &a, const float &b) + { + return {a.x + b, a.y + b, a.z + b, a.w + b}; + } + operator const float *() const { return &x; @@ -58,11 +63,27 @@ struct float4 { return *this; } + friend float4 operator-(const float4 &a, const float4 &b) + { + return {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; + } + + friend float4 operator-(const float4 &a, const float &b) + { + return {a.x - b, a.y - b, a.z - b, a.w - b}; + } + friend float4 operator+(const float4 &a, const float4 &b) { return {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; } + friend float4 operator/(const float4 &a, float f) + { + BLI_assert(f != 0.0f); + return a * (1.0f / f); + } + float4 &operator*=(float factor) { x *= factor; @@ -81,6 +102,37 @@ struct float4 { { return b * a; } + + float length() const + { + return len_v4(*this); + } + + static float distance(const float4 &a, const float4 &b) + { + return (a - b).length(); + } + + static float4 safe_divide(const float4 &a, const float b) + { + return (b != 0.0f) ? a / b : float4(0.0f); + } + + static float4 interpolate(const float4 &a, const float4 &b, float t) + { + return a * (1 - t) + b * t; + } + + static float4 floor(const float4 &a) + { + return float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); + } + + static float4 normalize(const float4 &a) + { + const float t = len_v4(a); + return (t != 0.0f) ? a / t : float4(0.0f); + } }; } // namespace blender |