Blender
V4.3
source
blender
compositor
realtime_compositor
algorithms
intern
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
14
#include "
COM_algorithm_morphological_distance.hh
"
15
16
namespace
blender::realtime_compositor
{
17
18
static
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
26
void
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
41
GPU_shader_unbind
();
42
output.unbind_as_image();
43
input.unbind_as_texture();
44
}
45
46
}
// namespace blender::realtime_compositor
BLI_math_base.hh
COM_algorithm_morphological_distance.hh
COM_context.hh
COM_result.hh
COM_utilities.hh
GPU_shader.hh
GPU_shader_uniform_1i
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
Definition
gpu_shader.cc:674
GPU_shader_bind
void GPU_shader_bind(GPUShader *shader)
Definition
gpu_shader.cc:372
GPU_shader_unbind
void GPU_shader_unbind()
Definition
gpu_shader.cc:404
GPU_texture.hh
GPUShader
struct GPUShader GPUShader
Definition
blender/display_driver.h:21
blender::realtime_compositor::Context
Definition
COM_context.hh:37
blender::realtime_compositor::Result
Definition
COM_result.hh:92
blender::math::abs
T abs(const T &a)
Definition
BLI_math_base.hh:33
blender::realtime_compositor
Definition
BKE_node.hh:80
blender::realtime_compositor::morphological_distance
void morphological_distance(Context &context, Result &input, Result &output, int distance)
Definition
morphological_distance.cc:26
blender::realtime_compositor::get_shader_name
static const char * get_shader_name(int distance)
Definition
morphological_distance.cc:18
blender::realtime_compositor::compute_dispatch_threads_at_least
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
Definition
utilities.cc:131
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0