[Bf-blender-cvs] [fbd01624e3f] master: Shader Nodes: Convert bump node to use new socket builder

Aaron Carlisle noreply at git.blender.org
Sat Dec 25 17:13:22 CET 2021


Commit: fbd01624e3feb10add9d04672a3db0f52817423a
Author: Aaron Carlisle
Date:   Sat Dec 25 11:12:43 2021 -0500
Branches: master
https://developer.blender.org/rBfbd01624e3feb10add9d04672a3db0f52817423a

Shader Nodes: Convert bump node to use new socket builder

This node is a bit special in that it uses two internal sockets
for a hack for Eevee; see rBffd5e1e6acd296a187e7af016f9d7f8a9f209f87

As a result, the `SOCK_UNAVAIL` flag is exposed to socket builder API.

Reviewed By: JacquesLucke, fclem

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

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

M	source/blender/nodes/NOD_node_declaration.hh
M	source/blender/nodes/intern/node_declaration.cc
M	source/blender/nodes/shader/nodes/node_shader_bump.cc

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

diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index 4ad1bcad885..113e8ffc93d 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -95,6 +95,7 @@ class SocketDeclaration {
   bool compact_ = false;
   bool is_multi_input_ = false;
   bool no_mute_links_ = false;
+  bool is_unavailable_ = false;
   bool is_attribute_name_ = false;
   bool is_default_link_socket_ = false;
 
@@ -185,12 +186,23 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
     decl_->description_ = std::move(value);
     return *(Self *)this;
   }
+
   Self &no_muted_links(bool value = true)
   {
     decl_->no_mute_links_ = value;
     return *(Self *)this;
   }
 
+  /**
+   * Used for sockets that are always unavailable and should not be seen by the user.
+   * Ideally, no new calls to this method should be added over time.
+   */
+  Self &unavailable(bool value = true)
+  {
+    decl_->is_unavailable_ = value;
+    return *(Self *)this;
+  }
+
   Self &is_attribute_name(bool value = true)
   {
     decl_->is_attribute_name_ = value;
diff --git a/source/blender/nodes/intern/node_declaration.cc b/source/blender/nodes/intern/node_declaration.cc
index 75d47cfd386..28e8bf5a4b7 100644
--- a/source/blender/nodes/intern/node_declaration.cc
+++ b/source/blender/nodes/intern/node_declaration.cc
@@ -63,6 +63,7 @@ void SocketDeclaration::set_common_flags(bNodeSocket &socket) const
   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);
+  SET_FLAG_FROM_TEST(socket.flag, is_unavailable_, SOCK_UNAVAIL);
 }
 
 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_NO_INTERNAL_LINK) != 0) != no_mute_links_) {
     return false;
   }
+  if (((socket.flag & SOCK_UNAVAIL) != 0) != is_unavailable_) {
+    return false;
+  }
   return true;
 }
 
diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.cc b/source/blender/nodes/shader/nodes/node_shader_bump.cc
index 3d90927116f..086f657307c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bump.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bump.cc
@@ -24,19 +24,27 @@
 #include "node_shader_util.h"
 
 /* **************** BUMP ******************** */
-/* clang-format off */
-static bNodeSocketTemplate sh_node_bump_in[] = {
-    {SOCK_FLOAT, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-    {SOCK_FLOAT, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
-    {SOCK_FLOAT, N_("Height"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_HIDE_VALUE},
-    {SOCK_FLOAT, N_("Height_dx"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_UNAVAIL},
-    {SOCK_FLOAT, N_("Height_dy"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_UNAVAIL},
-    {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-    {-1, ""}
-};
-/* clang-format on */
 
-static bNodeSocketTemplate sh_node_bump_out[] = {{SOCK_VECTOR, "Normal"}, {-1, ""}};
+namespace blender::nodes::node_shader_bump_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+  b.add_input<decl::Float>(N_("Strength"))
+      .default_value(1.0f)
+      .min(0.0f)
+      .max(1.0f)
+      .subtype(PROP_FACTOR);
+  b.add_input<decl::Float>(N_("Distance")).default_value(1.0f).min(0.0f).max(1000.0f);
+  b.add_input<decl::Float>(N_("Height"))
+      .default_value(1.0f)
+      .min(-1000.0f)
+      .max(1000.0f)
+      .hide_value();
+  b.add_input<decl::Float>(N_("Height_dx")).default_value(1.0f).unavailable();
+  b.add_input<decl::Float>(N_("Height_dy")).default_value(1.0f).unavailable();
+  b.add_input<decl::Vector>(N_("Normal")).min(-1.0f).max(1.0f).hide_value();
+  b.add_output<decl::Vector>(N_("Normal"));
+}
 
 static int gpu_shader_bump(GPUMaterial *mat,
                            bNode *node,
@@ -54,15 +62,19 @@ static int gpu_shader_bump(GPUMaterial *mat,
       mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert));
 }
 
+}  // namespace blender::nodes::node_shader_bump_cc
+
 /* node type definition */
 void register_node_type_sh_bump()
 {
+  namespace file_ns = blender::nodes::node_shader_bump_cc;
+
   static bNodeType ntype;
 
   sh_node_type_base(&ntype, SH_NODE_BUMP, "Bump", NODE_CLASS_OP_VECTOR, 0);
-  node_type_socket_templates(&ntype, sh_node_bump_in, sh_node_bump_out);
+  ntype.declare = file_ns::node_declare;
   node_type_storage(&ntype, "", nullptr, nullptr);
-  node_type_gpu(&ntype, gpu_shader_bump);
+  node_type_gpu(&ntype, file_ns::gpu_shader_bump);
 
   nodeRegisterType(&ntype);
 }



More information about the Bf-blender-cvs mailing list