Blender V4.3
node_composite_id_mask.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 <cmath>
10
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
14#include "GPU_shader.hh"
15
16#include "COM_algorithm_smaa.hh"
17#include "COM_node_operation.hh"
18#include "COM_utilities.hh"
19
21
22/* **************** ID Mask ******************** */
23
25
27{
28 b.add_input<decl::Float>("ID value")
29 .default_value(1.0f)
30 .min(0.0f)
31 .max(1.0f)
33 b.add_output<decl::Float>("Alpha");
34}
35
37{
38 uiItemR(layout, ptr, "index", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
39 uiItemR(layout, ptr, "use_antialiasing", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
40}
41
42using namespace blender::realtime_compositor;
43
45 public:
47
48 void execute() override
49 {
50 const Result &input_mask = get_input("ID value");
51 if (input_mask.is_single_value()) {
53 return;
54 }
55
56 GPUShader *shader = context().get_shader("compositor_id_mask");
57 GPU_shader_bind(shader);
58
59 GPU_shader_uniform_1i(shader, "index", get_index());
60
61 input_mask.bind_as_texture(shader, "input_mask_tx");
62
63 /* If anti-aliasing is disabled, write to the output directly, otherwise, write to a temporary
64 * result to later perform anti-aliasing. */
65 Result non_anti_aliased_mask = context().create_result(ResultType::Float);
66 Result &output_mask = use_anti_aliasing() ? non_anti_aliased_mask : get_result("Alpha");
67
68 const Domain domain = compute_domain();
69 output_mask.allocate_texture(domain);
70 output_mask.bind_as_image(shader, "output_mask_img");
71
72 compute_dispatch_threads_at_least(shader, domain.size);
73
74 input_mask.unbind_as_texture();
75 output_mask.unbind_as_image();
77
78 if (use_anti_aliasing()) {
79 smaa(context(), non_anti_aliased_mask, get_result("Alpha"));
80 non_anti_aliased_mask.release();
81 }
82 }
83
85 {
86 const float input_mask_value = get_input("ID value").get_float_value();
87 const float mask = int(round(input_mask_value)) == get_index() ? 1.0f : 0.0f;
89 get_result("Alpha").set_float_value(mask);
90 }
91
93 {
94 return bnode().custom1;
95 }
96
98 {
99 return bnode().custom2 != 0;
100 }
101};
102
104{
105 return new IDMaskOperation(context, node);
106}
107
108} // namespace blender::nodes::node_composite_id_mask_cc
109
111{
113
114 static blender::bke::bNodeType ntype;
115
116 cmp_node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTER);
117 ntype.declare = file_ns::cmp_node_idmask_declare;
118 ntype.draw_buttons = file_ns::node_composit_buts_id_mask;
119 ntype.get_compositor_operation = file_ns::get_compositor_operation;
120
122}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
struct GPUShader GPUShader
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
Result create_result(ResultType type, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
Result & get_input(StringRef identifier) const
Definition operation.cc:144
Result & get_result(StringRef identifier)
Definition operation.cc:46
void bind_as_image(GPUShader *shader, const char *image_name, bool read=false) const
Definition result.cc:264
void set_float_value(float value)
Definition result.cc:467
void allocate_texture(Domain domain, bool from_pool=true)
Definition result.cc:204
void bind_as_texture(GPUShader *shader, const char *texture_name) const
Definition result.cc:253
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_buts_id_mask(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_idmask_declare(NodeDeclarationBuilder &b)
void smaa(Context &context, Result &input, Result &output, float threshold=0.1f, float local_contrast_adaptation_factor=2.0f, int corner_rounding=25)
Definition smaa.cc:160
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:131
void register_node_type_cmp_idmask()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126