Blender V4.3
node_composite_moviedistortion.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_string_utf8.h"
10
11#include "DNA_movieclip_types.h"
12
13#include "BKE_context.hh"
14#include "BKE_lib_id.hh"
15#include "BKE_tracking.h"
16
17#include "UI_interface.hh"
18#include "UI_resources.hh"
19
20#include "GPU_shader.hh"
21#include "GPU_texture.hh"
22
24#include "COM_node_operation.hh"
25#include "COM_utilities.hh"
26
28
29/* **************** Translate ******************** */
30
32
34{
35 b.add_input<decl::Color>("Image")
36 .default_value({0.8f, 0.8f, 0.8f, 1.0f})
37 .compositor_domain_priority(0);
38 b.add_output<decl::Color>("Image");
39}
40
41static void label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int label_maxncpy)
42{
43 if (node->custom1 == 0) {
44 BLI_strncpy_utf8(label, IFACE_("Undistortion"), label_maxncpy);
45 }
46 else {
47 BLI_strncpy_utf8(label, IFACE_("Distortion"), label_maxncpy);
48 }
49}
50
51static void init(const bContext *C, PointerRNA *ptr)
52{
53 bNode *node = (bNode *)ptr->data;
54 Scene *scene = CTX_data_scene(C);
55
56 node->id = (ID *)scene->clip;
57 id_us_plus(node->id);
58}
59
60static void storage_free(bNode *node)
61{
62 if (node->storage) {
64 }
65
66 node->storage = nullptr;
67}
68
69static void storage_copy(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
70{
71 if (src_node->storage) {
73 }
74}
75
77{
78 bNode *node = (bNode *)ptr->data;
79
80 uiTemplateID(layout, C, ptr, "clip", nullptr, "CLIP_OT_open", nullptr);
81
82 if (!node->id) {
83 return;
84 }
85
86 uiItemR(layout, ptr, "distortion_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
87}
88
89using namespace blender::realtime_compositor;
90
92 public:
94
95 void execute() override
96 {
97 Result &input_image = get_input("Image");
98 Result &output_image = get_result("Image");
99 if (input_image.is_single_value() || !get_movie_clip()) {
100 input_image.pass_through(output_image);
101 return;
102 }
103
104 const Domain domain = compute_domain();
105 const DistortionGrid &distortion_grid = context().cache_manager().distortion_grids.get(
106 context(),
108 domain.size,
110 context().get_frame_number());
111
112 GPUShader *shader = context().get_shader("compositor_movie_distortion");
113 GPU_shader_bind(shader);
114
116 GPU_texture_filter_mode(input_image, true);
117 input_image.bind_as_texture(shader, "input_tx");
118
119 distortion_grid.bind_as_texture(shader, "distortion_grid_tx");
120
121 output_image.allocate_texture(domain);
122 output_image.bind_as_image(shader, "output_img");
123
124 compute_dispatch_threads_at_least(shader, domain.size);
125
126 input_image.unbind_as_texture();
127 distortion_grid.unbind_as_texture();
128 output_image.unbind_as_image();
130 }
131
133 {
134 return bnode().custom1 == 0 ? DistortionType::Distort : DistortionType::Undistort;
135 }
136
138 {
139 return reinterpret_cast<MovieClip *>(bnode().id);
140 }
141};
142
144{
145 return new MovieDistortionOperation(context, node);
146}
147
148} // namespace blender::nodes::node_composite_moviedistortion_cc
149
151{
153
154 static blender::bke::bNodeType ntype;
155
156 cmp_node_type_base(&ntype, CMP_NODE_MOVIEDISTORTION, "Movie Distortion", NODE_CLASS_DISTORT);
157 ntype.declare = file_ns::cmp_node_moviedistortion_declare;
158 ntype.draw_buttons = file_ns::node_composit_buts_moviedistortion;
159 ntype.labelfunc = file_ns::label;
160 ntype.initfunc_api = file_ns::init;
161 blender::bke::node_type_storage(&ntype, nullptr, file_ns::storage_free, file_ns::storage_copy);
162 ntype.get_compositor_operation = file_ns::get_compositor_operation;
163
165}
Scene * CTX_data_scene(const bContext *C)
void id_us_plus(ID *id)
Definition lib_id.cc:351
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:412
struct MovieDistortion * BKE_tracking_distortion_copy(struct MovieDistortion *distortion)
Definition tracking.cc:2313
void BKE_tracking_distortion_free(struct MovieDistortion *distortion)
Definition tracking.cc:2414
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define IFACE_(msgid)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
void uiTemplateID(uiLayout *layout, const bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int filter=UI_TEMPLATE_ID_FILTER_ALL, bool live_icon=false, const char *text=nullptr)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
struct GPUShader GPUShader
void init()
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
DistortionGrid & get(Context &context, MovieClip *movie_clip, int2 size, DistortionType type, int frame_number)
void bind_as_texture(GPUShader *shader, const char *texture_name) const
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
const char * label
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void storage_copy(bNodeTree *, bNode *dest_node, const bNode *src_node)
static void cmp_node_moviedistortion_declare(NodeDeclarationBuilder &b)
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_moviedistortion()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Definition DNA_ID.h:413
void * data
Definition RNA_types.hh:42
int16_t custom1
struct ID * id
void * storage
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:280
PointerRNA * ptr
Definition wm_files.cc:4126