Blender V4.5
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
8
9#include "BLI_math_base.hh"
10#include "BLI_string_utf8.h"
11
12#include "DNA_mask_types.h"
13
14#include "UI_interface.hh"
15#include "UI_resources.hh"
16
17#include "COM_cached_mask.hh"
18#include "COM_node_operation.hh"
19
21
22/* **************** Mask ******************** */
23
25
27{
28 b.use_custom_socket_order();
29
30 b.add_output<decl::Float>("Mask");
31
32 b.add_layout([](uiLayout *layout, bContext *C, PointerRNA *ptr) {
33 uiTemplateID(layout, C, ptr, "mask", nullptr, nullptr, nullptr);
34 layout->prop(ptr, "size_source", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
35 });
36
37 b.add_input<decl::Int>("Size X")
38 .default_value(256)
39 .min(1)
40 .description("The resolution of the mask along the X direction")
41 .compositor_expects_single_value();
42 b.add_input<decl::Int>("Size Y")
43 .default_value(256)
44 .min(1)
45 .description("The resolution of the mask along the Y direction")
46 .compositor_expects_single_value();
47 b.add_input<decl::Bool>("Feather")
48 .default_value(true)
49 .description("Use feather information from the mask")
50 .compositor_expects_single_value();
51
52 PanelDeclarationBuilder &motion_blur_panel = b.add_panel("Motion Blur").default_closed(true);
53 motion_blur_panel.add_input<decl::Bool>("Motion Blur")
54 .default_value(false)
55 .panel_toggle()
56 .description("Use multi-sampled motion blur of the mask")
57 .compositor_expects_single_value();
58 motion_blur_panel.add_input<decl::Int>("Samples", "Motion Blur Samples")
59 .default_value(16)
60 .min(1)
61 .max(64)
62 .description("Number of motion blur samples")
63 .compositor_expects_single_value();
64 motion_blur_panel.add_input<decl::Float>("Shutter", "Motion Blur Shutter")
65 .default_value(0.5f)
67 .min(0.0f)
68 .max(1.0f)
69 .description("Exposure for motion blur as a factor of FPS")
70 .compositor_expects_single_value();
71}
72
73static void node_mask_label(const bNodeTree * /*ntree*/,
74 const bNode *node,
75 char *label,
76 int label_maxncpy)
77{
78 BLI_strncpy_utf8(label, node->id ? node->id->name + 2 : IFACE_("Mask"), label_maxncpy);
79}
80
81static void node_update(bNodeTree *ntree, bNode *node)
82{
83 const bool is_size_needed = node->custom1 & (CMP_NODE_MASK_FLAG_SIZE_FIXED |
85 bNodeSocket *size_x_input = bke::node_find_socket(*node, SOCK_IN, "Size X");
86 bNodeSocket *size_y_input = bke::node_find_socket(*node, SOCK_IN, "Size Y");
87 blender::bke::node_set_socket_availability(*ntree, *size_x_input, is_size_needed);
88 blender::bke::node_set_socket_availability(*ntree, *size_y_input, is_size_needed);
89}
90
91using namespace blender::compositor;
92
94 public:
96
97 void execute() override
98 {
99 Result &output_mask = this->get_result("Mask");
100 if (!this->get_mask() ||
101 (!this->is_fixed_size() && !this->context().is_valid_compositing_region()))
102 {
103 output_mask.allocate_invalid();
104 return;
105 }
106
107 const Domain domain = compute_domain();
108 Result &cached_mask = context().cache_manager().cached_masks.get(
109 this->context(),
110 this->get_mask(),
111 domain.size,
112 this->get_aspect_ratio(),
113 this->get_use_feather(),
114 this->get_motion_blur_samples(),
115 this->get_motion_blur_shutter());
116
117 output_mask.wrap_external(cached_mask);
118 }
119
121 {
122 return Domain(this->compute_size());
123 }
124
126 {
128 return this->get_size();
129 }
130
132 return this->get_size() * this->context().get_render_percentage();
133 }
134
135 return this->context().get_compositing_region_size();
136 }
137
139 {
140 return int2(math::max(1, this->get_input("Size X").get_single_value_default(256)),
141 math::max(1, this->get_input("Size Y").get_single_value_default(256)));
142 }
143
145 {
146 if (this->is_fixed_size()) {
147 return 1.0f;
148 }
149
150 return this->context().get_render_data().yasp / this->context().get_render_data().xasp;
151 }
152
158
160 {
161 return this->get_input("Feather").get_single_value_default(true);
162 }
163
165 {
166 const int samples = math::clamp(
167 this->get_input("Motion Blur Samples").get_single_value_default(16), 1, 64);
168 return this->use_motion_blur() ? samples : 1;
169 }
170
172 {
173 return math::clamp(
174 this->get_input("Motion Blur Shutter").get_single_value_default(0.5f), 0.0f, 1.0f);
175 }
176
178 {
179 return this->get_input("Motion Blur").get_single_value_default(false);
180 }
181
183 {
184 return static_cast<CMPNodeMaskFlags>(this->bnode().custom1);
185 }
186
188 {
189 return reinterpret_cast<Mask *>(this->bnode().id);
190 }
191};
192
194{
195 return new MaskOperation(context, node);
196}
197
198} // namespace blender::nodes::node_composite_mask_cc
199
201{
202 namespace file_ns = blender::nodes::node_composite_mask_cc;
203
204 static blender::bke::bNodeType ntype;
205
206 cmp_node_type_base(&ntype, "CompositorNodeMask", CMP_NODE_MASK);
207 ntype.ui_name = "Mask";
208 ntype.ui_description = "Input mask from a mask datablock, created in the image editor";
209 ntype.enum_name_legacy = "MASK";
210 ntype.nclass = NODE_CLASS_INPUT;
211 ntype.declare = file_ns::cmp_node_mask_declare;
212 ntype.updatefunc = file_ns::node_update;
213 ntype.labelfunc = file_ns::node_mask_label;
214 ntype.get_compositor_operation = file_ns::get_compositor_operation;
215
217}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#define CMP_NODE_MASK
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define IFACE_(msgid)
CMPNodeMaskFlags
@ CMP_NODE_MASK_FLAG_SIZE_FIXED
@ CMP_NODE_MASK_FLAG_SIZE_FIXED_SCENE
@ SOCK_IN
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FACTOR
Definition RNA_types.hh:239
#define C
Definition RandGen.cpp:29
void uiTemplateID(uiLayout *layout, const bContext *C, PointerRNA *ptr, blender::StringRefNull propname, const char *newop, const char *openop, const char *unlinkop, int filter=UI_TEMPLATE_ID_FILTER_ALL, bool live_icon=false, std::optional< blender::StringRef > text=std::nullopt)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
Result & get(Context &context, Mask *mask, int2 size, float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter)
virtual const RenderData & get_render_data() const =0
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
T get_single_value_default(const T &default_value) const
void wrap_external(GPUTexture *texture)
Definition result.cc:448
DeclType::Builder & add_input(StringRef name, StringRef identifier="")
#define this
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
Definition node.cc:2864
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
Definition node.cc:5011
T clamp(const T &a, const T &min, const T &max)
T max(const T &a, const T &b)
static void node_update(bNodeTree *ntree, bNode *node)
static void cmp_node_mask_declare(NodeDeclarationBuilder &b)
static void node_mask_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
VecBase< int32_t, 2 > int2
static void register_node_type_cmp_mask()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
char name[66]
Definition DNA_ID.h:415
int16_t custom1
struct ID * id
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:336
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:258
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:269
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4227