Blender V4.3
node_composite_pixelate.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 "GPU_shader.hh"
10
11#include "COM_node_operation.hh"
12#include "COM_utilities.hh"
13
14#include "UI_interface.hh"
15#include "UI_resources.hh"
16
18
19/* **************** Pixelate ******************** */
20
22
24{
25 b.add_input<decl::Color>("Color").compositor_domain_priority(0);
26 b.add_output<decl::Color>("Color");
27}
28
29static void node_composit_init_pixelate(bNodeTree * /*ntree*/, bNode *node)
30{
31 node->custom1 = 1;
32}
33
35{
36 uiItemR(layout, ptr, "pixel_size", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
37}
38
39using namespace blender::realtime_compositor;
40
42 public:
44
45 void execute() override
46 {
47 Result &input_image = get_input("Color");
48 Result &output_image = get_result("Color");
49 const int pixel_size = get_pixel_size();
50 if (input_image.is_single_value() || pixel_size == 1) {
51 input_image.pass_through(output_image);
52 return;
53 }
54
55 GPUShader *shader = context().get_shader("compositor_pixelate");
56 GPU_shader_bind(shader);
57
58 GPU_shader_uniform_1i(shader, "pixel_size", pixel_size);
59
60 input_image.bind_as_texture(shader, "input_tx");
61
62 const Domain domain = compute_domain();
63 output_image.allocate_texture(domain);
64 output_image.bind_as_image(shader, "output_img");
65
66 compute_dispatch_threads_at_least(shader, domain.size);
67
69 output_image.unbind_as_image();
70 input_image.unbind_as_texture();
71 }
72
74 {
75 return bnode().custom1;
76 }
77};
78
80{
81 return new PixelateOperation(context, node);
82}
83
84} // namespace blender::nodes::node_composite_pixelate_cc
85
87{
89
90 static blender::bke::bNodeType ntype;
91
92 cmp_node_type_base(&ntype, CMP_NODE_PIXELATE, "Pixelate", NODE_CLASS_OP_FILTER);
93 ntype.declare = file_ns::cmp_node_pixelate_declare;
94 ntype.draw_buttons = file_ns::node_composit_buts_pixelate;
95 ntype.initfunc = file_ns::node_composit_init_pixelate;
96 ntype.get_compositor_operation = file_ns::get_compositor_operation;
97
99}
#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_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)
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
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void cmp_node_pixelate_declare(NodeDeclarationBuilder &b)
static void node_composit_buts_pixelate(uiLayout *layout, bContext *, PointerRNA *ptr)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_init_pixelate(bNodeTree *, bNode *node)
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_pixelate()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
int16_t custom1
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