Blender V4.5
node_composite_composite.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
9#include "BLI_bounds_types.hh"
11
12#include "UI_interface.hh"
13#include "UI_resources.hh"
14
15#include "GPU_shader.hh"
16#include "GPU_texture.hh"
17
18#include "COM_node_operation.hh"
19#include "COM_utilities.hh"
20
22
23/* **************** COMPOSITE ******************** */
24
26
28{
29 b.add_input<decl::Color>("Image").default_value({0.0f, 0.0f, 0.0f, 1.0f});
30}
31
32using namespace blender::compositor;
33
35 public:
37
38 void execute() override
39 {
40 if (!this->context().is_valid_compositing_region()) {
41 return;
42 }
43
44 const Result &image = this->get_input("Image");
45 if (image.is_single_value()) {
46 this->execute_clear();
47 }
48 else {
49 this->execute_copy();
50 }
51 }
52
54 {
55 const Result &image = this->get_input("Image");
56
58
59 const Domain domain = this->compute_domain();
61 if (this->context().use_gpu()) {
63 }
64 else {
65 parallel_for(domain.size, [&](const int2 texel) { output.store_pixel(texel, color); });
66 }
67 }
68
70 {
71 if (this->context().use_gpu()) {
72 this->execute_copy_gpu();
73 }
74 else {
75 this->execute_copy_cpu();
76 }
77 }
78
80 {
81 const Result &image = this->get_input("Image");
82 const Domain domain = this->compute_domain();
84
85 GPUShader *shader = this->context().get_shader("compositor_write_output", output.precision());
86 GPU_shader_bind(shader);
87
89 GPU_shader_uniform_2iv(shader, "lower_bound", bounds.min);
90 GPU_shader_uniform_2iv(shader, "upper_bound", bounds.max);
91
92 image.bind_as_texture(shader, "input_tx");
93
94 output.bind_as_image(shader, "output_img");
95
97
98 image.unbind_as_texture();
99 output.unbind_as_image();
101 }
102
104 {
105 const Domain domain = this->compute_domain();
106 const Result &image = this->get_input("Image");
108
109 const Bounds<int2> bounds = this->get_output_bounds();
110 parallel_for(domain.size, [&](const int2 texel) {
111 const int2 output_texel = texel + bounds.min;
112 if (output_texel.x > bounds.max.x || output_texel.y > bounds.max.y) {
113 return;
114 }
115 output.store_pixel(texel + bounds.min, image.load_pixel<float4>(texel));
116 });
117 }
118
119 /* Returns the bounds of the area of the compositing region. Only write into the compositing
120 * region, which might be limited to a smaller region of the output result. */
122 {
123 const rcti compositing_region = this->context().get_compositing_region();
124 return Bounds<int2>(int2(compositing_region.xmin, compositing_region.ymin),
125 int2(compositing_region.xmax, compositing_region.ymax));
126 }
127
128 /* The operation domain has the same size as the compositing region without any transformations
129 * applied. */
131 {
132 return Domain(this->context().get_compositing_region_size());
133 }
134};
135
137{
138 return new CompositeOperation(context, node);
139}
140
141} // namespace blender::nodes::node_composite_composite_cc
142
144{
146
147 static blender::bke::bNodeType ntype;
148
149 cmp_node_type_base(&ntype, "CompositorNodeComposite", CMP_NODE_COMPOSITE);
150 ntype.ui_name = "Composite";
151 ntype.ui_description = "Final render output";
152 ntype.enum_name_legacy = "COMPOSITE";
154 ntype.declare = file_ns::cmp_node_composite_declare;
155 ntype.get_compositor_operation = file_ns::get_compositor_operation;
156 ntype.no_muting = true;
157
159}
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:434
#define CMP_NODE_COMPOSITE
void GPU_shader_bind(GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2])
void GPU_shader_unbind()
void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
@ GPU_DATA_FLOAT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
virtual Result get_output_result()=0
NodeOperation(Context &context, DNode node)
Result & get_input(StringRef identifier) const
Definition operation.cc:138
static ResultPrecision precision(eGPUTextureFormat format)
Definition result.cc:166
void unbind_as_texture() const
Definition result.cc:389
void bind_as_texture(GPUShader *shader, const char *texture_name) const
Definition result.cc:365
T load_pixel(const int2 &texel) const
bool is_single_value() const
Definition result.cc:625
const T & get_single_value() const
#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_composite_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
static void register_node_type_cmp_composite()
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
int ymin
int ymax
int xmin
int xmax