38 switch (
node.custom1) {
49 switch (
node.custom1) {
53 return IFACE_(
"Multiplier");
59 return IFACE_(
"Increment");
68 switch (
node.custom1) {
72 return IFACE_(
"Reference");
84 switch (
node.custom1) {
116 for (
int i = 0; i < in_vector_2->
dimensions; i++) {
117 in_vector_2->
value[i] = 1.0f;
123 for (
int i = 0; i < in_vector_3->
dimensions; i++) {
124 in_vector_2->
value[i] = 1.0f;
125 in_vector_3->
value[i] = 0.0f;
160 if (item->name !=
nullptr && item->identifier[0] !=
'\0') {
167 SocketSearchOp{
"Value"_ustr, NodeVectorMathOperation(item->value)},
172 SocketSearchOp{
"Vector"_ustr, NodeVectorMathOperation(item->value)},
183 return "vector_math_add";
185 return "vector_math_subtract";
187 return "vector_math_multiply";
189 return "vector_math_divide";
192 return "vector_math_cross";
194 return "vector_math_project";
196 return "vector_math_reflect";
198 return "vector_math_dot";
201 return "vector_math_distance";
203 return "vector_math_length";
205 return "vector_math_scale";
207 return "vector_math_normalize";
210 return "vector_math_snap";
212 return "vector_math_round";
214 return "vector_math_floor";
216 return "vector_math_ceil";
218 return "vector_math_modulo";
220 return "vector_math_fraction";
222 return "vector_math_absolute";
224 return "vector_math_minimum";
226 return "vector_math_maximum";
228 return "vector_math_wrap";
230 return "vector_math_sine";
232 return "vector_math_cosine";
234 return "vector_math_tangent";
236 return "vector_math_refract";
238 return "vector_math_faceforward";
240 return "vector_math_multiply_add";
242 return "vector_math_power";
244 return "vector_math_sign";
257 if (
in[0].link !=
nullptr &&
in[0].link ==
in[1].link) {
258 switch (
node->custom1) {
269 if (name !=
nullptr) {
347 VectorElem output_elem;
348 output_elem.merge(params.
get_input_elem<VectorElem>(
"Vector"_ustr));
349 output_elem.merge(params.
get_input_elem<VectorElem>(
"Vector_001"_ustr));
354 VectorElem output_elem;
355 output_elem.merge(params.
get_input_elem<VectorElem>(
"Vector"_ustr));
357 output_elem = VectorElem::all();
387 const UString first_input_id =
"Vector"_ustr;
388 const UString second_input_id =
"Vector_001"_ustr;
389 const UString scale_input_id =
"Scale"_ustr;
390 const UString output_vector_id =
"Vector"_ustr;
431 auto op = node_->custom1;
432 NodeItem res = empty();
433 const NodeItem null_vec = val(MaterialX::Vector3(0.0f));
436 NodeItem
x = get_input_value(0, NodeItem::Type::Vector3);
452 res = (
x + val(0.5f)).
floor();
468 res =
length.if_else(NodeItem::CompareOp::Eq, val(0.0f), null_vec,
x /
length);
474 NodeItem
y = get_input_value(1, NodeItem::Type::Vector3);
475 NodeItem
w = get_input_value(3, NodeItem::Type::Float);
503 res = create_node(
"crossproduct", NodeItem::Type::Vector3, {{
"in1",
x}, {
"in2",
y}});
506 res =
x.dotproduct(
y);
509 NodeItem len_sq =
y.dotproduct(
y);
510 res = len_sq.if_else(
511 NodeItem::CompareOp::NotEq, val(0.0f), (
x.dotproduct(
y) / len_sq) *
y, null_vec);
516 res =
x - val(2.0f) *
y.dotproduct(
x) *
y;
527 NodeItem
z = get_input_value(2, NodeItem::Type::Vector3);
535 NodeItem dot_yx =
y.dotproduct(
x);
536 NodeItem k = val(1.0f) - (
w *
w * (val(1.0f) - (dot_yx * dot_yx)));
537 NodeItem r =
w *
x - ((
w * dot_yx + k.sqrt()) *
y);
538 res = k.if_else(NodeItem::CompareOp::GreaterEq, val(0.0f), r, null_vec);
542 res =
z.dotproduct(
y).if_else(NodeItem::CompareOp::GreaterEq, val(0.0f), -
x,
x);
546 NodeItem range = (
y -
z);
547 NodeItem if_branch =
x - (range * ((
x -
z) / range).floor());
549 res = create_node(
"combine3", NodeItem::Type::Vector3);
550 std::vector<std::string> inputs = {
"in1",
"in2",
"in3"};
552 for (
size_t i = 0; i < inputs.size(); ++i) {
555 range[i].if_else(NodeItem::CompareOp::NotEq, val(0.0f), if_branch[i],
z[i]));
585 ntype.
declare = file_ns::sh_node_vector_math_declare;
586 ntype.
draw_buttons = file_ns::node_shader_buts_vect_math;
588 ntype.
gpu_fn = file_ns::gpu_shader_vector_math;
589 ntype.
updatefunc = file_ns::node_shader_update_vector_math;
593 ntype.
eval_elem = file_ns::node_eval_elem;
#define NODE_CLASS_OP_VECTOR
#define SH_NODE_VECTOR_MATH
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
#define BLI_assert_unreachable()
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.
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeTree & node_tree() const
const bNodeSocket & other_socket() const
eNodeSocketInOut in_out() const
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
void set_matching_fn(const mf::MultiFunction *fn)
std::unique_ptr< CustomSocketLabelFn > label_fn
T get_output(const UString identifier) const
void set_input(const UString identifier, T value)
T get_input(const UString identifier) const
NodeVectorMathOperation mode
void operator()(LinkSearchOpParams ¶ms)
T get_input_elem(const UString identifier) const
void set_output_elem(const UString identifier, T elem)
T get_output_elem(const UString identifier) const
void set_input_elem(const UString identifier, T elem)
float length(VecOp< float, D >) RET
void node_register_type(bNodeType &ntype)
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
const MultiFunction & lookup(UString id)
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 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_shader_buts_vect_math(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_eval_inverse_elem(value_elem::InverseElemEvalParams ¶ms)
static void vector_math_input_defaults(bNode &node, const NodeVectorMathOperation mode)
const FloatMathOperationInfo * get_float3_math_operation_info(const int operation)
@ ITEM_R_SPLIT_EMPTY_NAME
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void node_vector_math_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void register_node_type_sh_vect_math()
const EnumPropertyItem rna_enum_node_vec_math_items[]
@ NODE_VECTOR_MATH_COSINE
@ NODE_VECTOR_MATH_MAXIMUM
@ NODE_VECTOR_MATH_MINIMUM
@ NODE_VECTOR_MATH_MULTIPLY_ADD
@ NODE_VECTOR_MATH_REFLECT
@ NODE_VECTOR_MATH_TANGENT
@ NODE_VECTOR_MATH_PROJECT
@ NODE_VECTOR_MATH_CROSS_PRODUCT
@ NODE_VECTOR_MATH_DIVIDE
@ NODE_VECTOR_MATH_NORMALIZE
@ NODE_VECTOR_MATH_SUBTRACT
@ NODE_VECTOR_MATH_DOT_PRODUCT
@ NODE_VECTOR_MATH_DISTANCE
@ NODE_VECTOR_MATH_LENGTH
@ NODE_VECTOR_MATH_MODULO
@ NODE_VECTOR_MATH_FRACTION
@ NODE_VECTOR_MATH_FACEFORWARD
@ NODE_VECTOR_MATH_REFRACT
@ NODE_VECTOR_MATH_MULTIPLY
@ NODE_VECTOR_MATH_ABSOLUTE
VecBase< float, 3 > float3
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
bke::bNodeTreeType * typeinfo
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
NodeInverseElemEvalFunction eval_inverse_elem
NodeMaterialXFunction materialx_fn
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
NodeInverseEvalFunction eval_inverse
std::string ui_description
void(*) updatefunc(bNodeTree *ntree, bNode *node)
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
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
UString multi_function_name
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)