25 b.use_custom_socket_order();
26 b.allow_any_socket_order();
28 b.add_input<
decl::Color>(
"Image"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
29 b.add_output<
decl::Color>(
"Image"_ustr).align_with_previous();
32 b.add_input<
decl::Color>(
"Key Color"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
39 "If the difference in hue between the color and key color is less than this threshold, "
47 "If the difference in saturation between the color and key color is less than this "
48 "threshold, it is keyed");
55 "If the difference in value between the color and key color is less than this "
56 "threshold, it is keyed")
73 const float hue_threshold,
74 const float saturation_epsilon,
75 const float value_epsilon,
85 float hue_epsilon = hue_threshold / 2.0f;
87 bool is_within_saturation =
math::distance(color_hsva.y, key_hsva.y) < saturation_epsilon;
88 bool is_within_value =
math::distance(color_hsva.z, key_hsva.z) < value_epsilon;
89 bool is_within_hue =
math::distance(color_hsva.x, key_hsva.x) < hue_epsilon;
91 float min_hue =
math::min(color_hsva.x, key_hsva.x);
92 float max_hue =
math::max(color_hsva.x, key_hsva.x);
93 is_within_hue = is_within_hue || ((min_hue + (1.0f - max_hue)) < hue_epsilon);
95 matte = (is_within_hue && is_within_saturation && is_within_value) ? 0.0f :
color.w;
104 return mf::build::SI5_SO2<Color, Color, float, float, float, Color, float>(
107 const Color &key_color,
109 const float &saturation,
112 float &matte) ->
void {
115 output_color =
Color(out_color);
117 mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
127 ntype.
ui_description =
"Create matte using a given color, for green or blue screen footage";
#define CMP_NODE_COLOR_MATTE
#define BLT_I18NCONTEXT_COLOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void construct_and_set_matching_fn_cb(Fn &&create_multi_function)
void node_register_type(bNodeType &ntype)
ColorSceneLinear4f< eAlpha::Premultiplied > Color
T distance(const T &a, const T &b)
T min(const T &a, const T &b)
T max(const T &a, const T &b)
static void node_declare(NodeDeclarationBuilder &b)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_register()
static void color_matte(const float4 color, const float4 key, const float hue_threshold, const float saturation_epsilon, const float value_epsilon, float4 &result, float &matte)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static constexpr int _160
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
NodeDeclareFunction declare