36 b.use_custom_socket_order();
37 b.allow_any_socket_order();
40 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
43 b.add_output<
decl::Color>(
"Image").structure_type(StructureType::Dynamic).align_with_previous();
44 b.add_output<
decl::Float>(
"Plane").structure_type(StructureType::Dynamic);
49 .default_value({0.0f, 1.0f})
55 .default_value({1.0f, 1.0f})
61 .default_value({0.0f, 0.0f})
67 .default_value({1.0f, 0.0f})
80 .
description(
"The extension mode applied to the X axis")
85 .
description(
"The extension mode applied to the Y axis")
125 smaa(
context(), plane_mask, anti_aliased_plane_mask);
129 this->
compute_plane(homography_matrix, &anti_aliased_plane_mask);
133 output_mask.
steal_data(anti_aliased_plane_mask);
136 anti_aliased_plane_mask.
release();
148 if (this->
context().use_gpu()) {
205 output.allocate_texture(domain);
216 if (transformed_coordinates.z == 0.0f) {
221 float2 projected_coordinates = transformed_coordinates.
xy() / transformed_coordinates.z;
225 sampled_color =
input.sample(
226 projected_coordinates, interpolation, extension_mode_x, extension_mode_y);
233 float2 x_gradient = (homography_matrix[0].xy() / transformed_coordinates.z) /
size.x;
234 float2 y_gradient = (homography_matrix[1].xy() / transformed_coordinates.z) /
size.y;
235 sampled_color =
input.sample_ewa_extended(projected_coordinates, x_gradient, y_gradient);
238 float4 plane_color = plane_mask ? sampled_color * plane_mask->
load_pixel<
float>(texel) :
241 output.store_pixel(texel, plane_color);
247 if (this->
context().use_gpu()) {
293 if (transformed_coordinates.z == 0.0f) {
297 float2 projected_coordinates = transformed_coordinates.
xy() / transformed_coordinates.z;
298 bool is_inside_plane_x = projected_coordinates.x >= 0.0f && projected_coordinates.x <= 1.0f;
299 bool is_inside_plane_y = projected_coordinates.y >= 0.0f && projected_coordinates.y <= 1.0f;
303 bool is_x_masked = is_inside_plane_x || !is_x_clipped;
304 bool is_y_masked = is_inside_plane_y || !is_y_clipped;
305 float mask_value = is_x_masked && is_y_masked ? 1.0f : 0.0f;
329 float corners[4][2] = {{lower_left.x, lower_left.y},
330 {lower_right.x, lower_right.y},
331 {upper_right.x, upper_right.y},
332 {upper_left.x, upper_left.y}};
333 float identity_corners[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
335 return homography_matrix;
342 const MenuValue menu_value =
input.get_single_value_default(default_menu_value);
344 switch (interpolation) {
366 const MenuValue menu_value =
input.get_single_value_default(default_menu_value);
368 switch (extension_x) {
388 const MenuValue menu_value =
input.get_single_value_default(default_menu_value);
390 switch (extension_y) {
408 return "compositor_plane_deform_masked";
410 return "compositor_plane_deform_bicubic_masked";
412 return "compositor_plane_deform_anisotropic_masked";
419 return "compositor_plane_deform";
421 return "compositor_plane_deform_bicubic";
427 return "compositor_plane_deform_anisotropic_masked";
438 return is_clipped_x || is_clipped_y || output_needed || use_anisotropic;
466 ntype.
ui_description =
"Plane warp transformation using explicit corner values";
469 ntype.
declare = file_ns::cmp_node_cornerpin_declare;
470 ntype.
initfunc = file_ns::node_composit_init_cornerpin;
#define NODE_CLASS_DISTORT
#define CMP_NODE_CORNERPIN
void BKE_tracking_homography_between_two_quads(float reference_corners[4][2], float corners[4][2], float H[3][3])
bool is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
@ CMP_NODE_INTERPOLATION_NEAREST
@ CMP_NODE_INTERPOLATION_BILINEAR
@ CMP_NODE_INTERPOLATION_BICUBIC
@ CMP_NODE_INTERPOLATION_ANISOTROPIC
@ CMP_NODE_EXTENSION_MODE_EXTEND
@ CMP_NODE_EXTENSION_MODE_CLIP
@ CMP_NODE_EXTENSION_MODE_REPEAT
void GPU_shader_uniform_1b(blender::gpu::Shader *sh, const char *name, bool value)
void GPU_shader_uniform_mat3_as_mat4(blender::gpu::Shader *sh, const char *name, const float data[3][3])
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_texture_extend_mode_y(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_extend_mode_x(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_anisotropic_filter(blender::gpu::Texture *texture, bool use_aniso)
void GPU_texture_mipmap_mode(blender::gpu::Texture *texture, bool use_mipmap, bool use_filter)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
Read Guarded memory(de)allocation.
#define NOD_REGISTER_NODE(REGISTER_FUNC)
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Result create_result(ResultType type, ResultPrecision precision)
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
void share_data(const Result &source)
T get_single_value_default(const T &default_value) const
void store_pixel(const int2 &texel, const T &pixel_value)
void allocate_texture(const Domain domain, const bool from_pool=true, const std::optional< ResultStorageType > storage_type=std::nullopt)
void unbind_as_texture() const
void set_single_value(const T &value)
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
const Domain & domain() const
T load_pixel(const int2 &texel) const
void unbind_as_image() const
void allocate_single_value()
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
bool is_single_value() const
void steal_data(Result &source)
DeclType::Builder & add_input(StringRef name, StringRef identifier="")
StructureType structure_type
ExtensionMode get_extension_mode_y()
Result compute_plane_mask_cpu(const float3x3 &homography_matrix)
void compute_plane_cpu(const float3x3 &homography_matrix, Result *plane_mask)
float3x3 compute_homography_matrix()
Interpolation get_interpolation()
bool should_compute_mask()
Result compute_plane_mask_gpu(const float3x3 &homography_matrix)
Result compute_plane_mask(const float3x3 &homography_matrix)
const char * get_shader_name()
void compute_plane_gpu(const float3x3 &homography_matrix, Result *plane_mask)
void compute_plane(const float3x3 &homography_matrix, Result *plane_mask)
ExtensionMode get_extension_mode_x()
NodeOperation(Context &context, DNode node)
Domain compute_domain() override
void * MEM_callocN(size_t len, const char *str)
void node_register_type(bNodeType &ntype)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
GPUSamplerExtendMode map_extension_mode_to_extend_mode(const ExtensionMode &mode)
void smaa(Context &context, const Result &input, Result &output, const float threshold=0.1f, const float local_contrast_adaptation_factor=2.0f, const int corner_rounding=25)
void parallel_for(const int2 range, const Function &function)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_init_cornerpin(bNodeTree *, bNode *node)
static void cmp_node_cornerpin_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
static void register_node_type_cmp_cornerpin()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
const EnumPropertyItem rna_enum_node_compositor_extension_items[]
const EnumPropertyItem rna_enum_node_compositor_interpolation_items[]
const c_style_mat & ptr() const
static MatBase identity()
VecBase< T, 2 > xy() const
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
void(* initfunc)(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare