Blender V4.3
node_composite_filter.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
10
11#include "UI_interface.hh"
12#include "UI_resources.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
38{
39 uiItemR(layout, ptr, "filter_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
40}
41
42using namespace blender::realtime_compositor;
43
45 public:
47
48 void execute() override
49 {
51 GPU_shader_bind(shader);
52
54
55 const Result &input_image = get_input("Image");
56 input_image.bind_as_texture(shader, "input_tx");
57
58 const Result &factor = get_input("Fac");
59 factor.bind_as_texture(shader, "factor_tx");
60
61 const Domain domain = compute_domain();
62
63 Result &output_image = get_result("Image");
64 output_image.allocate_texture(domain);
65 output_image.bind_as_image(shader, "output_img");
66
67 compute_dispatch_threads_at_least(shader, domain.size);
68
69 input_image.unbind_as_texture();
70 factor.unbind_as_texture();
71 output_image.unbind_as_image();
73 }
74
79
81 {
82 /* Initialize the kernels as arrays of rows with the top row first. Edge detection kernels
83 * return the kernel in the X direction, while the kernel in the Y direction will be computed
84 * inside the shader by transposing the kernel in the X direction. */
85 switch (get_filter_method()) {
87 const float kernel[3][3] = {{1.0f / 16.0f, 2.0f / 16.0f, 1.0f / 16.0f},
88 {2.0f / 16.0f, 4.0f / 16.0f, 2.0f / 16.0f},
89 {1.0f / 16.0f, 2.0f / 16.0f, 1.0f / 16.0f}};
90 return float3x3(kernel);
91 }
93 const float kernel[3][3] = {
94 {-1.0f, -1.0f, -1.0f}, {-1.0f, 9.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}};
95 return float3x3(kernel);
96 }
98 const float kernel[3][3] = {{-1.0f / 8.0f, -1.0f / 8.0f, -1.0f / 8.0f},
99 {-1.0f / 8.0f, 1.0f, -1.0f / 8.0f},
100 {-1.0f / 8.0f, -1.0f / 8.0f, -1.0f / 8.0f}};
101 return float3x3(kernel);
102 }
104 const float kernel[3][3] = {{1.0f, 0.0f, -1.0f}, {2.0f, 0.0f, -2.0f}, {1.0f, 0.0f, -1.0f}};
105 return float3x3(kernel);
106 }
108 const float kernel[3][3] = {{1.0f, 0.0f, -1.0f}, {1.0f, 0.0f, -1.0f}, {1.0f, 0.0f, -1.0f}};
109 return float3x3(kernel);
110 }
112 const float kernel[3][3] = {
113 {5.0f, -3.0f, -2.0f}, {5.0f, -3.0f, -2.0f}, {5.0f, -3.0f, -2.0f}};
114 return float3x3(kernel);
115 }
117 const float kernel[3][3] = {{1.0f, 2.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {-1.0f, -2.0f, -1.0f}};
118 return float3x3(kernel);
119 }
121 const float kernel[3][3] = {
122 {0.0f, -1.0f, 0.0f}, {-1.0f, 5.0f, -1.0f}, {0.0f, -1.0f, 0.0f}};
123 return float3x3(kernel);
124 }
125 default: {
126 const float kernel[3][3] = {{0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
127 return float3x3(kernel);
128 }
129 }
130 }
131
132 const char *get_shader_name()
133 {
134 switch (get_filter_method()) {
139 return "compositor_edge_filter";
144 default:
145 return "compositor_filter";
146 }
147 }
148};
149
151{
152 return new FilterOperation(context, node);
153}
154
155} // namespace blender::nodes::node_composite_filter_cc
156
158{
160
161 static blender::bke::bNodeType ntype;
162
163 cmp_node_type_base(&ntype, CMP_NODE_FILTER, "Filter", NODE_CLASS_OP_FILTER);
164 ntype.declare = file_ns::cmp_node_filter_declare;
165 ntype.draw_buttons = file_ns::node_composit_buts_filter;
167 ntype.flag |= NODE_PREVIEW;
168 ntype.get_compositor_operation = file_ns::get_compositor_operation;
169
171}
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:408
@ NODE_PREVIEW
CMPNodeFilterMethod
@ CMP_NODE_FILTER_PREWITT
@ CMP_NODE_FILTER_SHARP_BOX
@ CMP_NODE_FILTER_KIRSCH
@ CMP_NODE_FILTER_LAPLACE
@ CMP_NODE_FILTER_SHARP_DIAMOND
@ CMP_NODE_FILTER_SOFT
@ CMP_NODE_FILTER_SOBEL
@ CMP_NODE_FILTER_SHADOW
void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3])
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
@ PROP_FACTOR
Definition RNA_types.hh:154
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 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
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_buts_filter(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_filter_declare(NodeDeclarationBuilder &b)
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:131
MatBase< float, 3, 3 > float3x3
void register_node_type_cmp_filter()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_filter_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
Definition node_util.cc:229
int16_t custom1
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
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