Blender
V4.5
source
blender
nodes
composite
nodes
node_composite_diff_matte.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2006 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
9
#include "
BLI_math_base.hh
"
10
#include "
BLI_math_vector.hh
"
11
#include "
BLI_math_vector_types.hh
"
12
13
#include "
FN_multi_function_builder.hh
"
14
15
#include "
NOD_multi_function.hh
"
16
17
#include "
UI_interface.hh
"
18
#include "
UI_resources.hh
"
19
20
#include "
GPU_material.hh
"
21
22
#include "
node_composite_util.hh
"
23
24
/* ******************* channel Difference Matte ********************************* */
25
26
namespace
blender::nodes::node_composite_diff_matte_cc
{
27
28
static
void
cmp_node_diff_matte_declare
(
NodeDeclarationBuilder
&
b
)
29
{
30
b
.add_input<
decl::Color
>(
"Image 1"
).default_value({1.0f, 1.0f, 1.0f, 1.0f});
31
b
.add_input<
decl::Color
>(
"Image 2"
).default_value({1.0f, 1.0f, 1.0f, 1.0f});
32
b
.add_input<
decl::Float
>(
"Tolerance"
)
33
.default_value(0.1f)
34
.
subtype
(
PROP_FACTOR
)
35
.min(0.0f)
36
.max(1.0f)
37
.description(
38
"If the average color difference between the two images is less than this threshold, "
39
"it is keyed"
);
40
b
.add_input<
decl::Float
>(
"Falloff"
)
41
.default_value(0.1f)
42
.
subtype
(
PROP_FACTOR
)
43
.min(0.0f)
44
.max(1.0f)
45
.description(
46
"If the average color difference between the two images is less than this threshold, "
47
"it is partially keyed, otherwise, it is not keyed"
);
48
49
b
.add_output<
decl::Color
>(
"Image"
);
50
b
.add_output<
decl::Float
>(
"Matte"
);
51
}
52
53
using namespace
blender::compositor
;
54
55
static
int
node_gpu_material
(
GPUMaterial
*
material
,
56
bNode
*
node
,
57
bNodeExecData
*
/*execdata*/
,
58
GPUNodeStack
*
inputs
,
59
GPUNodeStack
*
outputs
)
60
{
61
return
GPU_stack_link
(
material
,
node
,
"node_composite_difference_matte"
,
inputs
,
outputs
);
62
}
63
64
static
void
node_build_multi_function
(
blender::nodes::NodeMultiFunctionBuilder
&builder)
65
{
66
builder.
construct_and_set_matching_fn_cb
([=]() {
67
return
mf::build::SI4_SO2<float4, float4, float, float, float4, float>(
68
"Difference Key"
,
69
[=](
const
float4
&color,
70
const
float4
&
key
,
71
const
float
&tolerance,
72
const
float
&falloff,
73
float4
&
result
,
74
float
&matte) ->
void
{
75
float
difference =
math::dot
(
math::abs
(color -
key
).xyz(),
float3
(1.0f)) / 3.0f;
76
77
bool
is_opaque = difference > tolerance + falloff;
78
float
alpha = is_opaque ?
79
color.w :
80
math::safe_divide
(
math::max
(0.0f, difference - tolerance), falloff);
81
82
matte =
math::min
(alpha, color.w);
83
result
= color * matte;
84
},
85
mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
86
});
87
}
88
89
}
// namespace blender::nodes::node_composite_diff_matte_cc
90
91
static
void
register_node_type_cmp_diff_matte
()
92
{
93
namespace
file_ns =
blender::nodes::node_composite_diff_matte_cc
;
94
95
static
blender::bke::bNodeType
ntype;
96
97
cmp_node_type_base
(&ntype,
"CompositorNodeDiffMatte"
,
CMP_NODE_DIFF_MATTE
);
98
ntype.
ui_name
=
"Difference Key"
;
99
ntype.
ui_description
=
100
"Produce a matte that isolates foreground content by comparing it with a reference "
101
"background image"
;
102
ntype.
enum_name_legacy
=
"DIFF_MATTE"
;
103
ntype.
nclass
=
NODE_CLASS_MATTE
;
104
ntype.
declare
= file_ns::cmp_node_diff_matte_declare;
105
ntype.
flag
|=
NODE_PREVIEW
;
106
ntype.
gpu_fn
= file_ns::node_gpu_material;
107
ntype.
build_multi_function
= file_ns::node_build_multi_function;
108
109
blender::bke::node_register_type
(ntype);
110
}
111
NOD_REGISTER_NODE
(
register_node_type_cmp_diff_matte
)
NODE_CLASS_MATTE
#define NODE_CLASS_MATTE
Definition
BKE_node.hh:440
CMP_NODE_DIFF_MATTE
#define CMP_NODE_DIFF_MATTE
Definition
BKE_node_legacy_types.hh:183
result
double result
Definition
BLI_expr_pylike_eval_test.cc:351
BLI_math_base.hh
BLI_math_vector.hh
BLI_math_vector_types.hh
key
int key
Definition
BLI_set_test.cc:631
NODE_PREVIEW
@ NODE_PREVIEW
Definition
DNA_node_types.h:592
FN_multi_function_builder.hh
GPU_material.hh
GPU_stack_link
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Definition
gpu_node_graph.cc:825
NOD_multi_function.hh
NOD_REGISTER_NODE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Definition
NOD_register.hh:34
PROP_FACTOR
@ PROP_FACTOR
Definition
RNA_types.hh:239
UI_interface.hh
UI_resources.hh
blender::nodes::NodeDeclarationBuilder
Definition
NOD_node_declaration.hh:629
blender::nodes::NodeMultiFunctionBuilder
Definition
NOD_multi_function.hh:18
blender::nodes::NodeMultiFunctionBuilder::construct_and_set_matching_fn_cb
void construct_and_set_matching_fn_cb(Fn &&create_multi_function)
Definition
NOD_multi_function.hh:117
blender::nodes::decl::Color
Definition
NOD_socket_declarations.hh:133
blender::nodes::decl::Float
Definition
NOD_socket_declarations.hh:19
blender::nodes::decl::Float::subtype
PropertySubType subtype
Definition
NOD_socket_declarations.hh:26
b
b
Definition
compositor_morphological_distance_info.hh:24
node
OperationNode * node
Definition
deg_builder_cycle.cc:38
material
Material material
Definition
deg_eval_copy_on_write.cc:96
blender::bke::node_register_type
void node_register_type(bNodeType &ntype)
Definition
node.cc:2748
blender::compositor
Definition
BKE_node.hh:76
blender::math::safe_divide
T safe_divide(const T &a, const T &b)
Definition
BLI_math_base.hh:97
blender::math::dot
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
Definition
BLI_math_quaternion.hh:197
blender::math::min
T min(const T &a, const T &b)
Definition
BLI_math_base.hh:43
blender::math::max
T max(const T &a, const T &b)
Definition
BLI_math_base.hh:49
blender::math::abs
T abs(const T &a)
Definition
BLI_math_base.hh:33
blender::nodes::node_composite_diff_matte_cc
Definition
node_composite_diff_matte.cc:26
blender::nodes::node_composite_diff_matte_cc::node_build_multi_function
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
Definition
node_composite_diff_matte.cc:64
blender::nodes::node_composite_diff_matte_cc::cmp_node_diff_matte_declare
static void cmp_node_diff_matte_declare(NodeDeclarationBuilder &b)
Definition
node_composite_diff_matte.cc:28
blender::nodes::node_composite_diff_matte_cc::node_gpu_material
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
Definition
node_composite_diff_matte.cc:55
blender::float3
VecBase< float, 3 > float3
Definition
BLI_math_vector_types.hh:619
register_node_type_cmp_diff_matte
static void register_node_type_cmp_diff_matte()
Definition
node_composite_diff_matte.cc:91
cmp_node_type_base
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Definition
node_composite_util.cc:33
node_composite_util.hh
outputs
static blender::bke::bNodeSocketTemplate outputs[]
Definition
node_texture_at.cc:16
inputs
static blender::bke::bNodeSocketTemplate inputs[]
Definition
node_texture_at.cc:11
GPUMaterial
Definition
gpu/intern/gpu_material.cc:60
GPUNodeStack
Definition
GPU_material.hh:272
bNodeExecData
Definition
node_util.hh:19
bNode
Definition
DNA_node_types.h:415
blender::VecBase< float, 4 >
blender::bke::bNodeType
Defines a node type.
Definition
BKE_node.hh:226
blender::bke::bNodeType::ui_description
std::string ui_description
Definition
BKE_node.hh:232
blender::bke::bNodeType::ui_name
std::string ui_name
Definition
BKE_node.hh:231
blender::bke::bNodeType::gpu_fn
NodeGPUExecFunction gpu_fn
Definition
BKE_node.hh:330
blender::bke::bNodeType::build_multi_function
NodeMultiFunctionBuildFunction build_multi_function
Definition
BKE_node.hh:344
blender::bke::bNodeType::nclass
short nclass
Definition
BKE_node.hh:239
blender::bke::bNodeType::flag
short flag
Definition
BKE_node.hh:239
blender::bke::bNodeType::enum_name_legacy
const char * enum_name_legacy
Definition
BKE_node.hh:235
blender::bke::bNodeType::declare
NodeDeclareFunction declare
Definition
BKE_node.hh:355
Generated on Fri Apr 3 2026 06:33:18 for Blender by
doxygen
1.11.0