Blender V5.3
node_composite_flip.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
6
7#include "GPU_shader.hh"
8
10#include "COM_utilities.hh"
11
13
15
17{
18 b.use_custom_socket_order();
19 b.allow_any_socket_order();
20 b.add_input<decl::Color>("Image"_ustr)
21 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
22 .hide_value()
23 .structure_type(StructureType::Dynamic);
24 b.add_output<decl::Color>("Image"_ustr)
25 .structure_type(StructureType::Dynamic)
26 .align_with_previous();
27
28 b.add_input<decl::Bool>("Flip X"_ustr).default_value(false);
29 b.add_input<decl::Bool>("Flip Y"_ustr).default_value(false);
30}
31
32using namespace blender::compositor;
33
35 public:
37
38 void execute() override
39 {
40 const Result &input = this->get_input("Image");
41 if (input.is_single_value() || (!this->get_flip_x() && !this->get_flip_y())) {
42 Result &output = this->get_result("Image");
43 output.share_data(input);
44 return;
45 }
46
47 if (this->context().use_gpu()) {
48 this->execute_gpu();
49 }
50 else {
51 this->execute_cpu();
52 }
53 }
54
56 {
57 gpu::Shader *shader = context().get_shader("compositor_flip");
59
60 GPU_shader_uniform_1b(shader, "flip_x", this->get_flip_x());
61 GPU_shader_uniform_1b(shader, "flip_y", this->get_flip_y());
62
63 Result &input = get_input("Image");
64 input.bind_as_texture(shader, "input_tx");
65
66 const Domain domain = compute_domain();
67 Result &result = get_result("Image");
68 result.allocate_texture(domain);
69 result.bind_as_image(shader, "output_img");
70
72
73 input.unbind_as_texture();
74 result.unbind_as_image();
76 }
77
79 {
80 const bool flip_x = this->get_flip_x();
81 const bool flip_y = this->get_flip_y();
82
83 Result &input = get_input("Image");
84
85 const Domain domain = compute_domain();
86 Result &output = get_result("Image");
87 output.allocate_texture(domain);
88
89 const int2 size = domain.data_size;
90 parallel_for(domain.data_size, [&](const int2 texel) {
91 int2 flipped_texel = texel;
92 if (flip_x) {
93 flipped_texel.x = size.x - texel.x - 1;
94 }
95 if (flip_y) {
96 flipped_texel.y = size.y - texel.y - 1;
97 }
98 output.store_pixel(texel, input.load_pixel<Color>(flipped_texel));
99 });
100 }
101
103 {
104 return this->get_input("Flip X").get_single_value_default<bool>();
105 }
106
108 {
109 return this->get_input("Flip Y").get_single_value_default<bool>();
110 }
111};
112
114{
115 return new FlipOperation(context, node);
116}
117
118static void node_register()
119{
120 static bke::bNodeType ntype;
121
122 cmp_node_type_base(&ntype, "CompositorNodeFlip"_ustr, CMP_NODE_FLIP);
123 ntype.ui_name = "Flip";
124 ntype.ui_description = "Flip an image along a defined axis";
125 ntype.enum_name_legacy = "FLIP";
127 ntype.declare = node_declare;
129
131}
132NOD_REGISTER_NODE(node_register)
133
134} // namespace blender::nodes::node_composite_flip_cc
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:486
#define CMP_NODE_FLIP
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define output
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
virtual Domain compute_domain()
Definition operation.cc:62
void unbind_as_texture() const
Definition result.cc:964
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
Definition result.cc:854
T load_pixel(const int2 &texel) const
NodeOperation(Context &context, const bNode &node)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:235
ColorSceneLinear4f< eAlpha::Premultiplied > Color
Definition COM_result.hh:96
void parallel_for(const int2 range, const Function &function)
static void node_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
void GPU_shader_unbind()
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393