Blender V4.5
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.add_input<decl::Color>("Image").default_value({1.0f, 1.0f, 1.0f, 1.0f});
25 b.add_input<decl::Bool>("Flip X").default_value(false).compositor_expects_single_value();
26 b.add_input<decl::Bool>("Flip Y").default_value(false).compositor_expects_single_value();
27
28 b.add_output<decl::Color>("Image");
29}
30
31using namespace blender::compositor;
32
34 public:
36
37 void execute() override
38 {
39 const Result &input = this->get_input("Image");
40 if (input.is_single_value() || (!this->get_flip_x() && !this->get_flip_y())) {
41 Result &output = this->get_result("Image");
42 output.share_data(input);
43 return;
44 }
45
46 if (this->context().use_gpu()) {
47 this->execute_gpu();
48 }
49 else {
50 this->execute_cpu();
51 }
52 }
53
55 {
56 GPUShader *shader = context().get_shader("compositor_flip");
57 GPU_shader_bind(shader);
58
59 GPU_shader_uniform_1b(shader, "flip_x", this->get_flip_x());
60 GPU_shader_uniform_1b(shader, "flip_y", this->get_flip_y());
61
62 Result &input = get_input("Image");
63 input.bind_as_texture(shader, "input_tx");
64
65 const Domain domain = compute_domain();
66 Result &result = get_result("Image");
67 result.allocate_texture(domain);
68 result.bind_as_image(shader, "output_img");
69
71
72 input.unbind_as_texture();
73 result.unbind_as_image();
75 }
76
78 {
79 const bool flip_x = this->get_flip_x();
80 const bool flip_y = this->get_flip_y();
81
82 Result &input = get_input("Image");
83
84 const Domain domain = compute_domain();
85 Result &output = get_result("Image");
86 output.allocate_texture(domain);
87
88 const int2 size = domain.size;
89 parallel_for(domain.size, [&](const int2 texel) {
90 int2 flipped_texel = texel;
91 if (flip_x) {
92 flipped_texel.x = size.x - texel.x - 1;
93 }
94 if (flip_y) {
95 flipped_texel.y = size.y - texel.y - 1;
96 }
97 output.store_pixel(texel, input.load_pixel<float4>(flipped_texel));
98 });
99 }
100
102 {
103 return this->get_input("Flip X").get_single_value_default(false);
104 }
105
107 {
108 return this->get_input("Flip Y").get_single_value_default(false);
109 }
110};
111
113{
114 return new FlipOperation(context, node);
115}
116
117} // namespace blender::nodes::node_composite_flip_cc
118
120{
121 namespace file_ns = blender::nodes::node_composite_flip_cc;
122
123 static blender::bke::bNodeType ntype;
124
125 cmp_node_type_base(&ntype, "CompositorNodeFlip", CMP_NODE_FLIP);
126 ntype.ui_name = "Flip";
127 ntype.ui_description = "Flip an image along a defined axis";
128 ntype.enum_name_legacy = "FLIP";
130 ntype.declare = file_ns::cmp_node_flip_declare;
131 ntype.get_compositor_operation = file_ns::get_compositor_operation;
132
134}
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:441
#define CMP_NODE_FLIP
void GPU_shader_bind(GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
void GPU_shader_unbind()
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
GPUShader * 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:401
bool is_single_value() const
Definition result.cc:622
#define input
#define this
#define output
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:170
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:226
std::string ui_description
Definition BKE_node.hh:232
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:336
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)