73 float accumulated_value = 0.0f;
76 float center_value =
input.load_pixel<
float>(texel);
77 if constexpr (IsErode) {
78 center_value = 1.0f - center_value;
85 float limit_distance = center_value;
86 float limit_distance_falloff = 1.0f;
98 for (
int s = -1; s < 2; s += 2) {
100 float value =
input.load_pixel_extended<
float>(texel +
int2(s *
i, 0));
101 if constexpr (IsErode) {
102 value = 1.0f - value;
104 accumulated_value += value * weight;
108 float falloff_distance = value * falloff;
111 if (falloff_distance > limit_distance) {
112 limit_distance = falloff_distance;
113 limit_distance_falloff = falloff;
121 float value =
math::interpolate(accumulated_value, limit_distance, limit_distance_falloff);
122 if constexpr (IsErode) {
123 value = 1.0f - value;
128 output.store_pixel(
int2(texel.y, texel.x), value);
135 return "compositor_morphological_distance_feather_dilate";
137 return "compositor_morphological_distance_feather_erode";
143 const int falloff_type)
148 input.bind_as_texture(shader,
"input_tx");
151 context.cache_manager().morphological_distance_feather_weights.get(
168 output.allocate_texture(transposed_domain);
169 output.bind_as_image(shader,
"output_img");
174 input.unbind_as_texture();
185 const int falloff_type)
188 context.cache_manager().morphological_distance_feather_weights.get(
203 output.allocate_texture(transposed_domain);
218 const int falloff_type)
220 if (context.use_gpu()) {
227 const Result &original_input,
228 const Result &horizontal_pass_result,
231 const int falloff_type)
239 context.cache_manager().morphological_distance_feather_weights.get(
245 output.allocate_texture(domain);
246 output.bind_as_image(shader,
"output_img");
260 const Result &original_input,
261 const Result &horizontal_pass_result,
264 const int falloff_type)
267 context.cache_manager().morphological_distance_feather_weights.get(
271 output.allocate_texture(domain);
282 const Result &original_input,
283 const Result &horizontal_pass_result,
286 const int falloff_type)
288 if (context.use_gpu()) {
290 context, original_input, horizontal_pass_result,
output,
distance, falloff_type);
294 context, original_input, horizontal_pass_result,
output,
distance, falloff_type);
302 const int falloff_type)
306 horizontal_pass_result.
release();
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void unbind_as_texture() const
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
const Domain & domain() const
T load_pixel(const int2 &texel) const
float distance(VecOp< float, D >, VecOp< float, D >) RET
static void vertical_pass_cpu(Context &context, const Result &original_input, const Result &horizontal_pass_result, Result &output, const int distance, const int falloff_type)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
void morphological_distance_feather(Context &context, const Result &input, Result &output, const int distance, const int falloff_type=PROP_SMOOTH)
static void vertical_pass(Context &context, const Result &original_input, const Result &horizontal_pass_result, Result &output, const int distance, const int falloff_type)
static Result horizontal_pass_cpu(Context &context, const Result &input, const int distance, const int falloff_type)
static Result horizontal_pass_gpu(Context &context, const Result &input, const int distance, const int falloff_type)
static Result horizontal_pass(Context &context, const Result &input, const int distance, const int falloff_type)
static void morphological_distance_feather_pass(const Result &input, const MorphologicalDistanceFeatherWeights &weights, Result &output)
void parallel_for(const int2 range, const Function &function)
static void vertical_pass_gpu(Context &context, const Result &original_input, const Result &horizontal_pass_result, Result &output, const int distance, const int falloff_type)
static const char * get_shader_name(const int distance)
T interpolate(const T &a, const T &b, const FactorT &t)
VecBase< int32_t, 2 > int2