Blender V4.3
node_composite_despeckle.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 "UI_interface.hh"
10#include "UI_resources.hh"
11
12#include "GPU_shader.hh"
13
14#include "COM_node_operation.hh"
15#include "COM_utilities.hh"
16
18
19/* **************** FILTER ******************** */
20
22
24{
25 b.add_input<decl::Float>("Fac")
26 .default_value(1.0f)
27 .min(0.0f)
28 .max(1.0f)
30 .compositor_domain_priority(1);
31 b.add_input<decl::Color>("Image")
32 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
33 .compositor_domain_priority(0);
34 b.add_output<decl::Color>("Image");
35}
36
37static void node_composit_init_despeckle(bNodeTree * /*ntree*/, bNode *node)
38{
39 node->custom3 = 0.5f;
40 node->custom4 = 0.5f;
41}
42
44{
46
47 col = uiLayoutColumn(layout, false);
48 uiItemR(col, ptr, "threshold", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
49 uiItemR(col, ptr, "threshold_neighbor", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
50}
51
52using namespace blender::realtime_compositor;
53
55 public:
57
58 void execute() override
59 {
60 const Result &input_image = get_input("Image");
61 /* Single value inputs can't be despeckled and are returned as is. */
62 if (input_image.is_single_value()) {
63 get_input("Image").pass_through(get_result("Image"));
64 return;
65 }
66
67 GPUShader *shader = context().get_shader("compositor_despeckle");
68 GPU_shader_bind(shader);
69
70 GPU_shader_uniform_1f(shader, "threshold", get_threshold());
71 GPU_shader_uniform_1f(shader, "neighbor_threshold", get_neighbor_threshold());
72
73 input_image.bind_as_texture(shader, "input_tx");
74
75 const Result &factor_image = get_input("Fac");
76 factor_image.bind_as_texture(shader, "factor_tx");
77
78 const Domain domain = compute_domain();
79 Result &output_image = get_result("Image");
80 output_image.allocate_texture(domain);
81 output_image.bind_as_image(shader, "output_img");
82
83 compute_dispatch_threads_at_least(shader, domain.size);
84
86 output_image.unbind_as_image();
87 input_image.unbind_as_texture();
88 factor_image.unbind_as_texture();
89 }
90
92 {
93 return bnode().custom3;
94 }
95
97 {
98 return bnode().custom4;
99 }
100};
101
103{
104 return new DespeckleOperation(context, node);
105}
106
107} // namespace blender::nodes::node_composite_despeckle_cc
108
110{
112
113 static blender::bke::bNodeType ntype;
114
115 cmp_node_type_base(&ntype, CMP_NODE_DESPECKLE, "Despeckle", NODE_CLASS_OP_FILTER);
116 ntype.declare = file_ns::cmp_node_despeckle_declare;
117 ntype.draw_buttons = file_ns::node_composit_buts_despeckle;
118 ntype.flag |= NODE_PREVIEW;
119 ntype.initfunc = file_ns::node_composit_init_despeckle;
120 ntype.get_compositor_operation = file_ns::get_compositor_operation;
121
123}
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:408
@ NODE_PREVIEW
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
@ PROP_FACTOR
Definition RNA_types.hh:154
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
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)
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 pass_through(Result &target)
Definition result.cc:289
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
uint col
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_composit_init_despeckle(bNodeTree *, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void cmp_node_despeckle_declare(NodeDeclarationBuilder &b)
static void node_composit_buts_despeckle(uiLayout *layout, bContext *, PointerRNA *ptr)
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_despeckle()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
float custom4
float custom3
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
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