25 {0,
nullptr, 0,
nullptr,
nullptr},
30 b.use_custom_socket_order();
31 b.allow_any_socket_order();
33 b.add_input<
decl::Color>(
"Image"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
34 b.add_output<
decl::Color>(
"Image"_ustr).align_with_previous();
37 b.add_input<
decl::Color>(
"Key Color"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
49 "If the distance between the color and the key color in the given color space is less "
50 "than this threshold, it is keyed");
57 "If the distance between the color and the key color in the given color space is less "
58 "than this threshold, it is partially keyed, otherwise, it is not keyed");
64 node->storage = MEM_new<NodeChroma>(__func__);
75 return GPU_stack_link(material,
node,
"node_composite_distance_matte", inputs, outputs);
81 const float tolerance,
88 switch (color_space) {
101 color_vector /= 255.0f;
103 key.x, key.y, key.z, &key_vector.x, &key_vector.y, &key_vector.z,
BLI_YCC_ITU_BT709);
104 key_vector /= 255.0f;
108 float difference =
math::distance(color_vector.xyz(), key_vector.xyz());
109 bool is_opaque = difference > tolerance + falloff;
110 float alpha = is_opaque ?
color.w :
120 static auto function = mf::build::SI5_SO2<Color, Color, MenuValue, float, float, Color, float>(
123 const Color &key_color,
125 const float &tolerance,
126 const float &falloff,
128 float &matte) ->
void {
137 output_color =
Color(out_color);
139 mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
148 ntype.
ui_name =
"Distance Key";
149 ntype.
ui_description =
"Create matte based on 3D distance between colors";
#define CMP_NODE_DIST_MATTE
#define BLI_YCC_ITU_BT709
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
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))
ColorSceneLinear4f< eAlpha::Premultiplied > Color
T safe_divide(const T &a, const T &b)
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 int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
static const EnumPropertyItem color_space_items[]
static void distance_key(const float4 color, const float4 key, const CMPNodeDistanceMatteColorSpace color_space, const float tolerance, const float falloff, float4 &result, float &matte)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static void node_init(bNodeTree *, bNode *node)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
CMPNodeDistanceMatteColorSpace
@ CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_YCCA
@ CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_RGBA
void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
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
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare