[Bf-blender-cvs] [79bcc192402] master: Cleanup: Move more shader nodes to socket declaration API

Hans Goudey noreply at git.blender.org
Thu Sep 23 00:34:16 CEST 2021


Commit: 79bcc19240258fe697b583376f59902c3235691c
Author: Hans Goudey
Date:   Wed Sep 22 17:34:09 2021 -0500
Branches: master
https://developer.blender.org/rB79bcc19240258fe697b583376f59902c3235691c

Cleanup: Move more shader nodes to socket declaration API

I had to add `no_muted_links` to the declaration API. The name could
change there, but I think it's more obvious than "internal"

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

M	source/blender/nodes/NOD_node_declaration.hh
M	source/blender/nodes/intern/node_declaration.cc
M	source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
M	source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
M	source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
M	source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc

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

diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index d64b76ccbb9..8e9e72bf4c8 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -37,6 +37,7 @@ class SocketDeclaration {
   bool hide_label_ = false;
   bool hide_value_ = false;
   bool is_multi_input_ = false;
+  bool no_mute_links_ = false;
 
   friend NodeDeclarationBuilder;
   template<typename SocketDecl> friend class SocketDeclarationBuilder;
@@ -93,6 +94,12 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
     decl_->is_multi_input_ = value;
     return *(Self *)this;
   }
+
+  Self &no_muted_links(bool value = true)
+  {
+    decl_->no_mute_links_ = value;
+    return *(Self *)this;
+  }
 };
 
 using SocketDeclarationPtr = std::unique_ptr<SocketDeclaration>;
diff --git a/source/blender/nodes/intern/node_declaration.cc b/source/blender/nodes/intern/node_declaration.cc
index f6b6cc49b2e..8a38b68ec59 100644
--- a/source/blender/nodes/intern/node_declaration.cc
+++ b/source/blender/nodes/intern/node_declaration.cc
@@ -69,6 +69,7 @@ void SocketDeclaration::set_common_flags(bNodeSocket &socket) const
   SET_FLAG_FROM_TEST(socket.flag, hide_value_, SOCK_HIDE_VALUE);
   SET_FLAG_FROM_TEST(socket.flag, hide_label_, SOCK_HIDE_LABEL);
   SET_FLAG_FROM_TEST(socket.flag, is_multi_input_, SOCK_MULTI_INPUT);
+  SET_FLAG_FROM_TEST(socket.flag, no_mute_links_, SOCK_NO_INTERNAL_LINK);
 }
 
 bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
@@ -88,6 +89,9 @@ bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
   if (((socket.flag & SOCK_MULTI_INPUT) != 0) != is_multi_input_) {
     return false;
   }
+  if (((socket.flag & SOCK_NO_INTERNAL_LINK) != 0) != no_mute_links_) {
+    return false;
+  }
   return true;
 }
 
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
index 0c0d75179a9..e0520ee49d3 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
@@ -19,27 +19,16 @@
 
 #include "../node_shader_util.h"
 
-/* **************** BLEND ******************** */
+namespace blender::nodes {
 
-static bNodeSocketTemplate sh_node_tex_gradient_in[] = {
-    {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-    {-1, ""},
+static void sh_node_tex_gradient_declare(NodeDeclarationBuilder &b)
+{
+  b.add_input<decl::Vector>("Vector").hide_value();
+  b.add_output<decl::Color>("Color").no_muted_links();
+  b.add_output<decl::Float>("Fac").no_muted_links();
 };
 
-static bNodeSocketTemplate sh_node_tex_gradient_out[] = {
-    {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
-    {SOCK_FLOAT,
-     N_("Fac"),
-     0.0f,
-     0.0f,
-     0.0f,
-     0.0f,
-     0.0f,
-     1.0f,
-     PROP_FACTOR,
-     SOCK_NO_INTERNAL_LINK},
-    {-1, ""},
-};
+}  // namespace blender::nodes
 
 static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode *node)
 {
@@ -72,7 +61,7 @@ void register_node_type_sh_tex_gradient(void)
   static bNodeType ntype;
 
   sh_node_type_base(&ntype, SH_NODE_TEX_GRADIENT, "Gradient Texture", NODE_CLASS_TEXTURE, 0);
-  node_type_socket_templates(&ntype, sh_node_tex_gradient_in, sh_node_tex_gradient_out);
+  ntype.declare = blender::nodes::sh_node_tex_gradient_declare;
   node_type_init(&ntype, node_shader_init_tex_gradient);
   node_type_storage(
       &ntype, "NodeTexGradient", node_free_standard_storage, node_copy_standard_storage);
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
index f5e9aef3aad..d33d92f25fd 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
@@ -19,34 +19,23 @@
 
 #include "../node_shader_util.h"
 
-/* **************** MUSGRAVE ******************** */
-
-static bNodeSocketTemplate sh_node_tex_musgrave_in[] = {
-    {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-    {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f},
-    {SOCK_FLOAT, N_("Dimension"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Gain"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
-    {-1, ""},
-};
+namespace blender::nodes {
 
-static bNodeSocketTemplate sh_node_tex_musgrave_out[] = {
-    {SOCK_FLOAT,
-     N_("Fac"),
-     0.0f,
-     0.0f,
-     0.0f,
-     0.0f,
-     0.0f,
-     1.0f,
-     PROP_FACTOR,
-     SOCK_NO_INTERNAL_LINK},
-    {-1, ""},
+static void sh_node_tex_musgrave_declare(NodeDeclarationBuilder &b)
+{
+  b.add_input<decl::Vector>("Vector").hide_value();
+  b.add_input<decl::Float>("W").min(-1000.0f).max(1000.0f);
+  b.add_input<decl::Float>("Scale").min(-1000.0f).max(1000.0f).default_value(5.0f);
+  b.add_input<decl::Float>("Detail").min(0.0f).max(16.0f).default_value(2.0f);
+  b.add_input<decl::Float>("Dimension").min(0.0f).max(1000.0f).default_value(2.0f);
+  b.add_input<decl::Float>("Lacunarity").min(0.0f).max(1000.0f).default_value(2.0f);
+  b.add_input<decl::Float>("Offset").min(-1000.0f).max(1000.0f);
+  b.add_input<decl::Float>("Gain").min(0.0f).max(1000.0f).default_value(1.0f);
+  b.add_output<decl::Float>("Fac").no_muted_links();
 };
 
+}  // namespace blender::nodes
+
 static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node)
 {
   NodeTexMusgrave *tex = (NodeTexMusgrave *)MEM_callocN(sizeof(NodeTexMusgrave),
@@ -139,7 +128,7 @@ void register_node_type_sh_tex_musgrave(void)
   static bNodeType ntype;
 
   sh_node_type_base(&ntype, SH_NODE_TEX_MUSGRAVE, "Musgrave Texture", NODE_CLASS_TEXTURE, 0);
-  node_type_socket_templates(&ntype, sh_node_tex_musgrave_in, sh_node_tex_musgrave_out);
+  ntype.declare = blender::nodes::sh_node_tex_musgrave_declare;
   node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
   node_type_init(&ntype, node_shader_init_tex_musgrave);
   node_type_storage(
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 c0deb232b2d..1ae6b3a616c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
@@ -21,32 +21,25 @@
 
 #include "BLI_noise.hh"
 
-/* **************** NOISE ******************** */
+namespace blender::nodes {
 
-static bNodeSocketTemplate sh_node_tex_noise_in[] = {
-    {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-    {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f},
-    {SOCK_FLOAT, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-    {SOCK_FLOAT, N_("Distortion"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {-1, ""},
+static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b)
+{
+  b.add_input<decl::Vector>("Vector").hide_value();
+  b.add_input<decl::Float>("W").min(-1000.0f).max(1000.0f);
+  b.add_input<decl::Float>("Scale").min(-1000.0f).max(1000.0f).default_value(5.0f);
+  b.add_input<decl::Float>("Detail").min(0.0f).max(16.0f).default_value(2.0f);
+  b.add_input<decl::Float>("Roughness")
+      .min(0.0f)
+      .max(1.0f)
+      .default_value(0.5f)
+      .subtype(PROP_FACTOR);
+  b.add_input<decl::Float>("Distortion").min(-1000.0f).max(1000.0f).default_value(0.0f);
+  b.add_output<decl::Float>("Fac").no_muted_links();
+  b.add_output<decl::Color>("Color").no_muted_links();
 };
 
-static bNodeSocketTemplate sh_node_tex_noise_out[] = {
-    {SOCK_FLOAT,
-     N_("Fac"),
-     0.0f,
-     0.0f,
-     0.0f,
-     0.0f,
-     0.0f,
-     1.0f,
-     PROP_FACTOR,
-     SOCK_NO_INTERNAL_LINK},
-    {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
-    {-1, ""},
-};
+}  // namespace blender::nodes
 
 static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node)
 {
@@ -252,7 +245,7 @@ void register_node_type_sh_tex_noise(void)
   static bNodeType ntype;
 
   sh_fn_node_type_base(&ntype, SH_NODE_TEX_NOISE, "Noise Texture", NODE_CLASS_TEXTURE, 0);
-  node_type_socket_templates(&ntype, sh_node_tex_noise_in, sh_node_tex_noise_out);
+  ntype.declare = blender::nodes::sh_node_tex_noise_declare;
   node_type_init(&ntype, node_shader_init_tex_noise);
   node_type_storage(
       &ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage);
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
index 1cc715d99ea..cea7af247c1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
@@ -19,54 +19,33 @@
 
 #include "../node_shader_util.h"
 
-/* **************** VORONOI ******************** */
-
-static bNodeSocketTemplate sh_node_tex_voronoi_in[] = {
-    {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-    {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Smoothness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-    {SOCK_FLOAT, N_("Exponent"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 32.0f},
-    {SOCK_FLOAT, N_("Randomness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-    {-1, ""},
-};
+namespace blender::nodes {
 
-static bNodeSocketTemplate sh_node_tex_voronoi_out[] = {
-    {SOCK_FLOAT,
-     N_("Distance"),
-     0.0f,
-     0.0f

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list