21 .structure_type(StructureType::Dynamic)
23 "The distance in pixel to the nearest pixel at the boundary of the mask. The distance "
24 "is negative inside the mask");
28 .description(
"The integer coordinates of the nearest pixel at the boundary of the mask");
69 nearest_pixel_output.
share_data(flooded_boundary);
79 if (this->
context().use_gpu()) {
102 mask.unbind_as_texture();
127 bool has_unmasked_neighbors = false;
128 for (int j = -1; j <= 1; j++) {
129 for (int i = -1; i <= 1; i++) {
130 const int2 offset = int2(i, j);
133 if (offset == int2(0)) {
137 if (!mask.load_pixel_extended<bool>(texel + offset)) {
138 has_unmasked_neighbors = true;
145 const bool is_masked =
mask.load_pixel<
bool>(texel);
146 const bool is_boundary_pixel = is_masked && has_unmasked_neighbors;
151 boundary.store_pixel(texel, jump_flooding_value);
159 if (this->
context().use_gpu()) {
184 mask.unbind_as_texture();
199 const bool is_inside_mask = mask.load_pixel<bool>(texel);
200 const int2 closest_boundary_texel = flooded_boundary.load_pixel<int2>(texel);
201 const float distance_to_boundary = math::distance(float2(texel),
202 float2(closest_boundary_texel));
203 const float signed_distance = is_inside_mask ? -distance_to_boundary : distance_to_boundary;
205 distance_output.store_pixel(texel, signed_distance);
221 ntype.
ui_description =
"Computes a signed distance field from the given mask";
#define NODE_CLASS_OP_FILTER
#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)
bool is_single_value() const
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
void set_precision(ResultPrecision precision)
void unbind_as_image() const
void allocate_single_value()
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
StructureType structure_type
NodeOperation(Context &context, const bNode &node)
void compute_signed_distance_gpu(const Result &flooded_boundary)
Result compute_boundary()
Result compute_boundary_gpu()
void compute_signed_distance_cpu(const Result &flooded_boundary)
Result compute_boundary_cpu()
void compute_signed_distance(const Result &flooded_boundary)
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
int2 initialize_jump_flooding_value(const int2 &texel, const bool is_seed)
void jump_flooding(Context &context, Result &input, Result &output)
void parallel_for(const int2 range, const Function &function)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
NodeDeclareFunction declare