29 b.add_input<
decl::Vector>(
"Vector",
"Vector_001").
min(-10000.0f).max(10000.0f);
30 b.add_input<
decl::Vector>(
"Vector",
"Vector_002").
min(-10000.0f).max(10000.0f);
31 b.add_input<
decl::Float>(
"Scale").default_value(1.0f).min(-10000.0f).max(10000.0f);
47 bNode &node =
params.add_node(
"ShaderNodeVectorMath");
66 if (item->name !=
nullptr && item->identifier[0] !=
'\0') {
89 return "vector_math_add";
91 return "vector_math_subtract";
93 return "vector_math_multiply";
95 return "vector_math_divide";
98 return "vector_math_cross";
100 return "vector_math_project";
102 return "vector_math_reflect";
104 return "vector_math_dot";
107 return "vector_math_distance";
109 return "vector_math_length";
111 return "vector_math_scale";
113 return "vector_math_normalize";
116 return "vector_math_snap";
118 return "vector_math_floor";
120 return "vector_math_ceil";
122 return "vector_math_modulo";
124 return "vector_math_fraction";
126 return "vector_math_absolute";
128 return "vector_math_minimum";
130 return "vector_math_maximum";
132 return "vector_math_wrap";
134 return "vector_math_sine";
136 return "vector_math_cosine";
138 return "vector_math_tangent";
140 return "vector_math_refract";
142 return "vector_math_faceforward";
144 return "vector_math_multiply_add";
146 return "vector_math_power";
148 return "vector_math_sign";
161 if (
name !=
nullptr) {
251 const mf::MultiFunction *multi_fn =
nullptr;
255 static auto fn = mf::build::SI2_SO<float3, float3, float3>(
259 if (multi_fn !=
nullptr) {
265 static auto fn = mf::build::SI3_SO<float3, float3, float3, float3>(
269 if (multi_fn !=
nullptr) {
275 static auto fn = mf::build::SI3_SO<float3, float3, float, float3>(
279 if (multi_fn !=
nullptr) {
285 static auto fn = mf::build::SI2_SO<float3, float3, float>(
289 if (multi_fn !=
nullptr) {
295 static auto fn = mf::build::SI2_SO<float3, float, float3>(
299 if (multi_fn !=
nullptr) {
305 static auto fn = mf::build::SI1_SO<float3, float3>(
309 if (multi_fn !=
nullptr) {
315 static auto fn = mf::build::SI1_SO<float3, float>(
319 if (multi_fn !=
nullptr) {
341 VectorElem output_elem;
342 output_elem.merge(
params.get_input_elem<VectorElem>(
"Vector"));
343 output_elem.merge(
params.get_input_elem<VectorElem>(
"Vector_001"));
344 params.set_output_elem(
"Vector", output_elem);
348 VectorElem output_elem;
349 output_elem.merge(
params.get_input_elem<VectorElem>(
"Vector"));
350 if (
params.get_input_elem<FloatElem>(
"Scale")) {
351 output_elem = VectorElem::all();
353 params.set_output_elem(
"Vector", output_elem);
380 const StringRef first_input_id =
"Vector";
381 const StringRef second_input_id =
"Vector_001";
382 const StringRef scale_input_id =
"Scale";
383 const StringRef output_vector_id =
"Vector";
386 params.set_input(first_input_id,
392 params.set_input(first_input_id,
398 params.set_input(first_input_id,
404 params.set_input(first_input_id,
410 params.set_input(first_input_id,
424 auto op = node_->custom1;
425 NodeItem res = empty();
426 const NodeItem null_vec = val(MaterialX::Vector3(0.0f));
429 NodeItem
x = get_input_value(0, NodeItem::Type::Vector3);
458 res =
length.if_else(NodeItem::CompareOp::Eq, val(0.0f), null_vec,
x /
length);
464 NodeItem
y = get_input_value(1, NodeItem::Type::Vector3);
465 NodeItem
w = get_input_value(3, NodeItem::Type::Float);
493 res = create_node(
"crossproduct", NodeItem::Type::Vector3, {{
"in1",
x}, {
"in2",
y}});
496 res =
x.dotproduct(
y);
499 NodeItem len_sq =
y.dotproduct(
y);
500 res = len_sq.if_else(
501 NodeItem::CompareOp::NotEq, val(0.0f), (
x.dotproduct(
y) / len_sq) *
y, null_vec);
506 res =
x - val(2.0f) *
y.dotproduct(
x) *
y;
517 NodeItem
z = get_input_value(2, NodeItem::Type::Vector3);
525 NodeItem dot_yx =
y.dotproduct(
x);
526 NodeItem k = val(1.0f) - (
w *
w * (val(1.0f) - (dot_yx * dot_yx)));
527 NodeItem r =
w *
x - ((
w * dot_yx + k.sqrt()) *
y);
528 res = k.if_else(NodeItem::CompareOp::GreaterEq, val(0.0f), r, null_vec);
532 res =
z.dotproduct(
y).if_else(NodeItem::CompareOp::GreaterEq, val(0.0f), -
x,
x);
536 NodeItem range = (
y -
z);
537 NodeItem if_branch =
x - (range * ((
x -
z) / range).floor());
539 res = create_node(
"combine3", NodeItem::Type::Vector3);
540 std::vector<std::string>
inputs = {
"in1",
"in2",
"in3"};
542 for (
size_t i = 0;
i <
inputs.size(); ++
i) {
545 range[
i].if_else(NodeItem::CompareOp::NotEq, val(0.0f), if_branch[
i],
z[
i]));
575 ntype.
declare = file_ns::sh_node_vector_math_declare;
576 ntype.
draw_buttons = file_ns::node_shader_buts_vect_math;
578 ntype.
gpu_fn = file_ns::gpu_shader_vector_math;
579 ntype.
updatefunc = file_ns::node_shader_update_vector_math;
583 ntype.
eval_elem = file_ns::node_eval_elem;
#define NODE_CLASS_OP_VECTOR
#define SH_NODE_VECTOR_MATH
#define BLI_assert_unreachable()
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
@ NODE_VECTOR_MATH_NORMALIZE
@ NODE_VECTOR_MATH_LENGTH
@ NODE_VECTOR_MATH_CROSS_PRODUCT
@ NODE_VECTOR_MATH_MODULO
@ NODE_VECTOR_MATH_COSINE
@ NODE_VECTOR_MATH_REFLECT
@ NODE_VECTOR_MATH_REFRACT
@ NODE_VECTOR_MATH_DOT_PRODUCT
@ NODE_VECTOR_MATH_ABSOLUTE
@ NODE_VECTOR_MATH_DIVIDE
@ NODE_VECTOR_MATH_TANGENT
@ NODE_VECTOR_MATH_DISTANCE
@ NODE_VECTOR_MATH_FRACTION
@ NODE_VECTOR_MATH_PROJECT
@ NODE_VECTOR_MATH_MULTIPLY
@ NODE_VECTOR_MATH_MAXIMUM
@ NODE_VECTOR_MATH_FACEFORWARD
@ NODE_VECTOR_MATH_SUBTRACT
@ NODE_VECTOR_MATH_MULTIPLY_ADD
@ NODE_VECTOR_MATH_MINIMUM
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
constexpr const char * c_str() const
void set_matching_fn(const mf::MultiFunction *fn)
NodeVectorMathOperation mode
void operator()(LinkSearchOpParams ¶ms)
float length(VecOp< float, D >) RET
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
void node_register_type(bNodeType &ntype)
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
T safe_divide(const T &a, const T &b)
static const char * gpu_shader_get_name(int mode)
static void sh_node_vector_math_build_multi_function(NodeMultiFunctionBuilder &builder)
static int gpu_shader_vector_math(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_buts_vect_math(uiLayout *layout, bContext *, PointerRNA *ptr)
static void sh_node_vector_math_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_eval_elem(value_elem::ElemEvalParams ¶ms)
static const mf::MultiFunction * get_multi_function(const bNode &node)
static void node_eval_inverse(inverse_eval::InverseEvalParams ¶ms)
static void node_shader_update_vector_math(bNodeTree *ntree, bNode *node)
static void sh_node_vector_math_declare(NodeDeclarationBuilder &b)
static void node_eval_inverse_elem(value_elem::InverseElemEvalParams ¶ms)
bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
VecBase< float, 3 > float3
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void common_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void register_node_type_sh_vect_math()
static blender::bke::bNodeSocketTemplate inputs[]
void node_sock_label_clear(bNodeSocket *sock)
void node_sock_label(bNodeSocket *sock, const char *name)
void node_vector_math_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
const EnumPropertyItem rna_enum_node_vec_math_items[]
NodeInverseElemEvalFunction eval_inverse_elem
NodeMaterialXFunction materialx_fn
NodeInverseEvalFunction eval_inverse
std::string ui_description
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
NodeGPUExecFunction gpu_fn
NodeElemEvalFunction eval_elem
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
void(* updatefunc)(bNodeTree *ntree, bNode *node)
StringRefNull title_case_name
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)