45 col->label(
IFACE_(
"Inner Edge:"), ICON_NONE);
47 col->label(
IFACE_(
"Buffer Edge:"), ICON_NONE);
86 flooded_inner_boundary.
release();
87 flooded_outer_boundary.
release();
92 if (this->
context().use_gpu()) {
102 GPUShader *shader =
context().
get_shader(
"compositor_double_edge_mask_compute_boundary",
154 bool has_inner_non_masked_neighbors = false;
155 bool has_outer_non_masked_neighbors = false;
156 for (int j = -1; j <= 1; j++) {
157 for (int i = -1; i <= 1; i++) {
158 int2 offset = int2(i, j);
161 if (offset == int2(0)) {
165 if (inner_mask.load_pixel_extended<float>(texel + offset) == 0.0f) {
166 has_inner_non_masked_neighbors = true;
173 float boundary_fallback = include_edges_of_image ? 0.0f : 1.0f;
174 if (outer_mask.load_pixel_fallback(texel + offset, boundary_fallback) == 0.0f) {
175 has_outer_non_masked_neighbors = true;
179 if (has_inner_non_masked_neighbors && has_outer_non_masked_neighbors) {
185 bool is_inner_masked = inner_mask.
load_pixel<
float>(texel) > 0.0f;
186 bool is_outer_masked = outer_mask.
load_pixel<
float>(texel) > 0.0f;
192 bool is_inner_boundary = is_inner_masked && has_inner_non_masked_neighbors &&
194 bool is_outer_boundary = is_outer_masked && !is_inner_masked &&
195 has_outer_non_masked_neighbors;
201 inner_boundary.
store_pixel(texel, inner_jump_flooding_value);
202 outer_boundary.
store_pixel(texel, outer_jump_flooding_value);
208 if (this->
context().use_gpu()) {
217 const Result &flooded_outer_boundary)
219 GPUShader *shader =
context().get_shader(
"compositor_double_edge_mask_compute_gradient");
228 flooded_inner_boundary.
bind_as_texture(shader,
"flooded_inner_boundary_tx");
229 flooded_outer_boundary.
bind_as_texture(shader,
"flooded_outer_boundary_tx");
233 output.allocate_texture(domain);
234 output.bind_as_image(shader,
"output_img");
245 const Result &flooded_outer_boundary)
252 output.allocate_texture(domain);
270 float inner_mask = inner_mask_input.load_pixel<float>(texel);
271 if (inner_mask != 0.0f) {
272 output.store_pixel(texel, 1.0f);
277 float outer_mask = outer_mask_input.
load_pixel<
float>(texel);
278 if (outer_mask == 0.0f) {
279 output.store_pixel(texel, 0.0f);
289 float gradient = distance_to_outer / (distance_to_outer + distance_to_inner);
291 output.store_pixel(texel, gradient);
299 return !bool(
bnode().custom1);
306 return bool(
bnode().custom2);
324 ntype.
ui_name =
"Double Edge Mask";
328 ntype.
declare = file_ns::cmp_node_double_edge_mask_declare;
329 ntype.
draw_buttons = file_ns::node_composit_buts_double_edge_mask;
#define CMP_NODE_DOUBLEEDGEMASK
void GPU_shader_bind(GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
Result create_result(ResultType type, ResultPrecision precision)
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
const bNode & bnode() const
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
void allocate_texture(Domain domain, bool from_pool=true)
void store_pixel(const int2 &texel, const T &pixel_value)
void unbind_as_texture() const
void bind_as_texture(GPUShader *shader, const char *texture_name) const
T load_pixel(const int2 &texel) const
void bind_as_image(GPUShader *shader, const char *image_name, bool read=false) const
void unbind_as_image() const
bool is_single_value() const
int compositor_domain_priority() const
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_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(GPUShader *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 void node_composit_buts_double_edge_mask(uiLayout *layout, bContext *, PointerRNA *ptr)
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
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare
uiLayout & column(bool align)
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)