45 b.add_input<
decl::Float>(
"Factor"_ustr,
"Factor_Float"_ustr)
51 .description(
"Amount of mixing between the A and B inputs")
52 .compositor_domain_priority(2);
53 b.add_input<
decl::Vector>(
"Factor"_ustr,
"Factor_Vector"_ustr)
59 .description(
"Amount of mixing between the A and B vector inputs")
60 .compositor_domain_priority(2);
65 .is_default_link_socket()
67 .description(
"Value of the first floating number input")
68 .compositor_domain_priority(0);
73 .description(
"Value of the second floating number input")
74 .compositor_domain_priority(1);
79 .description(
"Value of the first vector input")
80 .compositor_domain_priority(0);
83 .description(
"Value of the second vector input")
84 .compositor_domain_priority(1);
88 .is_default_link_socket()
90 .description(
"Value of the first color input")
91 .compositor_domain_priority(0);
95 .description(
"Value of the second color input")
96 .compositor_domain_priority(1);
101 .compositor_domain_priority(0);
104 .compositor_domain_priority(1);
106 b.add_output<
decl::Float>(
"Result"_ustr,
"Result_Float"_ustr);
107 b.add_output<
decl::Vector>(
"Result"_ustr,
"Result_Vector"_ustr);
108 b.add_output<
decl::Color>(
"Result"_ustr,
"Result_Color"_ustr);
116 switch (
data.data_type) {
175 bool use_vector_factor = data_type ==
SOCK_VECTOR &&
182 for (
bNodeSocket *socket = sock_factor_vec->
next; socket !=
nullptr; socket = socket->
next) {
199 node_storage(
node).blend_type =
type;
231 node_storage(
node).data_type = type;
240 node_storage(
node).data_type = type;
249 node_storage(
node).data_type = type;
256 IFACE_(
"Factor (Non-Uniform)"),
271 node_storage(
node).data_type = type;
290 if (item->name !=
nullptr && item->identifier[0] !=
'\0') {
301 data->clamp_factor = 1;
302 data->clamp_result = 0;
308 const bool non_uniform,
309 const int blend_type)
313 return "node_mix_float";
315 return (non_uniform) ?
"node_mix_vector_non_uniform" :
"node_mix_vector";
317 switch (blend_type) {
319 return "node_mix_blend";
321 return "node_mix_add";
323 return "node_mix_mult";
325 return "node_mix_sub";
327 return "node_mix_screen";
329 return "node_mix_div_fallback";
331 return "node_mix_diff";
333 return "node_mix_exclusion";
335 return "node_mix_dark";
337 return "node_mix_light";
339 return "node_mix_overlay";
341 return "node_mix_dodge";
343 return "node_mix_burn";
345 return "node_mix_hue";
347 return "node_mix_sat";
349 return "node_mix_val";
351 return "node_mix_color";
353 return "node_mix_soft";
355 return "node_mix_linear";
361 return "node_mix_rotation";
378 const int blend_type =
storage.blend_type;
381 if (name ==
nullptr) {
386 if (is_non_uniform && is_vector_mode) {
387 const float min[3] = {0.0f, 0.0f, 0.0f};
388 const float max[3] = {1.0f, 1.0f, 1.0f};
391 "node_mix_clamp_vector",
398 const float min = 0.0f;
399 const float max = 1.0f;
402 "node_mix_clamp_value",
422 if (is_non_uniform) {
460 if (
ret && is_color_mode &&
storage.clamp_result) {
461 const float min[4] = {0.0f, 0.0f, 0.0f, 0.0f};
462 const float max[4] = {1.0f, 1.0f, 1.0f, 1.0f};
465 "node_mix_clamp_color",
476 const bool clamp_factor_;
477 const bool clamp_result_;
478 const int blend_type_;
482 : clamp_factor_(clamp_factor), clamp_result_(clamp_result), blend_type_(blend_type)
484 static const mf::Signature
signature = []() {
486 mf::SignatureBuilder builder{
"MixColor",
signature};
487 builder.single_input<
float>(
"Factor");
498 const VArray<float> &fac = params.readonly_single_input<
float>(0,
"Factor");
506 results[i] = col1[i];
507 ramp_blend(blend_type_, results[i], std::clamp(fac[i], 0.0f, 1.0f), col2[i]);
512 results[i] = col1[i];
513 ramp_blend(blend_type_, results[i], fac[i], col2[i]);
525 static constexpr int8_t id = 0;
527 hash.add(clamp_factor_);
528 hash.add(clamp_result_);
529 hash.add(blend_type_);
537 const bool clamp_factor =
data->clamp_factor;
538 switch (
data->data_type) {
541 static auto fn = mf::build::SI3_SO<float, float, float, float>(
542 "Clamp Mix Float", [](
float t,
const float a,
const float b) {
547 static auto fn = mf::build::SI3_SO<float, float, float, float>(
554 if (uniform_factor) {
555 static auto fn = mf::build::SI3_SO<float, float3, float3, float3>(
556 "Clamp Mix Vector", [](
const float t,
const float3 a,
const float3 b) {
561 static auto fn = mf::build::SI3_SO<float3, float3, float3, float3>(
564 return a * (
float3(1.0f) - t) +
b * t;
568 if (uniform_factor) {
569 static auto fn = mf::build::SI3_SO<float, float3, float3, float3>(
570 "Mix Vector", [](
const float t,
const float3 a,
const float3 b) {
575 static auto fn = mf::build::SI3_SO<float3, float3, float3, float3>(
577 return a * (
float3(1.0f) - t) +
b * t;
584 mf::build::SI3_SO<float, math::Quaternion, math::Quaternion, math::Quaternion>(
585 "Clamp Mix Rotation",
592 mf::build::SI3_SO<float, math::Quaternion, math::Quaternion, math::Quaternion>(
625 NodeItem factor = empty();
626 NodeItem value1 = empty();
627 NodeItem value2 = empty();
628 switch (
data->data_type) {
630 factor = get_input_value(0, NodeItem::Type::Float);
631 value1 = get_input_value(2, NodeItem::Type::Float);
632 value2 = get_input_value(3, NodeItem::Type::Float);
637 factor = get_input_value(0, NodeItem::Type::Float);
640 factor = get_input_value(1, NodeItem::Type::Vector3);
642 value1 = get_input_value(4, NodeItem::Type::Vector3);
643 value2 = get_input_value(5, NodeItem::Type::Vector3);
647 factor = get_input_value(0, NodeItem::Type::Float);
648 value1 = get_input_value(6, NodeItem::Type::Color3);
649 value2 = get_input_value(7, NodeItem::Type::Color3);
656 if (
data->clamp_factor) {
657 factor = factor.clamp();
659 NodeItem res = factor.mix(value1, value2);
663 if (
data->clamp_result) {
684 ntype.
declare = file_ns::sh_node_mix_declare;
685 ntype.
ui_class = file_ns::sh_node_mix_ui_class;
686 ntype.
gpu_fn = file_ns::gpu_shader_mix;
687 ntype.
updatefunc = file_ns::sh_node_mix_update;
688 ntype.
initfunc = file_ns::node_mix_init;
693 ntype.
labelfunc = file_ns::sh_node_mix_label;
General operations, lookup, etc. for materials.
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_OP_VECTOR
#define NODE_CLASS_OP_COLOR
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_COLOR
#define BLI_assert_unreachable()
const Signature & signature() const
void set_signature(const Signature *signature)
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
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)
void construct_and_set_matching_fn(Args &&...args)
bool is_default_link_socket
std::optional< std::string > translation_context
ColorGeometry4f default_value
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
void hash_unique(UniqueHashBytes &hash) const override
MixColorFunction(const bool clamp_factor, const bool clamp_result, const int blend_type)
void operator()(LinkSearchOpParams ¶ms)
#define storage(slot, qualifiers)
void node_register_type(bNodeType &ntype)
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
QuaternionBase< float > Quaternion
T clamp(const T &a, const T &min, const T &max)
T interpolate(const T &a, const T &b, const FactorT &t)
static const char * gpu_shader_get_name(eNodeSocketDatatype data_type, const bool non_uniform, const int blend_type)
static void node_mix_init(bNodeTree *, bNode *node)
static int sh_node_mix_ui_class(const bNode *node)
static void node_mix_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void sh_node_mix_build_multi_function(NodeMultiFunctionBuilder &builder)
static const mf::MultiFunction * get_multi_function(const bNode &node)
static int gpu_shader_mix(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void sh_node_mix_declare(NodeDeclarationBuilder &b)
static void sh_node_mix_update(bNodeTree *ntree, bNode *node)
static void sh_node_mix_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
static void sh_node_mix_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
void ramp_blend(int type, float r_col[4], float fac, const float col[4])
const EnumPropertyItem rna_enum_ramp_blend_items[]
GPUNodeLink * GPU_node_get_input_link(const bNode &node, GPUNodeStack inputs[], StringRef identifier)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
GPUNodeLink * GPU_uniform(const float *num)
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
BMesh const char void * data
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
GPUNodeStack & GPU_node_get_output(const bNode &node, GPUNodeStack outputs[], StringRef identifier)
MINLINE void clamp_v4(float vec[4], float min, float max)
void register_node_type_sh_mix()
@ NODE_MIX_MODE_NON_UNIFORM
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void node_free_standard_storage(bNode *node)
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
struct bNodeSocket * next
NodeMaterialXFunction materialx_fn
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
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
NodeMultiFunctionBuildFunction build_multi_function
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
int(*) ui_class(const bNode *node)
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)