32 b.use_custom_socket_order();
33 b.allow_any_socket_order();
36 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
40 .structure_type(StructureType::Dynamic)
41 .align_with_previous();
42 b.add_output<
decl::Float>(
"Plane"_ustr).structure_type(StructureType::Dynamic);
47 .default_value({0.0f, 1.0f})
53 .default_value({1.0f, 1.0f})
59 .default_value({0.0f, 0.0f})
65 .default_value({1.0f, 0.0f})
78 .
description(
"The extension mode applied to the X axis")
83 .
description(
"The extension mode applied to the Y axis")
123 smaa(
context(), plane_mask, anti_aliased_plane_mask);
127 this->
compute_plane(homography_matrix, &anti_aliased_plane_mask);
131 output_mask.
share_data(anti_aliased_plane_mask);
134 anti_aliased_plane_mask.
release();
145 if (this->
context().use_gpu()) {
202 output.allocate_texture(domain);
213 if (transformed_coordinates.z == 0.0f) {
218 float2 projected_coordinates = transformed_coordinates.xy() / transformed_coordinates.z;
223 projected_coordinates, interpolation, extension_mode_x, extension_mode_y));
227 float2 x_gradient = (homography_matrix[0].xy() * transformed_coordinates.z -
228 transformed_coordinates.xy() * homography_matrix[0].z) /
230 float2 y_gradient = (homography_matrix[1].xy() * transformed_coordinates.z -
231 transformed_coordinates.xy() * homography_matrix[1].z) /
241 float4 plane_color = plane_mask ? sampled_color * plane_mask->
load_pixel<
float>(texel) :
250 if (this->
context().use_gpu()) {
296 if (transformed_coordinates.z == 0.0f) {
300 float2 projected_coordinates = transformed_coordinates.xy() / transformed_coordinates.z;
301 bool is_inside_plane_x = projected_coordinates.x >= 0.0f && projected_coordinates.x <= 1.0f;
302 bool is_inside_plane_y = projected_coordinates.y >= 0.0f && projected_coordinates.y <= 1.0f;
306 bool is_x_masked = is_inside_plane_x || !is_x_clipped;
307 bool is_y_masked = is_inside_plane_y || !is_y_clipped;
308 float mask_value = is_x_masked && is_y_masked ? 1.0f : 0.0f;
332 float corners[4][2] = {{lower_left.x, lower_left.y},
333 {lower_right.x, lower_right.y},
334 {upper_right.x, upper_right.y},
335 {upper_left.x, upper_left.y}};
336 float identity_corners[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
338 return homography_matrix;
345 switch (interpolation) {
367 switch (extension_x) {
387 switch (extension_y) {
405 return "compositor_plane_deform_masked";
407 return "compositor_plane_deform_bicubic_masked";
409 return "compositor_plane_deform_anisotropic_masked";
416 return "compositor_plane_deform";
418 return "compositor_plane_deform_bicubic";
424 return "compositor_plane_deform_anisotropic_masked";
435 return is_clipped_x || is_clipped_y || output_needed || use_anisotropic;
459 ntype.
ui_description =
"Plane warp transformation using explicit corner values";
#define NODE_CLASS_DISTORT
#define CMP_NODE_CORNERPIN
Read Blender memory allocation and freeing.
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Result create_result(ResultType type, ResultPrecision precision)
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
void share_data(const Result &source)
T sample(const float2 &coordinates, const Interpolation &interpolation, const Extension &extension_mode_x, const Extension &extension_mode_y, std::optional< float2x2 > jacobian=std::nullopt) const
bool is_single_value() const
void store_pixel(const int2 &texel, const T &pixel_value)
bool should_compute() const
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
T get_single_value_default() 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
DeclType::Builder & add_input(UString name, UString identifier=""_ustr)
StructureType structure_type
NodeOperation(Context &context, const bNode &node)
void compute_plane_gpu(const float3x3 &homography_matrix, Result *plane_mask)
void compute_plane(const float3x3 &homography_matrix, Result *plane_mask)
const char * get_shader_name()
void compute_plane_cpu(const float3x3 &homography_matrix, Result *plane_mask)
bool should_compute_mask()
Extension get_extension_mode_y()
float3x3 compute_homography_matrix()
Domain compute_domain() override
Result compute_plane_mask(const float3x3 &homography_matrix)
Interpolation get_interpolation()
Result compute_plane_mask_cpu(const float3x3 &homography_matrix)
Result compute_plane_mask_gpu(const float3x3 &homography_matrix)
Extension get_extension_mode_x()
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))
ColorSceneLinear4f< eAlpha::Premultiplied > Color
GPUSamplerExtendMode map_extension_mode_to_extend_mode(const Extension &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, const bNode &node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_register()
static void node_init(bNodeTree *, bNode *node)
const EnumPropertyItem rna_enum_node_compositor_extension_items[]
MatBase< float, 2, 2 > float2x2
void GPU_texture_anisotropic_filter(gpu::Texture *texture, bool use_aniso)
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
BMesh const char void * data
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
@ CMP_NODE_EXTENSION_MODE_REPEAT
@ CMP_NODE_EXTENSION_MODE_EXTEND
@ CMP_NODE_EXTENSION_MODE_CLIP
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void BKE_tracking_homography_between_two_quads(float reference_corners[4][2], float corners[4][2], float H[3][3])
@ CMP_NODE_INTERPOLATION_NEAREST
@ CMP_NODE_INTERPOLATION_BICUBIC
@ CMP_NODE_INTERPOLATION_ANISOTROPIC
@ CMP_NODE_INTERPOLATION_BILINEAR
void GPU_texture_extend_mode_x(gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_extend_mode_y(gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
void GPU_shader_uniform_mat3_as_mat4(gpu::Shader *sh, const char *name, const float data[3][3])
const EnumPropertyItem rna_enum_node_compositor_interpolation_items[]
bool is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const c_style_mat & ptr() const
static MatBase identity()
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare