Blender V5.3
node_composite_mask.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_math_base.hh"
6#include "BLI_string_utf8.hh"
7
8#include "DNA_mask_types.h"
9
10#include "UI_interface.hh"
12
13#include "COM_cached_mask.hh"
14#include "COM_node_operation.hh"
15
17
19
21 {0, "SCENE", 0, "Scene Size", ""},
22 {CMP_NODE_MASK_FLAG_SIZE_FIXED, "FIXED", 0, N_("Fixed"), N_("Use pixel size for the buffer")},
24 "FIXED_SCENE",
25 0,
26 N_("Fixed/Scene"),
27 N_("Pixel size scaled by scene percentage")},
28 {0, nullptr, 0, nullptr, nullptr},
29};
30
32{
33 b.use_custom_socket_order();
34
35 b.add_output<decl::Float>("Mask"_ustr).structure_type(StructureType::Dynamic);
36
37 b.add_layout([](ui::Layout &layout, bContext *C, PointerRNA *ptr) {
38 template_id(&layout, C, ptr, "mask", "mask.new", nullptr, nullptr);
39 });
40
41 b.add_input<decl::Menu>("Size Source"_ustr)
42 .default_value(MenuValue(0))
43 .static_items(size_source_items)
45 .description("The source where the size of the mask is retrieved");
46 b.add_input<decl::Int>("Size X"_ustr)
47 .default_value(256)
49 .min(1)
50 .usage_by_menu("Size Source"_ustr,
52 .description("The resolution of the mask along the X direction");
53 b.add_input<decl::Int>("Size Y"_ustr)
54 .default_value(256)
56 .min(1)
57 .usage_by_menu("Size Source"_ustr,
59 .description("The resolution of the mask along the Y direction");
60 b.add_input<decl::Bool>("Feather"_ustr)
61 .default_value(true)
62 .description("Use feather information from the mask");
63
64 PanelDeclarationBuilder &motion_blur_panel =
65 b.add_panel("Motion Blur"_ustr).default_closed(true);
66 motion_blur_panel.add_input<decl::Bool>("Motion Blur"_ustr)
67 .default_value(false)
68 .panel_toggle()
69 .description("Use multi-sampled motion blur of the mask");
70 motion_blur_panel.add_input<decl::Int>("Samples"_ustr, "Motion Blur Samples"_ustr)
71 .default_value(16)
72 .min(1)
73 .max(64)
74 .description("Number of motion blur samples");
75 motion_blur_panel.add_input<decl::Float>("Shutter"_ustr, "Motion Blur Shutter"_ustr)
76 .default_value(0.5f)
78 .min(0.0f)
79 .max(1.0f)
80 .description("Exposure for motion blur as a factor of FPS");
81}
82
83static void node_label(const bNodeTree * /*ntree*/,
84 const bNode *node,
85 char *label,
86 int label_maxncpy)
87{
88 BLI_strncpy_utf8(label, node->id ? node->id->name + 2 : IFACE_("Mask"), label_maxncpy);
89}
90
91using namespace blender::compositor;
92
94 public:
96
97 void execute() override
98 {
99 if (!this->get_mask()) {
101 return;
102 }
103
104 const Domain domain = compute_domain();
105 Result &cached_mask = context().cache_manager().cached_masks.get(
106 this->context(),
107 this->get_mask(),
108 domain,
109 this->get_aspect_ratio(),
110 this->get_use_feather(),
111 this->context().get_frame_number(),
114 false);
115
116 Result &output_mask = this->get_result("Mask");
117 output_mask.share_data(cached_mask);
118 }
119
121 {
123 return Domain(this->get_size());
124 }
125
127 return Domain(this->get_size() * this->context().get_render_percentage());
128 }
129
130 return this->context().get_compositing_domain();
131 }
132
134 {
135 return int2(math::max(1, this->get_input("Size X").get_single_value_default<int>()),
136 math::max(1, this->get_input("Size Y").get_single_value_default<int>()));
137 }
138
140 {
141 if (this->is_fixed_size()) {
142 return 1.0f;
143 }
144
145 return this->context().get_render_data().yasp / this->context().get_render_data().xasp;
146 }
147
153
155 {
156 return this->get_input("Feather").get_single_value_default<bool>();
157 }
158
160 {
161 const int samples = math::clamp(
162 this->get_input("Motion Blur Samples").get_single_value_default<int>(), 1, 64);
163 return this->use_motion_blur() ? samples : 1;
164 }
165
167 {
168 return math::clamp(
169 this->get_input("Motion Blur Shutter").get_single_value_default<float>(), 0.0f, 1.0f);
170 }
171
173 {
174 return this->get_input("Motion Blur").get_single_value_default<bool>();
175 }
176
178 {
179 return CMPNodeMaskFlags(
180 this->get_input("Size Source").get_single_value_default<MenuValue>().value);
181 }
182
184 {
185 return reinterpret_cast<Mask *>(this->node().id);
186 }
187};
188
190{
191 return new MaskOperation(context, node);
192}
193
194static void node_register()
195{
196 static bke::bNodeType ntype;
197
198 cmp_node_type_base(&ntype, "CompositorNodeMask"_ustr, CMP_NODE_MASK);
199 ntype.ui_name = "Mask";
200 ntype.ui_description = "Input mask from a mask data-block, created in the image editor";
201 ntype.enum_name_legacy = "MASK";
202 ntype.nclass = NODE_CLASS_INPUT;
203 ntype.declare = node_declare;
204 ntype.labelfunc = node_label;
206
208}
210
211} // namespace blender::nodes::node_composite_mask_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define CMP_NODE_MASK
#define IFACE_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define C
Definition RandGen.cpp:29
Result & get(Context &context, Mask *mask, const Domain &domain, float aspect_ratio, bool use_feather, int frame, int motion_blur_samples, float motion_blur_shutter, bool srgb_to_linear)
virtual const RenderData & get_render_data() const
virtual Domain get_compositing_domain() const =0
Domain(const int2 &size)
Definition domain.cc:20
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
void share_data(const Result &source)
Definition result.cc:996
DeclType::Builder & add_input(UString name, UString identifier=""_ustr)
NodeOperation(Context &context, const bNode &node)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
T clamp(const T &a, const T &min, const T &max)
T max(const T &a, const T &b)
static void node_declare(NodeDeclarationBuilder &b)
static const EnumPropertyItem size_source_items[]
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
@ CMP_NODE_MASK_FLAG_SIZE_FIXED_SCENE
@ CMP_NODE_MASK_FLAG_SIZE_FIXED
@ PROP_FACTOR
Definition RNA_types.hh:308
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:301
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
#define N_(msgid)