Blender V4.3
morphological_distance.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_math_base.hh"
6
7#include "GPU_shader.hh"
8#include "GPU_texture.hh"
9
10#include "COM_context.hh"
11#include "COM_result.hh"
12#include "COM_utilities.hh"
13
15
17
18static const char *get_shader_name(int distance)
19{
20 if (distance > 0) {
21 return "compositor_morphological_distance_dilate";
22 }
23 return "compositor_morphological_distance_erode";
24}
25
26void morphological_distance(Context &context, Result &input, Result &output, int distance)
27{
28 GPUShader *shader = context.get_shader(get_shader_name(distance));
29 GPU_shader_bind(shader);
30
31 /* Pass the absolute value of the distance. We have specialized shaders for each sign. */
32 GPU_shader_uniform_1i(shader, "radius", math::abs(distance));
33
34 input.bind_as_texture(shader, "input_tx");
35
36 output.allocate_texture(input.domain());
37 output.bind_as_image(shader, "output_img");
38
39 compute_dispatch_threads_at_least(shader, input.domain().size);
40
42 output.unbind_as_image();
43 input.unbind_as_texture();
44}
45
46} // namespace blender::realtime_compositor
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
struct GPUShader GPUShader
T abs(const T &a)
void morphological_distance(Context &context, Result &input, Result &output, int distance)
static const char * get_shader_name(int distance)
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:131