37 {0,
nullptr, 0,
nullptr,
nullptr},
43 StructureType::Dynamic);
45 "The size of dilation/erosion in pixels. Positive values dilates and negative values "
56 "The size of the falloff from the edges in pixels. If less than two pixels, the edges "
57 "will be anti-aliased");
65 b.add_output<
decl::Float>(
"Mask").structure_type(StructureType::Dynamic);
117 horizontal_pass_result.
release();
122 if (this->
context().use_gpu()) {
159 return horizontal_pass_result;
187 return horizontal_pass_result;
192 if (this->
context().use_gpu()) {
226 return "compositor_morphological_step_dilate";
228 return "compositor_morphological_step_erode";
255 const float limit = IsDilate ? std::numeric_limits<float>::lowest() :
256 std::numeric_limits<float>::max();
257 const auto morphology_operator = [](
const float a,
const float b) {
258 if constexpr (IsDilate) {
274 const int tiles_count = int(
math::ceil(
float(image_size.x) /
size));
278 Array<float> prefix_table(size);
279 Array<float> suffix_table(size);
280 for (const int64_t y : sub_y_range) {
281 for (const int64_t tile_index : IndexRange(tiles_count)) {
282 const int64_t tile_start = tile_index * size;
285 const int64_t tile_center = tile_start + size / 2;
287 float prefix_value = limit;
288 float suffix_value = limit;
292 for (const int64_t i : IndexRange(size)) {
293 const float right_value = input.load_pixel_fallback(int2(tile_center + i, y), limit);
294 prefix_value = morphology_operator(prefix_value, right_value);
295 prefix_table[i] = prefix_value;
299 const float left_value = input.load_pixel_fallback(int2(tile_center - i, y), limit);
300 suffix_value = morphology_operator(suffix_value, left_value);
301 suffix_table[size - 1 - i] = suffix_value;
304 const IndexRange tile_range = IndexRange(tile_start, size);
305 const IndexRange safe_tile_range = tile_range.intersect(IndexRange(image_size.x));
308 for (const int64_t x : safe_tile_range) {
311 const int64_t table_index = x - tile_start;
312 const float prefix_value = prefix_table[table_index];
313 const float suffix_value = suffix_table[table_index];
315 const float value = morphology_operator(prefix_value, suffix_value);
319 output.store_pixel(int2(y, x), value);
343 if (this->
context().use_gpu()) {
358 output.steal_data(output_mask);
364 gpu::Shader *shader =
context().get_shader(
"compositor_morphological_distance_threshold");
375 output.allocate_texture(domain);
376 output.bind_as_image(shader,
"output_img");
390 output.allocate_texture(domain);
392 const int2 image_size =
input.domain().size;
450 bool is_center_masked = input.load_pixel<float>(texel) > 0.5f;
454 int minimum_squared_distance = radius * radius * 2;
458 const int2 start = math::max(texel - radius, int2(0)) - texel;
459 const int2 end = math::min(texel + radius + 1, image_size) - texel;
463 for (int y = start.y; y < end.y; y++) {
464 const int yy = y * y;
465 for (int x = start.x; x < end.x; x++) {
466 bool is_sample_masked = input.load_pixel<float>(texel + int2(x, y)) > 0.5f;
467 if (is_center_masked != is_sample_masked) {
468 minimum_squared_distance = math::min(minimum_squared_distance, x * x + yy);
475 float signed_minimum_distance =
math::sqrt(
float(minimum_squared_distance)) *
476 (is_center_masked ? 1.0f : -1.0f);
482 output.store_pixel(texel, value);
509 if (
input.is_single_value()) {
543 return this->
get_input(
"Size").get_single_value_default(0);
548 return math::max(0.0f, this->
get_input(
"Falloff Size").get_single_value_default(0.0f));
555 const MenuValue menu_value =
input.get_single_value_default(default_menu_value);
563 const MenuValue menu_value =
input.get_single_value_default(default_menu_value);
564 return menu_value.
value;
582 ntype.
ui_name =
"Dilate/Erode";
586 ntype.
declare = file_ns::cmp_node_dilate_declare;
587 ntype.
initfunc = file_ns::node_composit_init_dilateerode;
#define NODE_CLASS_OP_FILTER
#define CMP_NODE_DILATEERODE
#define BLT_I18NCONTEXT_ID_CURVE_LEGACY
@ CMP_NODE_DILATE_ERODE_STEP
@ CMP_NODE_DILATE_ERODE_DISTANCE_FEATHER
@ CMP_NODE_DILATE_ERODE_DISTANCE_THRESHOLD
@ CMP_NODE_DILATE_ERODE_DISTANCE
void GPU_shader_uniform_1f(blender::gpu::Shader *sh, const char *name, float value)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(blender::gpu::Shader *sh, const char *name, int value)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
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 share_data(const Result &source)
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
void unbind_as_image() const
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
StructureType structure_type
void execute_distance_threshold_gpu(Result &output)
void execute_distance_threshold_cpu(Result &output)
CMPNodeDilateErodeMethod get_type()
Result execute_step_horizontal_pass_gpu()
void execute_step_vertical_pass(Result &horizontal_pass_result)
Result execute_step_horizontal_pass_cpu()
const char * get_morphological_step_shader_name()
void execute_distance_threshold()
Result execute_step_horizontal_pass()
void execute_step_pass_cpu(const Result &input, Result &output)
void execute_distance_feather()
int get_structuring_element_size()
void execute_step_vertical_pass_gpu(Result &horizontal_pass_result)
int get_morphological_distance_threshold_radius()
NodeOperation(Context &context, DNode node)
void execute_step_vertical_pass_cpu(Result &horizontal_pass_result)
float distance(VecOp< float, D >, VecOp< float, D >) RET
void * MEM_callocN(size_t len, const char *str)
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))
void morphological_distance(Context &context, const Result &input, Result &output, const int distance)
void morphological_distance_feather(Context &context, const Result &input, Result &output, const int distance, const int falloff_type=PROP_SMOOTH)
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)
T clamp(const T &a, const T &min, const T &max)
T min(const T &a, const T &b)
T max(const T &a, const T &b)
static void cmp_node_dilate_declare(NodeDeclarationBuilder &b)
static void node_composit_init_dilateerode(bNodeTree *, bNode *node)
static const EnumPropertyItem type_items[]
static NodeOperation * get_compositor_operation(Context &context, DNode node)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
VecBase< int32_t, 2 > int2
static void register_node_type_cmp_dilateerode()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
const EnumPropertyItem rna_enum_proportional_falloff_curve_only_items[]
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
void(* initfunc)(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)