31 b.add_input<
decl::Color>(
"Image").default_value({1.0f, 1.0f, 1.0f, 1.0f});
32 b.add_input<
decl::Color>(
"Key Color").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");
75 const float hue_threshold,
76 const float saturation_epsilon,
77 const float value_epsilon,
87 float hue_epsilon = hue_threshold / 2.0f;
89 bool is_within_saturation =
math::distance(color_hsva.y, key_hsva.y) < saturation_epsilon;
90 bool is_within_value =
math::distance(color_hsva.z, key_hsva.z) < value_epsilon;
91 bool is_within_hue =
math::distance(color_hsva.x, key_hsva.x) < hue_epsilon;
93 float min_hue =
math::min(color_hsva.x, key_hsva.x);
94 float max_hue =
math::max(color_hsva.x, key_hsva.x);
95 is_within_hue = is_within_hue || ((min_hue + (1.0f - max_hue)) < hue_epsilon);
97 matte = (is_within_hue && is_within_saturation && is_within_value) ? 0.0f :
color.w;
104 return mf::build::SI5_SO2<float4, float4, float, float, float, float4, float>(
109 const float &saturation,
112 float &matte) ->
void {
115 mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
129 ntype.
ui_description =
"Create matte using a given color, for green or blue screen footage";
132 ntype.
declare = file_ns::cmp_node_color_matte_declare;
134 ntype.
gpu_fn = file_ns::node_gpu_material;
#define CMP_NODE_COLOR_MATTE
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void construct_and_set_matching_fn_cb(Fn &&create_multi_function)
void node_register_type(bNodeType &ntype)
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_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void cmp_node_color_matte_declare(NodeDeclarationBuilder &b)
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)
VecBase< float, 4 > float4
VecBase< float, 3 > float3
static void register_node_type_cmp_color_matte()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static blender::bke::bNodeSocketTemplate outputs[]
static blender::bke::bNodeSocketTemplate inputs[]
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
NodeDeclareFunction declare