Blender V4.3
node_composite_displace.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 "BLI_math_vector.hh"
10
11#include "GPU_shader.hh"
12#include "GPU_texture.hh"
13
14#include "COM_node_operation.hh"
15#include "COM_utilities.hh"
16
18
19/* **************** Displace ******************** */
20
22
24{
25 b.add_input<decl::Color>("Image")
26 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
27 .compositor_domain_priority(0);
28 b.add_input<decl::Vector>("Vector")
29 .default_value({1.0f, 1.0f, 1.0f})
30 .min(0.0f)
31 .max(1.0f)
33 .compositor_domain_priority(1);
34 b.add_input<decl::Float>("X Scale")
35 .default_value(0.0f)
36 .min(-1000.0f)
37 .max(1000.0f)
39 b.add_input<decl::Float>("Y Scale")
40 .default_value(0.0f)
41 .min(-1000.0f)
42 .max(1000.0f)
44 b.add_output<decl::Color>("Image");
45}
46
47using namespace blender::realtime_compositor;
48
50 public:
52
53 void execute() override
54 {
55 if (is_identity()) {
56 get_input("Image").pass_through(get_result("Image"));
57 return;
58 }
59
60 GPUShader *shader = context().get_shader("compositor_displace");
61 GPU_shader_bind(shader);
62
63 const Result &input_image = get_input("Image");
64 GPU_texture_mipmap_mode(input_image, true, true);
65 GPU_texture_anisotropic_filter(input_image, true);
67 input_image.bind_as_texture(shader, "input_tx");
68
69 const Result &input_displacement = get_input("Vector");
70 input_displacement.bind_as_texture(shader, "displacement_tx");
71 const Result &input_x_scale = get_input("X Scale");
72 input_x_scale.bind_as_texture(shader, "x_scale_tx");
73 const Result &input_y_scale = get_input("Y Scale");
74 input_y_scale.bind_as_texture(shader, "y_scale_tx");
75
76 const Domain domain = compute_domain();
77 Result &output_image = get_result("Image");
78 output_image.allocate_texture(domain);
79 output_image.bind_as_image(shader, "output_img");
80
81 compute_dispatch_threads_at_least(shader, domain.size);
82
83 input_image.unbind_as_texture();
84 input_displacement.unbind_as_texture();
85 input_x_scale.unbind_as_texture();
86 input_y_scale.unbind_as_texture();
87 output_image.unbind_as_image();
89 }
90
92 {
93 const Result &input_image = get_input("Image");
94 if (input_image.is_single_value()) {
95 return true;
96 }
97
98 const Result &input_displacement = get_input("Vector");
99 if (input_displacement.is_single_value() &&
100 math::is_zero(input_displacement.get_vector_value()))
101 {
102 return true;
103 }
104
105 const Result &input_x_scale = get_input("X Scale");
106 const Result &input_y_scale = get_input("Y Scale");
107 if (input_x_scale.is_single_value() && input_x_scale.get_float_value() == 0.0f &&
108 input_y_scale.is_single_value() && input_y_scale.get_float_value() == 0.0f)
109 {
110 return true;
111 }
112
113 return false;
114 }
115};
116
118{
119 return new DisplaceOperation(context, node);
120}
121
122} // namespace blender::nodes::node_composite_displace_cc
123
125{
127
128 static blender::bke::bNodeType ntype;
129
130 cmp_node_type_base(&ntype, CMP_NODE_DISPLACE, "Displace", NODE_CLASS_DISTORT);
131 ntype.declare = file_ns::cmp_node_displace_declare;
132 ntype.get_compositor_operation = file_ns::get_compositor_operation;
133
135}
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:412
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter)
@ PROP_TRANSLATION
Definition RNA_types.hh:164
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
bool is_zero(const T &a)
static void cmp_node_displace_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode 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_displace()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition sort.c:32
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
NodeDeclareFunction declare
Definition BKE_node.hh:347