31 b.use_custom_socket_order();
32 b.allow_any_socket_order();
34 b.add_input<
decl::Color>(
"Image").default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
35 b.add_output<
decl::Color>(
"Image").align_with_previous();
38 b.add_input<
decl::Color>(
"Key Color").default_value({1.0f, 1.0f, 1.0f, 1.0f});
45 "If the difference in hue between the color and key color is less than this threshold, "
53 "If the difference in saturation between the color and key color is less than this "
54 "threshold, it is keyed");
61 "If the difference in value between the color and key color is less than this "
62 "threshold, it is keyed");
78 const float hue_threshold,
79 const float saturation_epsilon,
80 const float value_epsilon,
90 float hue_epsilon = hue_threshold / 2.0f;
92 bool is_within_saturation =
math::distance(color_hsva.y, key_hsva.y) < saturation_epsilon;
93 bool is_within_value =
math::distance(color_hsva.z, key_hsva.z) < value_epsilon;
94 bool is_within_hue =
math::distance(color_hsva.x, key_hsva.x) < hue_epsilon;
96 float min_hue =
math::min(color_hsva.x, key_hsva.x);
97 float max_hue =
math::max(color_hsva.x, key_hsva.x);
98 is_within_hue = is_within_hue || ((min_hue + (1.0f - max_hue)) < hue_epsilon);
100 matte = (is_within_hue && is_within_saturation && is_within_value) ? 0.0f :
color.w;
107 return mf::build::SI5_SO2<float4, float4, float, float, float, float4, float>(
112 const float &saturation,
115 float &matte) ->
void {
118 mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
132 ntype.
ui_description =
"Create matte using a given color, for green or blue screen footage";
135 ntype.
declare = file_ns::cmp_node_color_matte_declare;
137 ntype.
gpu_fn = file_ns::node_gpu_material;
constexpr int NODE_DEFAULT_MAX_WIDTH
#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_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
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