Blender V4.3
node_composite_map_uv.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 "GPU_shader.hh"
10#include "GPU_texture.hh"
11
12#include "UI_interface.hh"
13#include "UI_resources.hh"
14
15#include "COM_node_operation.hh"
16#include "COM_utilities.hh"
17
19
20/* **************** Map UV ******************** */
21
23
25{
26 b.add_input<decl::Color>("Image")
27 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
28 .compositor_realization_options(CompositorInputRealizationOptions::None);
29 b.add_input<decl::Vector>("UV")
30 .default_value({1.0f, 0.0f, 0.0f})
31 .min(0.0f)
32 .max(1.0f)
34 b.add_output<decl::Color>("Image");
35}
36
38{
39 uiItemR(layout, ptr, "filter_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
40 uiItemR(layout, ptr, "alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
41}
42
43static void node_composit_init_map_uv(bNodeTree * /*ntree*/, bNode *node)
44{
46}
47
48using namespace blender::realtime_compositor;
49
51 public:
53
54 void execute() override
55 {
56 if (get_input("Image").is_single_value()) {
57 get_input("Image").pass_through(get_result("Image"));
58 return;
59 }
60 bool nearest_neighbour = get_nearest_neighbour();
61
63
64 GPU_shader_bind(shader);
65
66 if (!nearest_neighbour) {
68 shader, "gradient_attenuation_factor", get_gradient_attenuation_factor());
69 }
70
71 const Result &input_image = get_input("Image");
72 if (nearest_neighbour) {
73 GPU_texture_mipmap_mode(input_image, false, false);
74 GPU_texture_anisotropic_filter(input_image, false);
75 }
76 else {
77 GPU_texture_mipmap_mode(input_image, true, true);
78 GPU_texture_anisotropic_filter(input_image, true);
79 }
80
82 input_image.bind_as_texture(shader, "input_tx");
83
84 const Result &input_uv = get_input("UV");
85 input_uv.bind_as_texture(shader, "uv_tx");
86
87 const Domain domain = compute_domain();
88 Result &output_image = get_result("Image");
89 output_image.allocate_texture(domain);
90 output_image.bind_as_image(shader, "output_img");
91
92 compute_dispatch_threads_at_least(shader, domain.size);
93
94 input_image.unbind_as_texture();
95 input_uv.unbind_as_texture();
96 output_image.unbind_as_image();
98 }
99
100 /* A factor that controls the attenuation of the result at the pixels where the gradients of the
101 * UV texture are too high, see the shader for more information. The factor ranges between zero
102 * and one, where it has no effect when it is zero and performs full attenuation when it is 1. */
104 {
105 return bnode().custom1 / 100.0f;
106 }
107
112
113 char const *get_shader_name()
114 {
115 return get_nearest_neighbour() ? "compositor_map_uv_nearest_neighbour" :
116 "compositor_map_uv_anisotropic";
117 }
118};
119
121{
122 return new MapUVOperation(context, node);
123}
124
125} // namespace blender::nodes::node_composite_map_uv_cc
126
128{
130
131 static blender::bke::bNodeType ntype;
132
133 cmp_node_type_base(&ntype, CMP_NODE_MAP_UV, "Map UV", NODE_CLASS_DISTORT);
134 ntype.declare = file_ns::cmp_node_map_uv_declare;
135 ntype.draw_buttons = file_ns::node_composit_buts_map_uv;
136 ntype.get_compositor_operation = file_ns::get_compositor_operation;
137 ntype.initfunc = file_ns::node_composit_init_map_uv;
138
140}
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:412
@ CMP_NODE_MAP_UV_FILTERING_NEAREST
@ CMP_NODE_MAP_UV_FILTERING_ANISOTROPIC
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
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)
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
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
static void node_composit_init_map_uv(bNodeTree *, bNode *node)
static void cmp_node_map_uv_declare(NodeDeclarationBuilder &b)
static void node_composit_buts_map_uv(uiLayout *layout, bContext *, PointerRNA *ptr)
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_mapuv()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition sort.c:32
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126