Blender V4.3
node_composite_bilateralblur.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
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
14#include "GPU_shader.hh"
15
16#include "COM_node_operation.hh"
17#include "COM_utilities.hh"
18
20
21/* **************** BILATERALBLUR ******************** */
22
24
26
28{
29 b.add_input<decl::Color>("Image")
30 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
31 .compositor_domain_priority(0);
32 b.add_input<decl::Color>("Determinator")
33 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
34 .compositor_domain_priority(1);
35 b.add_output<decl::Color>("Image");
36}
37
38static void node_composit_init_bilateralblur(bNodeTree * /*ntree*/, bNode *node)
39{
40 NodeBilateralBlurData *nbbd = MEM_cnew<NodeBilateralBlurData>(__func__);
41 node->storage = nbbd;
42 nbbd->iter = 1;
43 nbbd->sigma_color = 0.3;
44 nbbd->sigma_space = 5.0;
45}
46
48{
50
51 col = uiLayoutColumn(layout, true);
52 uiItemR(col, ptr, "iterations", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
53 uiItemR(col, ptr, "sigma_color", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
54 uiItemR(col, ptr, "sigma_space", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
55}
56
57using namespace blender::realtime_compositor;
58
60 public:
62
63 void execute() override
64 {
65 const Result &input_image = get_input("Image");
66 /* Single value inputs can't be blurred and are returned as is. */
67 if (input_image.is_single_value()) {
68 get_input("Image").pass_through(get_result("Image"));
69 return;
70 }
71
72 GPUShader *shader = context().get_shader("compositor_bilateral_blur");
73 GPU_shader_bind(shader);
74
75 GPU_shader_uniform_1i(shader, "radius", get_blur_radius());
76 GPU_shader_uniform_1f(shader, "threshold", get_threshold());
77
78 input_image.bind_as_texture(shader, "input_tx");
79
80 const Result &determinator_image = get_input("Determinator");
81 determinator_image.bind_as_texture(shader, "determinator_tx");
82
83 const Domain domain = compute_domain();
84 Result &output_image = get_result("Image");
85 output_image.allocate_texture(domain);
86 output_image.bind_as_image(shader, "output_img");
87
88 compute_dispatch_threads_at_least(shader, domain.size);
89
91 output_image.unbind_as_image();
92 input_image.unbind_as_texture();
93 determinator_image.unbind_as_texture();
94 }
95
97 {
98 return math::ceil(node_storage(bnode()).iter + node_storage(bnode()).sigma_space);
99 }
100
102 {
103 return node_storage(bnode()).sigma_color;
104 }
105};
106
108{
109 return new BilateralBlurOperation(context, node);
110}
111
112} // namespace blender::nodes::node_composite_bilateralblur_cc
113
115{
117
118 static blender::bke::bNodeType ntype;
119
120 cmp_node_type_base(&ntype, CMP_NODE_BILATERALBLUR, "Bilateral Blur", NODE_CLASS_OP_FILTER);
121 ntype.declare = file_ns::cmp_node_bilateralblur_declare;
122 ntype.draw_buttons = file_ns::node_composit_buts_bilateralblur;
123 ntype.initfunc = file_ns::node_composit_init_bilateralblur;
125 &ntype, "NodeBilateralBlurData", node_free_standard_storage, node_copy_standard_storage);
126 ntype.get_compositor_operation = file_ns::get_compositor_operation;
127
129}
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:408
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
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_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
T ceil(const T &a)
static void node_composit_init_bilateralblur(bNodeTree *, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void cmp_node_bilateralblur_declare(NodeDeclarationBuilder &b)
static void node_composit_buts_bilateralblur(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_bilateralblur()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
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