Blender V5.0
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
8
10
11#include "GPU_shader.hh"
12
13#include "COM_node_operation.hh"
14#include "COM_utilities.hh"
15
17
18/* **************** Flip ******************** */
19
21
23{
24 b.use_custom_socket_order();
25 b.allow_any_socket_order();
26 b.add_input<decl::Color>("Image")
27 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
28 .hide_value()
29 .structure_type(StructureType::Dynamic);
30 b.add_output<decl::Color>("Image").structure_type(StructureType::Dynamic).align_with_previous();
31
32 b.add_input<decl::Bool>("Flip X").default_value(false);
33 b.add_input<decl::Bool>("Flip Y").default_value(false);
34}
35
36using namespace blender::compositor;
37
39 public:
41
42 void execute() override
43 {
44 const Result &input = this->get_input("Image");
45 if (input.is_single_value() || (!this->get_flip_x() && !this->get_flip_y())) {
46 Result &output = this->get_result("Image");
47 output.share_data(input);
48 return;
49 }
50
51 if (this->context().use_gpu()) {
52 this->execute_gpu();
53 }
54 else {
55 this->execute_cpu();
56 }
57 }
58
60 {
61 gpu::Shader *shader = context().get_shader("compositor_flip");
62 GPU_shader_bind(shader);
63
64 GPU_shader_uniform_1b(shader, "flip_x", this->get_flip_x());
65 GPU_shader_uniform_1b(shader, "flip_y", this->get_flip_y());
66
67 Result &input = get_input("Image");
68 input.bind_as_texture(shader, "input_tx");
69
70 const Domain domain = compute_domain();
71 Result &result = get_result("Image");
72 result.allocate_texture(domain);
73 result.bind_as_image(shader, "output_img");
74
76
77 input.unbind_as_texture();
78 result.unbind_as_image();
80 }
81
83 {
84 const bool flip_x = this->get_flip_x();
85 const bool flip_y = this->get_flip_y();
86
87 Result &input = get_input("Image");
88
89 const Domain domain = compute_domain();
90 Result &output = get_result("Image");
91 output.allocate_texture(domain);
92
93 const int2 size = domain.size;
94 parallel_for(domain.size, [&](const int2 texel) {
95 int2 flipped_texel = texel;
96 if (flip_x) {
97 flipped_texel.x = size.x - texel.x - 1;
98 }
99 if (flip_y) {
100 flipped_texel.y = size.y - texel.y - 1;
101 }
102 output.store_pixel(texel, input.load_pixel<float4>(flipped_texel));
103 });
104 }
105
107 {
108 return this->get_input("Flip X").get_single_value_default(false);
109 }
110
112 {
113 return this->get_input("Flip Y").get_single_value_default(false);
114 }
115};
116
118{
119 return new FlipOperation(context, node);
120}
121
122} // namespace blender::nodes::node_composite_flip_cc
123
125{
126 namespace file_ns = blender::nodes::node_composite_flip_cc;
127
128 static blender::bke::bNodeType ntype;
129
130 cmp_node_type_base(&ntype, "CompositorNodeFlip", CMP_NODE_FLIP);
131 ntype.ui_name = "Flip";
132 ntype.ui_description = "Flip an image along a defined axis";
133 ntype.enum_name_legacy = "FLIP";
135 ntype.declare = file_ns::cmp_node_flip_declare;
136 ntype.get_compositor_operation = file_ns::get_compositor_operation;
137
139}
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:455
#define CMP_NODE_FLIP
void GPU_shader_uniform_1b(blender::gpu::Shader *sh, const char *name, bool value)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_unbind()
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
virtual Domain compute_domain()
Definition operation.cc:56
void share_data(const Result &source)
Definition result.cc:523
bool is_single_value() const
Definition result.cc:758
#define input
#define output
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:196
void parallel_for(const int2 range, const Function &function)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void cmp_node_flip_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
static void register_node_type_cmp_flip()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:348
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)