[Bf-blender-cvs] [4437f233f7d] geometry-nodes-deduplicate-float-math: dispatch 3 input functions

Jacques Lucke noreply at git.blender.org
Tue Nov 24 17:17:47 CET 2020


Commit: 4437f233f7d10fda7073a7727daa03edf777ea4b
Author: Jacques Lucke
Date:   Tue Nov 24 16:26:50 2020 +0100
Branches: geometry-nodes-deduplicate-float-math
https://developer.blender.org/rB4437f233f7d10fda7073a7727daa03edf777ea4b

dispatch 3 input functions

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

M	source/blender/nodes/NOD_math_functions.hh
M	source/blender/nodes/shader/nodes/node_shader_math.cc

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

diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh
index 3e2db131c29..346c80bcfda 100644
--- a/source/blender/nodes/NOD_math_functions.hh
+++ b/source/blender/nodes/NOD_math_functions.hh
@@ -141,4 +141,28 @@ inline bool dispatch_float_math_fl_to_fl(const int operation, OpType &&op)
   return false;
 }
 
+template<typename OpType>
+inline bool dispatch_float_math_fl_fl_fl_to_fl(const int operation, OpType &&op)
+{
+  const FloatMathOperationInfo *info = get_float_math_operation_info(operation);
+  if (info == nullptr) {
+    return false;
+  }
+
+  auto dispatch = [&](auto function) -> bool {
+    op(function, *info);
+    return true;
+  };
+
+  switch (operation) {
+    case NODE_MATH_MULTIPLY_ADD:
+      return dispatch([](float a, float b, float c) { return a * b + c; });
+    case NODE_MATH_COMPARE:
+      return dispatch([](float a, float b, float c) -> float {
+        return ((a == b) || (fabsf(a - b) <= fmaxf(c, FLT_EPSILON))) ? 1.0f : 0.0f;
+      });
+  }
+  return false;
+}
+
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.cc b/source/blender/nodes/shader/nodes/node_shader_math.cc
index 493158a5f28..b670dd7ce25 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_math.cc
@@ -76,6 +76,15 @@ static const blender::fn::MultiFunction &get_base_multi_function(
 
   const blender::fn::MultiFunction *base_fn = nullptr;
 
+  blender::nodes::dispatch_float_math_fl_to_fl(
+      mode, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
+        static blender::fn::CustomMF_SI_SO<float, float> fn{info.title_case_name, function};
+        base_fn = &fn;
+      });
+  if (base_fn != nullptr) {
+    return *base_fn;
+  }
+
   blender::nodes::dispatch_float_math_fl_fl_to_fl(
       mode, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
         static blender::fn::CustomMF_SI_SI_SO<float, float, float> fn{info.title_case_name,
@@ -86,9 +95,10 @@ static const blender::fn::MultiFunction &get_base_multi_function(
     return *base_fn;
   }
 
-  blender::nodes::dispatch_float_math_fl_to_fl(
+  blender::nodes::dispatch_float_math_fl_fl_fl_to_fl(
       mode, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
-        static blender::fn::CustomMF_SI_SO<float, float> fn{info.title_case_name, function};
+        static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, float> fn{
+            info.title_case_name, function};
         base_fn = &fn;
       });
   if (base_fn != nullptr) {
@@ -96,38 +106,6 @@ static const blender::fn::MultiFunction &get_base_multi_function(
   }
 
   return builder.get_not_implemented_fn();
-
-  switch (mode) {
-    case NODE_MATH_MULTIPLY_ADD: {
-      static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, float> fn{
-          "Multiply Add", [](float a, float b, float c) { return a * b + c; }};
-      return fn;
-    }
-    case NODE_MATH_COMPARE: {
-      static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, float> fn{
-          "Compare", [](float a, float b, float c) -> float {
-            return ((a == b) || (fabsf(a - b) <= fmaxf(c, FLT_EPSILON))) ? 1.0f : 0.0f;
-          }};
-      return fn;
-    }
-    case NODE_MATH_SMOOTH_MIN: {
-      return builder.get_not_implemented_fn();
-    }
-    case NODE_MATH_SMOOTH_MAX: {
-      return builder.get_not_implemented_fn();
-    }
-
-    case NODE_MATH_WRAP: {
-      return builder.get_not_implemented_fn();
-    }
-    case NODE_MATH_PINGPONG: {
-      return builder.get_not_implemented_fn();
-    }
-
-    default:
-      BLI_assert(false);
-      return builder.get_not_implemented_fn();
-  }
 }
 
 static void sh_node_math_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)



More information about the Bf-blender-cvs mailing list