[Bf-blender-cvs] [104887800c0] master: Geometry Nodes: Add Voronoi Texture

Charlie Jolly noreply at git.blender.org
Fri Oct 15 16:30:05 CEST 2021


Commit: 104887800c0f221fbcffa84bb360dd9ff001d7f1
Author: Charlie Jolly
Date:   Fri Oct 15 15:27:16 2021 +0100
Branches: master
https://developer.blender.org/rB104887800c0f221fbcffa84bb360dd9ff001d7f1

Geometry Nodes: Add Voronoi Texture

Port shader Voronoi to GN

Reviewed By: JacquesLucke

Differential Revision: https://developer.blender.org/D12725

===================================================================

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenlib/BLI_float2.hh
M	source/blender/blenlib/BLI_float3.hh
M	source/blender/blenlib/BLI_float4.hh
M	source/blender/blenlib/BLI_noise.hh
M	source/blender/blenlib/intern/math_base_inline.c
M	source/blender/blenlib/intern/math_vector_inline.c
M	source/blender/blenlib/intern/noise.cc
M	source/blender/modifiers/intern/MOD_nodes_evaluator.cc
M	source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc

===================================================================

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 04e9fba02f2..26d586ac859 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -720,6 +720,7 @@ geometry_node_categories = [
     GeometryNodeCategory("GEO_TEXTURE", "Texture", items=[
         NodeItem("ShaderNodeTexGradient"),
         NodeItem("ShaderNodeTexNoise"),
+        NodeItem("ShaderNodeTexVoronoi"),
         NodeItem("ShaderNodeTexWhiteNoise"),
     ]),
     GeometryNodeCategory("GEO_UTILITIES", "Utilities", items=[
diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh
index cf6e00ba938..bb4229db86e 100644
--- a/source/blender/blenlib/BLI_float2.hh
+++ b/source/blender/blenlib/BLI_float2.hh
@@ -115,6 +115,11 @@ struct float2 {
     return {a.x - b.x, a.y - b.y};
   }
 
+  friend float2 operator-(const float2 &a, const float &b)
+  {
+    return {a.x - b, a.y - b};
+  }
+
   friend float2 operator*(const float2 &a, float b)
   {
     return {a.x * b, a.y * b};
@@ -137,6 +142,26 @@ struct float2 {
     return stream;
   }
 
+  static float2 safe_divide(const float2 &a, const float b)
+  {
+    return (b != 0.0f) ? a / b : float2(0.0f);
+  }
+
+  static float2 floor(const float2 &a)
+  {
+    return float2(floorf(a.x), floorf(a.y));
+  }
+
+  /**
+   * Returns a normalized vector. The original vector is not changed.
+   */
+  float2 normalized() const
+  {
+    float2 result;
+    normalize_v2_v2(result, *this);
+    return result;
+  }
+
   static float dot(const float2 &a, const float2 &b)
   {
     return a.x * b.x + a.y * b.y;
diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh
index 04aae375889..8263ef72584 100644
--- a/source/blender/blenlib/BLI_float3.hh
+++ b/source/blender/blenlib/BLI_float3.hh
@@ -80,6 +80,11 @@ struct float3 {
     return {-a.x, -a.y, -a.z};
   }
 
+  friend float3 operator-(const float3 &a, const float &b)
+  {
+    return {a.x - b, a.y - b, a.z - b};
+  }
+
   float3 &operator-=(const float3 &b)
   {
     this->x -= b.x;
@@ -218,6 +223,16 @@ struct float3 {
     return result;
   }
 
+  static float3 safe_divide(const float3 &a, const float b)
+  {
+    return (b != 0.0f) ? a / b : float3(0.0f);
+  }
+
+  static float3 floor(const float3 &a)
+  {
+    return float3(floorf(a.x), floorf(a.y), floorf(a.z));
+  }
+
   void invert()
   {
     x = -x;
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
diff --git a/source/blender/blenlib/BLI_noise.hh b/source/blender/blenlib/BLI_noise.hh
index 12e7aa57ab0..93980e3569e 100644
--- a/source/blender/blenlib/BLI_noise.hh
+++ b/source/blender/blenlib/BLI_noise.hh
@@ -112,4 +112,98 @@ float3 perlin_float3_fractal_distorted(float4 position,
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Voronoi Noise
+ * \{ */
+
+void voronoi_f1(
+    const float w, const float randomness, float *r_distance, float3 *r_color, float *r_w);
+void voronoi_smooth_f1(const float w,
+                       const float smoothness,
+                       const float randomness,
+                       float *r_distance,
+                       float3 *r_color,
+                       float *r_w);
+void voronoi_f2(
+    const float w, const float randomness, float *r_distance, float3 *r_color, float *r_w);
+void voronoi_distance_to_edge(const float w, const float randomness, float *r_distance);
+void voronoi_n_sphere_radius(const float w, const float randomness, float *r_radius);
+
+void voronoi_f1(const float2 coord,
+                const float exponent,
+                const float randomness,
+                const int metric,
+                float *r_distance,
+                float3 *r_color,
+                float2 *r_position);
+void voronoi_smooth_f1(const float2 coord,
+                       const float smoothness,
+                       const float exponent,
+                       const float randomness,
+                       const int metric,
+                       float *r_distance,
+                       float3 *r_color,
+                       float2 *r_position);
+void voronoi_f2(const float2 coord,
+                const float exponent,
+                const float randomness,
+                const int metric,
+                float *r_distance,
+                float3 *r_color,
+                float2 *r_position);
+void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance);
+void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *r_radius);
+
+void voronoi_f1(const float3 coord,
+                const float exponent,
+                const float randomness,
+                const int metric,
+                float *r_distance,
+                float3 *r_color,
+                float3 *r_position);
+void voronoi_smooth_f1(const float3 coord,
+                       const float smoothness,
+                       const float exponent,
+                       const float randomness,
+                       const int metric,
+                       float *r_distance,
+                       float3 *r_color,
+                       float3 *r_position);
+void voronoi_f2(const float3 coord,
+                const float exponent,
+                const float randomness,
+                const int metric,
+                float *r_distance,
+                float3 *r_color,
+                float3 *r_position);
+void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance);
+void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *r_radius);
+
+void voronoi_f1(const float4 coord,
+                const float exponent,
+                const float randomness,
+                const int metric,
+                float *r_distance,
+                float3 *r_color,
+                float4 *r_position);
+void voronoi_smooth_f1(const float4 coord,
+                       const float smoothness,
+                       const float exponent,
+                       const float randomness,
+                       const int metric,
+                       float *r_distance,
+                       float3 *r_color,
+                       float4 *r_position);
+void voronoi_f2(const float4 coord,
+                const float exponent,
+                const float randomness,
+                const int metric,
+                float *r_distance,
+                float3 *r_color,
+                float4 *r_position);
+void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance);
+void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *r_radius);
+
+/** \} */
+
 }  // namespace blender::noise
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 49f9faf1704..f609d5f8e8b 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -511,6 +511,22 @@ MINLINE float smoothminf(float a, float b, float c)
   }
 }
 
+MINLINE float smoothstep(float edge0, float edge1, float x)
+{
+  float result;
+  if (x < edge0) {
+    result = 0.0f;
+  }
+  else if (x >= edge1) {
+    result = 1.0f;
+  }
+  else {
+    float t = (x - edge0) / (edge1 - edge0);
+    result = (3.0f - 2.0f * t) * (t * t);
+  }
+  return result;
+}
+
 MINLINE double min_dd(double a, double b)
 {
   return (a < b) ? a : b;
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 8be066bb0e9..bb32b511005 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -1145,6 +1145,19 @@ MINLINE float len_v3v3(const float a[3], const float b[3])
   return len_v3(d);
 }
 
+MINLINE float len_v4(const float a[4])
+{
+  return sqrtf(dot_v4v4(a, a));
+}
+
+MINLINE float len_v4v4(const float a[4], const float b[4])
+{
+  float d[4];
+
+  sub_v4_v4v4(d, b, a);
+  return len_v4(d);
+}
+
 /**
  * \note any vectors containing `nan` will be zeroed out.
  */
diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc
index ce2e9594059..a6c3377b71f 100644
--- a/source/blender/blenlib/intern/noise.cc
+++ b/source/blender/blenlib/intern/noise.cc
@@ -52,6 +52,7 @@
 #includ

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list