31 "The edges of the image that intersects the outer mask will be considered edges of the "
32 "outer mask. Otherwise, the outer mask will be considered open-ended");
36 "Only edges of the inner mask that lie inside the outer mask will be considered. "
37 "Otherwise, all edges of the inner mask will be considered");
39 b.add_output<
decl::Float>(
"Mask").structure_type(StructureType::Dynamic);
77 flooded_inner_boundary.
release();
78 flooded_outer_boundary.
release();
83 if (this->
context().use_gpu()) {
145 bool has_inner_non_masked_neighbors = false;
146 bool has_outer_non_masked_neighbors = false;
147 for (int j = -1; j <= 1; j++) {
148 for (int i = -1; i <= 1; i++) {
149 int2 offset = int2(i, j);
152 if (offset == int2(0)) {
156 if (inner_mask.load_pixel_extended<float>(texel + offset) == 0.0f) {
157 has_inner_non_masked_neighbors = true;
164 float boundary_fallback = include_edges_of_image ? 0.0f : 1.0f;
165 if (outer_mask.load_pixel_fallback(texel + offset, boundary_fallback) == 0.0f) {
166 has_outer_non_masked_neighbors = true;
170 if (has_inner_non_masked_neighbors && has_outer_non_masked_neighbors) {
176 bool is_inner_masked = inner_mask.
load_pixel<
float>(texel) > 0.0f;
177 bool is_outer_masked = outer_mask.
load_pixel<
float>(texel) > 0.0f;
183 bool is_inner_boundary = is_inner_masked && has_inner_non_masked_neighbors &&
185 bool is_outer_boundary = is_outer_masked && !is_inner_masked &&
186 has_outer_non_masked_neighbors;
192 inner_boundary.
store_pixel(texel, inner_jump_flooding_value);
193 outer_boundary.
store_pixel(texel, outer_jump_flooding_value);
199 if (this->
context().use_gpu()) {
208 const Result &flooded_outer_boundary)
210 gpu::Shader *shader =
context().get_shader(
"compositor_double_edge_mask_compute_gradient");
219 flooded_inner_boundary.
bind_as_texture(shader,
"flooded_inner_boundary_tx");
220 flooded_outer_boundary.
bind_as_texture(shader,
"flooded_outer_boundary_tx");
224 output.allocate_texture(domain);
225 output.bind_as_image(shader,
"output_img");
236 const Result &flooded_outer_boundary)
243 output.allocate_texture(domain);
261 float inner_mask = inner_mask_input.load_pixel<float>(texel);
262 if (inner_mask != 0.0f) {
263 output.store_pixel(texel, 1.0f);
268 float outer_mask = outer_mask_input.
load_pixel<
float>(texel);
269 if (outer_mask == 0.0f) {
270 output.store_pixel(texel, 0.0f);
280 float gradient = distance_to_outer / (distance_to_outer + distance_to_inner);
282 output.store_pixel(texel, gradient);
288 return !this->
get_input(
"Only Inside Outer").get_single_value_default(
false);
293 return this->
get_input(
"Image Edges").get_single_value_default(
false);
311 ntype.
ui_name =
"Double Edge Mask";
315 ntype.
declare = file_ns::cmp_node_double_edge_mask_declare;
constexpr int NODE_DEFAULT_MAX_WIDTH
#define CMP_NODE_DOUBLEEDGEMASK
void GPU_shader_uniform_1b(blender::gpu::Shader *sh, const char *name, bool value)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
#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, DNode node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
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
bool is_single_value() const
StructureType structure_type
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)
NodeOperation(Context &context, DNode node)
void node_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
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 void cmp_node_double_edge_mask_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
static void register_node_type_cmp_doubleedgemask()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)