[Bf-blender-cvs] [3b417492454] temp-attribute-processor: initial support for voronoi node

Jacques Lucke noreply at git.blender.org
Wed Jun 23 08:35:08 CEST 2021


Commit: 3b417492454be401c4144ae89cca31bccc03adae
Author: Jacques Lucke
Date:   Wed Jun 23 08:34:54 2021 +0200
Branches: temp-attribute-processor
https://developer.blender.org/rB3b417492454be401c4144ae89cca31bccc03adae

initial support for voronoi node

Only 3D in F1 mode with euclidean distance is support right now.

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
M	source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
R060	source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c	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 4208a1d2237..81c0aec5da6 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -629,6 +629,7 @@ attribute_node_categories = [
     ]),
     AttributeNodeCategory("ATTR_TEXTURE", "Texture", items=[
         NodeItem("ShaderNodeTexNoise"),
+        NodeItem("ShaderNodeTexVoronoi"),
     ]),
     AttributeNodeCategory("ATTR_UTILITIES", "Utilities", items=[
         NodeItem("ShaderNodeMapRange"),
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 7ce462d8a7a..7a7764c072c 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -284,7 +284,7 @@ set(SRC
   shader/nodes/node_shader_tex_noise.cc
   shader/nodes/node_shader_tex_pointdensity.c
   shader/nodes/node_shader_tex_sky.c
-  shader/nodes/node_shader_tex_voronoi.c
+  shader/nodes/node_shader_tex_voronoi.cc
   shader/nodes/node_shader_tex_wave.c
   shader/nodes/node_shader_tex_white_noise.c
   shader/nodes/node_shader_uvAlongStroke.c
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
index b45a4f146f2..f3f5763b315 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
@@ -631,7 +631,6 @@ static void process_attributes(GeoNodeExecParams &geo_params, GeometrySet &geome
   fn::MFNetwork network;
   ResourceScope scope;
   MFNetworkTreeMap network_map = insert_node_tree_into_mf_network(network, tree, scope);
-  std::cout << network.to_dot() << "\n";
 
   Vector<const fn::MFOutputSocket *> fn_input_sockets;
   Vector<const fn::MFInputSocket *> fn_output_sockets;
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
index 70e64e1c21c..4457909c8c0 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
@@ -141,6 +141,11 @@ class NoiseTextureFunction : public blender::fn::MultiFunction {
 static void sh_node_tex_noise_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
 {
   /* TODO: Not only support 3D. */
+  NodeTexNoise *tex = builder.dnode()->storage<NodeTexNoise>();
+  if (tex->dimensions != 3) {
+    builder.set_not_implemented();
+    return;
+  }
   static NoiseTextureFunction fn;
   builder.set_matching_fn(fn);
 }
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
similarity index 60%
rename from source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
rename to source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
index 64dc44fc67d..3ec683c7e67 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
@@ -19,6 +19,9 @@
 
 #include "../node_shader_util.h"
 
+#include "BLI_hash.h"
+#include "BLI_noise.h"
+
 /* **************** VORONOI ******************** */
 
 static bNodeSocketTemplate sh_node_tex_voronoi_in[] = {
@@ -69,7 +72,7 @@ static bNodeSocketTemplate sh_node_tex_voronoi_out[] = {
 
 static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
 {
-  NodeTexVoronoi *tex = MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi");
+  NodeTexVoronoi *tex = (NodeTexVoronoi *)MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi");
   BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
   BKE_texture_colormapping_default(&tex->base.color_mapping);
   tex->dimensions = 3;
@@ -79,6 +82,49 @@ static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
   node->storage = tex;
 }
 
+static const char *node_shader_gpu_name_tex_voronoi(NodeTexVoronoi *tex)
+{
+
+  static const char *names[][5] = {
+      {
+          "",
+          "node_tex_voronoi_f1_1d",
+          "node_tex_voronoi_f1_2d",
+          "node_tex_voronoi_f1_3d",
+          "node_tex_voronoi_f1_4d",
+      },
+      {
+          "",
+          "node_tex_voronoi_f2_1d",
+          "node_tex_voronoi_f2_2d",
+          "node_tex_voronoi_f2_3d",
+          "node_tex_voronoi_f2_4d",
+      },
+      {
+          "",
+          "node_tex_voronoi_smooth_f1_1d",
+          "node_tex_voronoi_smooth_f1_2d",
+          "node_tex_voronoi_smooth_f1_3d",
+          "node_tex_voronoi_smooth_f1_4d",
+      },
+      {
+          "",
+          "node_tex_voronoi_distance_to_edge_1d",
+          "node_tex_voronoi_distance_to_edge_2d",
+          "node_tex_voronoi_distance_to_edge_3d",
+          "node_tex_voronoi_distance_to_edge_4d",
+      },
+      {
+          "",
+          "node_tex_voronoi_n_sphere_radius_1d",
+          "node_tex_voronoi_n_sphere_radius_2d",
+          "node_tex_voronoi_n_sphere_radius_3d",
+          "node_tex_voronoi_n_sphere_radius_4d",
+      },
+  };
+  return names[tex->feature][tex->dimensions];
+}
+
 static int node_shader_gpu_tex_voronoi(GPUMaterial *mat,
                                        bNode *node,
                                        bNodeExecData *UNUSED(execdata),
@@ -88,49 +134,6 @@ static int node_shader_gpu_tex_voronoi(GPUMaterial *mat,
   node_shader_gpu_default_tex_coord(mat, node, &in[0].link);
   node_shader_gpu_tex_mapping(mat, node, in, out);
 
-  static const char *names[][5] = {
-      [SHD_VORONOI_F1] =
-          {
-              "",
-              "node_tex_voronoi_f1_1d",
-              "node_tex_voronoi_f1_2d",
-              "node_tex_voronoi_f1_3d",
-              "node_tex_voronoi_f1_4d",
-          },
-      [SHD_VORONOI_F2] =
-          {
-              "",
-              "node_tex_voronoi_f2_1d",
-              "node_tex_voronoi_f2_2d",
-              "node_tex_voronoi_f2_3d",
-              "node_tex_voronoi_f2_4d",
-          },
-      [SHD_VORONOI_SMOOTH_F1] =
-          {
-              "",
-              "node_tex_voronoi_smooth_f1_1d",
-              "node_tex_voronoi_smooth_f1_2d",
-              "node_tex_voronoi_smooth_f1_3d",
-              "node_tex_voronoi_smooth_f1_4d",
-          },
-      [SHD_VORONOI_DISTANCE_TO_EDGE] =
-          {
-              "",
-              "node_tex_voronoi_distance_to_edge_1d",
-              "node_tex_voronoi_distance_to_edge_2d",
-              "node_tex_voronoi_distance_to_edge_3d",
-              "node_tex_voronoi_distance_to_edge_4d",
-          },
-      [SHD_VORONOI_N_SPHERE_RADIUS] =
-          {
-              "",
-              "node_tex_voronoi_n_sphere_radius_1d",
-              "node_tex_voronoi_n_sphere_radius_2d",
-              "node_tex_voronoi_n_sphere_radius_3d",
-              "node_tex_voronoi_n_sphere_radius_4d",
-          },
-  };
-
   NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
   float metric = tex->distance;
 
@@ -138,7 +141,7 @@ static int node_shader_gpu_tex_voronoi(GPUMaterial *mat,
   BLI_assert(tex->dimensions > 0 && tex->dimensions < 5);
 
   return GPU_stack_link(
-      mat, node, names[tex->feature][tex->dimensions], in, out, GPU_constant(&metric));
+      mat, node, node_shader_gpu_name_tex_voronoi(tex), in, out, GPU_constant(&metric));
 }
 
 static void node_shader_update_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
@@ -178,17 +181,81 @@ static void node_shader_update_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node
   nodeSetSocketAvailability(outRadiusSock, tex->feature == SHD_VORONOI_N_SPHERE_RADIUS);
 }
 
+class VoronoiTextureFunction : public blender::fn::MultiFunction {
+ public:
+  VoronoiTextureFunction()
+  {
+    static blender::fn::MFSignature signature = create_signature();
+    this->set_signature(&signature);
+  }
+
+  static blender::fn::MFSignature create_signature()
+  {
+    blender::fn::MFSignatureBuilder signature{"Noise Texture"};
+    signature.single_input<blender::float3>("Vector");
+    signature.single_input<float>("Scale");
+    signature.single_input<float>("Randomness");
+    signature.single_output<float>("Distance");
+    signature.single_output<blender::ColorGeometry4f>("Color");
+    signature.single_output<blender::float3>("Position");
+    return signature.build();
+  }
+
+  void call(blender::IndexMask mask,
+            blender::fn::MFParams params,
+            blender::fn::MFContext UNUSED(context)) const override
+  {
+    const blender::VArray<blender::float3> &vectors =
+        params.readonly_single_input<blender::float3>(0, "Vector");
+    const blender::VArray<float> &scales = params.readonly_single_input<float>(1, "Scale");
+
+    blender::MutableSpan<float> r_distances = params.uninitialized_single_output<float>(
+        3, "Distance");
+    blender::MutableSpan<blender::ColorGeometry4f> r_colors =
+        params.uninitialized_single_output<blender::ColorGeometry4f>(4, "Color");
+    blender::MutableSpan<blender::float3> r_positions =
+        params.uninitialized_single_output<blender::float3>(5, "Position");
+
+    for (int i : mask) {
+      const float scale = scales[i];
+      const blender::float3 vector = vectors[i] * scale;
+      float da[4];
+      float pa[12];
+      BLI_noise_voronoi(vector.x, vector.y, vector.z, da, pa, 1, 0);
+      blender::ColorGeometry4f color;
+      BLI_noise_cell_v3(pa[0], pa[1], pa[1], color);
+      color.a = 1.0f;
+      r_distances[i] = da[0];
+      r_colors[i] = color;
+      r_positions[i] = {pa[0], pa[1], pa[2]};
+    }
+  }
+};
+
+static void sh_node_tex_voronoi_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
+{
+  NodeTexVoronoi *tex = builder.dnode()->storage<NodeTexVoronoi>();
+  if (tex->dimensions != 3 || tex->feature != SHD_VORONOI_F1 ||
+      tex->distance != SHD_VORONOI_EUCLIDEAN) {
+    builder.set_not_implemented();
+    return;
+  }
+  static VoronoiTextureFunction fn;
+  builder.set_matching_fn(fn);
+}
+
 void register_node_type_sh_tex_voronoi(void)
 {
   static bNodeType ntype;
 
-  sh_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0);
+  sh_fn_node_type_base(&ntype, SH_NODE_TE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list