28 "The edges of the image that intersects the outer mask will be considered edges of the "
29 "outer mask. Otherwise, the outer mask will be considered open-ended");
33 "Only edges of the inner mask that lie inside the outer mask will be considered. "
34 "Otherwise, all edges of the inner mask will be considered");
36 b.add_output<
decl::Float>(
"Mask"_ustr).structure_type(StructureType::Dynamic);
73 flooded_inner_boundary.
release();
74 flooded_outer_boundary.
release();
79 if (this->
context().use_gpu()) {
141 bool has_inner_non_masked_neighbors = false;
142 bool has_outer_non_masked_neighbors = false;
143 for (int j = -1; j <= 1; j++) {
144 for (int i = -1; i <= 1; i++) {
145 int2 offset = int2(i, j);
148 if (offset == int2(0)) {
152 if (inner_mask.load_pixel_extended<float>(texel + offset) == 0.0f) {
153 has_inner_non_masked_neighbors = true;
160 float boundary_fallback = include_edges_of_image ? 0.0f : 1.0f;
161 if (outer_mask.load_pixel_fallback(texel + offset, boundary_fallback) == 0.0f) {
162 has_outer_non_masked_neighbors = true;
166 if (has_inner_non_masked_neighbors && has_outer_non_masked_neighbors) {
172 bool is_inner_masked = inner_mask.
load_pixel<
float>(texel) > 0.0f;
173 bool is_outer_masked = outer_mask.
load_pixel<
float>(texel) > 0.0f;
179 bool is_inner_boundary = is_inner_masked && has_inner_non_masked_neighbors &&
181 bool is_outer_boundary = is_outer_masked && !is_inner_masked &&
182 has_outer_non_masked_neighbors;
188 inner_boundary.
store_pixel(texel, inner_jump_flooding_value);
189 outer_boundary.
store_pixel(texel, outer_jump_flooding_value);
195 if (this->
context().use_gpu()) {
204 const Result &flooded_outer_boundary)
220 output.allocate_texture(domain);
232 const Result &flooded_outer_boundary)
239 output.allocate_texture(domain);
257 float inner_mask = inner_mask_input.load_pixel<float>(texel);
258 if (inner_mask != 0.0f) {
259 output.store_pixel(texel, 1.0f);
264 float outer_mask = outer_mask_input.
load_pixel<
float>(texel);
265 if (outer_mask == 0.0f) {
266 output.store_pixel(texel, 0.0f);
276 float gradient = distance_to_outer / (distance_to_outer + distance_to_inner);
278 output.store_pixel(texel, gradient);
284 return !this->
get_input(
"Only Inside Outer").get_single_value_default<
bool>();
289 return this->
get_input(
"Image Edges").get_single_value_default<
bool>();
303 ntype.
ui_name =
"Double Edge Mask";
#define CMP_NODE_DOUBLEEDGEMASK
#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)
void allocate_default_remaining_outputs()
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
bool is_single_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 bind_as_texture(gpu::Shader *shader, const char *texture_name) const
T load_pixel(const int2 &texel) const
void unbind_as_image() const
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_boundary(Result &inner_boundary, Result &outer_boundary)
void compute_gradient_gpu(const Result &flooded_inner_boundary, const Result &flooded_outer_boundary)
void compute_boundary_cpu(Result &inner_boundary, Result &outer_boundary)
bool include_all_inner_edges()
void compute_gradient_cpu(const Result &flooded_inner_boundary, const Result &flooded_outer_boundary)
bool include_edges_of_image()
void compute_boundary_gpu(Result &inner_boundary, Result &outer_boundary)
void compute_gradient(const Result &flooded_inner_boundary, const Result &flooded_outer_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)
T distance(const T &a, const T &b)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_register()
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
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)
static constexpr int _160
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare