21 b.use_custom_socket_order();
22 b.allow_any_socket_order();
24 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
28 .structure_type(StructureType::Dynamic)
29 .align_with_previous();
36 .structure_type(StructureType::Dynamic);
41 "Pixels are despeckled only if their color difference from the average color of their "
42 "neighbors exceeds this threshold");
49 "Pixels are despeckled only if the number of pixels in their neighborhood that are "
50 "different exceed this ratio threshold relative to the total number of neighbors. "
51 "Neighbors are considered different if they exceed the color threshold input");
69 if (this->
context().use_gpu()) {
115 output.allocate_texture(domain);
120 float corner_weight = 1.0f /
math::sqrt(2.0f);
121 float sum_of_weights = 4.0f + corner_weight * 4.0f;
124 float3(corner_weight, 1.0f, corner_weight));
127 float4 center_color = float4(input.load_pixel<Color>(texel));
133 float4 sum_of_colors = float4(0.0f);
134 float accumulated_weight = 0.0f;
135 float4 accumulated_color = float4(0.0f);
136 for (int j = 0; j < 3; j++) {
137 for (int i = 0; i < 3; i++) {
138 float weight = weights[j][i];
139 float4 color = float4(input.load_pixel_extended<Color>(texel + int2(i - 1, j - 1))) *
141 sum_of_colors += color;
142 if (!math::is_equal(center_color.xyz(), color.xyz(), color_threshold)) {
143 accumulated_color += color;
144 accumulated_weight += weight;
151 if (accumulated_weight == 0.0f) {
160 if (accumulated_weight / sum_of_weights < neighbor_threshold) {
168 center_color.xyz(), (sum_of_colors / sum_of_weights).xyz(), color_threshold))
170 output.store_pixel(texel, Color(center_color));
175 float factor = factor_image.
load_pixel<
float,
true>(texel);
176 float4 mean_color = accumulated_color / accumulated_weight;
183 return math::max(0.0f, this->
get_input(
"Color Threshold").get_single_value_default<float>());
189 this->
get_input(
"Neighbor Threshold").get_single_value_default<float>(), 0.0f, 1.0f);
205 "Smooth areas of an image in which noise is noticeable, while leaving complex areas "
#define NODE_CLASS_OP_FILTER
#define CMP_NODE_DESPECKLE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
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
virtual Domain compute_domain()
bool is_single_value() const
void unbind_as_texture_or_single_value(gpu::Texture *single_value_texture) 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 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
gpu::Texture * bind_as_texture_or_single_value(gpu::Shader *shader, const char *texture_name) const
StructureType structure_type
NodeOperation(Context &context, const bNode &node)
float get_neighbor_threshold()
float get_color_threshold()
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
ColorSceneLinear4f< eAlpha::Premultiplied > Color
void parallel_for(const int2 range, const Function &function)
T clamp(const T &a, const T &min, const T &max)
T interpolate(const T &a, const T &b, const FactorT &t)
bool is_equal(const MatBase< T, NumCol, NumRow > &a, const MatBase< T, NumCol, NumRow > &b, const T epsilon=T(0))
T max(const T &a, const T &b)
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 GPU_shader_uniform_1f(gpu::Shader *sh, const char *name, float value)
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
const char * enum_name_legacy
NodeDeclareFunction declare