27 b.use_custom_socket_order();
28 b.allow_any_socket_order();
30 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
33 b.add_output<
decl::Color>(
"Image").structure_type(StructureType::Dynamic).align_with_previous();
36 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
37 .structure_type(StructureType::Dynamic);
39 "The size of the blur in pixels");
44 "Pixels are considered in the blur area if the average difference between their "
45 "determinator and the determinator of the center pixel is less than this threshold");
59 this->get_threshold() == 0.0f)
76 if (this->
context().use_gpu()) {
121 output.allocate_texture(domain);
124 float4 center_determinator = determinator_image.load_pixel<float4>(texel);
129 float accumulated_weight = 0.0f;
130 float4 accumulated_color = float4(0.0f);
131 for (int y = -radius; y <= radius; y++) {
132 for (int x = -radius; x <= radius; x++) {
133 float4 determinator = determinator_image.load_pixel_extended<float4>(texel + int2(x, y));
134 float difference = math::dot(math::abs(center_determinator - determinator).xyz(),
138 if (difference < threshold) {
139 accumulated_weight += 1.0f;
140 accumulated_color += input.load_pixel_extended<float4>(texel + int2(x, y));
148 float4 color = (accumulated_weight != 0.0f) ? (accumulated_color / accumulated_weight) :
179 ntype.
ui_name =
"Bilateral Blur";
180 ntype.
ui_description =
"Adaptively blur image, while retaining sharp edges";
183 ntype.
declare = file_ns::cmp_node_bilateralblur_declare;
#define NODE_CLASS_OP_FILTER
#define CMP_NODE_BILATERALBLUR
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)
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
bool is_single_value() const
StructureType structure_type
NodeOperation(Context &context, DNode node)
void node_register_type(bNodeType &ntype)
void symmetric_separable_blur(Context &context, const Result &input, Result &output, const float2 &radius, const int filter_type=R_FILTER_GAUSS)
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 max(const T &a, const T &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void cmp_node_bilateralblur_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
static void register_node_type_cmp_bilateralblur()
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)