diff options
Diffstat (limited to 'source/blender/nodes/shader/nodes/node_shader_vector_math.cc')
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_vector_math.cc | 186 |
1 files changed, 75 insertions, 111 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc index 3a9822fbc8e..472f903e1a5 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc +++ b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc @@ -23,6 +23,8 @@ #include "node_shader_util.h" +#include "NOD_math_functions.hh" + /* **************** VECTOR MATH ******************** */ static bNodeSocketTemplate sh_node_vector_math_in[] = { {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, @@ -177,117 +179,79 @@ static const blender::fn::MultiFunction &get_multi_function( { using blender::float3; - const int mode = builder.bnode().custom1; - switch (mode) { - case NODE_VECTOR_MATH_ADD: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{ - "Add", [](float3 a, float3 b) { return a + b; }}; - return fn; - } - case NODE_VECTOR_MATH_SUBTRACT: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{ - "Subtract", [](float3 a, float3 b) { return a - b; }}; - return fn; - } - case NODE_VECTOR_MATH_MULTIPLY: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{ - "Multiply", [](float3 a, float3 b) { return a * b; }}; - return fn; - } - case NODE_VECTOR_MATH_DIVIDE: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{ - "Divide", [](float3 a, float3 b) { return float3::safe_divide(a, b); }}; - return fn; - } - case NODE_VECTOR_MATH_CROSS_PRODUCT: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{ - "Cross Product", float3::cross_high_precision}; - return fn; - } - case NODE_VECTOR_MATH_PROJECT: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{"Project", float3::project}; - return fn; - } - case NODE_VECTOR_MATH_REFLECT: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{ - "Reflect", [](float3 a, float3 b) { return a.reflected(b); }}; - return fn; - } - case NODE_VECTOR_MATH_DOT_PRODUCT: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float> fn{"Dot Product", float3::dot}; - return fn; - } - case NODE_VECTOR_MATH_DISTANCE: { - static blender::fn::CustomMF_SI_SI_SO<float3, float3, float> fn{"Distance", - float3::distance}; - return fn; - } - case NODE_VECTOR_MATH_LENGTH: { - static blender::fn::CustomMF_SI_SO<float3, float> fn{"Length", - [](float3 a) { return a.length(); }}; - return fn; - } - case NODE_VECTOR_MATH_SCALE: { - static blender::fn::CustomMF_SI_SI_SO<float3, float, float3> fn{ - "Scale", [](float3 a, float factor) { return a * factor; }}; - return fn; - } - case NODE_VECTOR_MATH_NORMALIZE: { - static blender::fn::CustomMF_SI_SO<float3, float3> fn{ - "Normalize", [](float3 a) { return a.normalized(); }}; - return fn; - } - case NODE_VECTOR_MATH_REFRACT: { - static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float, float3> fn{ - "Refract", - [](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); }}; - return fn; - } - case NODE_VECTOR_MATH_FACEFORWARD: { - static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float3, float3> fn{ - "Faceforward", float3::faceforward}; - return fn; - } - case NODE_VECTOR_MATH_SNAP: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_FLOOR: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_CEIL: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_MODULO: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_FRACTION: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_ABSOLUTE: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_MINIMUM: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_MAXIMUM: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_WRAP: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_SINE: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_COSINE: { - return builder.get_not_implemented_fn(); - } - case NODE_VECTOR_MATH_TANGENT: { - return builder.get_not_implemented_fn(); - } - default: - BLI_assert_unreachable(); - return builder.get_not_implemented_fn(); - }; + NodeVectorMathOperation operation = NodeVectorMathOperation(builder.bnode().custom1); + + const blender::fn::MultiFunction *multi_fn = nullptr; + + blender::nodes::try_dispatch_float_math_fl3_fl3_to_fl3( + operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) { + static blender::fn::CustomMF_SI_SI_SO<float3, float3, float3> fn{info.title_case_name, + function}; + multi_fn = &fn; + }); + if (multi_fn != nullptr) { + return *multi_fn; + } + + blender::nodes::try_dispatch_float_math_fl3_fl3_fl3_to_fl3( + operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) { + static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float3, float3> fn{ + info.title_case_name, function}; + multi_fn = &fn; + }); + if (multi_fn != nullptr) { + return *multi_fn; + } + + blender::nodes::try_dispatch_float_math_fl3_fl3_fl_to_fl3( + operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) { + static blender::fn::CustomMF_SI_SI_SI_SO<float3, float3, float, float3> fn{ + info.title_case_name, function}; + multi_fn = &fn; + }); + if (multi_fn != nullptr) { + return *multi_fn; + } + + blender::nodes::try_dispatch_float_math_fl3_fl3_to_fl( + operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) { + static blender::fn::CustomMF_SI_SI_SO<float3, float3, float> fn{info.title_case_name, + function}; + multi_fn = &fn; + }); + if (multi_fn != nullptr) { + return *multi_fn; + } + + blender::nodes::try_dispatch_float_math_fl3_fl_to_fl3( + operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) { + static blender::fn::CustomMF_SI_SI_SO<float3, float, float3> fn{info.title_case_name, + function}; + multi_fn = &fn; + }); + if (multi_fn != nullptr) { + return *multi_fn; + } + + blender::nodes::try_dispatch_float_math_fl3_to_fl3( + operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) { + static blender::fn::CustomMF_SI_SO<float3, float3> fn{info.title_case_name, function}; + multi_fn = &fn; + }); + if (multi_fn != nullptr) { + return *multi_fn; + } + + blender::nodes::try_dispatch_float_math_fl3_to_fl( + operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) { + static blender::fn::CustomMF_SI_SO<float3, float> fn{info.title_case_name, function}; + multi_fn = &fn; + }); + if (multi_fn != nullptr) { + return *multi_fn; + } + + return builder.get_not_implemented_fn(); } static void sh_node_vector_math_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder) |