Geometry Nodes: Add remaining operations to the Vector Math node

This patch adds support for the remaining operations of the Vector Math
node within Geometry Nodes.  While the operations are already available
in the UI, they hadn't been implemented, yet. With this patch the node
uses the implementation that was added for the Attribute Vector Math
node - similar to how it's handled with the Math node and Attribute
Math node.

Differential Revision: https://developer.blender.org/D10650
This commit is contained in:
Leon Leno 2021-03-26 12:15:33 -04:00 committed by Hans Goudey
parent 63a6268e83
commit 97e212f52e
1 changed files with 75 additions and 111 deletions

View File

@ -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)