29 b.use_custom_socket_order();
30 b.allow_any_socket_order();
32 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
35 b.add_output<
decl::Color>(
"Image").structure_type(StructureType::Dynamic).align_with_previous();
42 .structure_type(StructureType::Dynamic);
47 "Pixels are despeckled only if their color difference from the average color of their "
48 "neighbors exceeds this threshold");
55 "Pixels are despeckled only if the number of pixels in their neighborhood that are "
56 "different exceed this ratio threshold relative to the total number of neighbors. "
57 "Neighbors are considered different if they exceed the color threshold input");
75 if (this->
context().use_gpu()) {
120 output.allocate_texture(domain);
125 float corner_weight = 1.0f /
math::sqrt(2.0f);
126 float sum_of_weights = 4.0f + corner_weight * 4.0f;
129 float3(corner_weight, 1.0f, corner_weight));
132 float4 center_color = input.load_pixel<float4>(texel);
138 float4 sum_of_colors = float4(0.0f);
139 float accumulated_weight = 0.0f;
140 float4 accumulated_color = float4(0.0f);
141 for (int j = 0; j < 3; j++) {
142 for (int i = 0; i < 3; i++) {
143 float weight = weights[j][i];
144 float4 color = input.load_pixel_extended<float4>(texel + int2(i - 1, j - 1)) * weight;
145 sum_of_colors += color;
146 if (!math::is_equal(center_color.xyz(), color.xyz(), color_threshold)) {
147 accumulated_color += color;
148 accumulated_weight += weight;
155 if (accumulated_weight == 0.0f) {
156 output.store_pixel(texel, center_color);
164 if (accumulated_weight / sum_of_weights < neighbor_threshold) {
165 output.store_pixel(texel, center_color);
172 center_color.xyz(), (sum_of_colors / sum_of_weights).xyz(), color_threshold))
174 output.store_pixel(texel, center_color);
179 float factor = factor_image.
load_pixel<
float,
true>(texel);
180 float4 mean_color = accumulated_color / accumulated_weight;
187 return math::max(0.0f, this->
get_input(
"Color Threshold").get_single_value_default(0.5f));
193 this->
get_input(
"Neighbor Threshold").get_single_value_default(0.5f), 0.0f, 1.0f);
213 "Smooth areas of an image in which noise is noticeable, while leaving complex areas "
217 ntype.
declare = file_ns::cmp_node_despeckle_declare;
#define NODE_CLASS_OP_FILTER
#define CMP_NODE_DESPECKLE
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)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
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
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
float get_neighbor_threshold()
float get_color_threshold()
NodeOperation(Context &context, DNode node)
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
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, DNode node)
static void cmp_node_despeckle_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
static void register_node_type_cmp_despeckle()
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)