Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Basnett <cmbasnett@gmail.com>2022-09-17 03:50:37 +0300
committerColin Basnett <cmbasnett@gmail.com>2022-09-17 03:50:37 +0300
commit564bda241a973396da51d7c3ccd9efd97d51728a (patch)
tree4d9aa4cccd82e2e606b47774afa5e1015bf14768 /source/blender/gpu/shaders/compositor/compositor_morphological_distance.glsl
parent0fff238150d076576053c25b646f653d6e3b0edb (diff)
parent48d7ff68f0df209c77bbb081ab46fbc109fd825a (diff)
Merge branch 'master' into feature-imformatfeature-imformat
Diffstat (limited to 'source/blender/gpu/shaders/compositor/compositor_morphological_distance.glsl')
-rw-r--r--source/blender/gpu/shaders/compositor/compositor_morphological_distance.glsl24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/gpu/shaders/compositor/compositor_morphological_distance.glsl b/source/blender/gpu/shaders/compositor/compositor_morphological_distance.glsl
new file mode 100644
index 00000000000..09f896b7a9d
--- /dev/null
+++ b/source/blender/gpu/shaders/compositor/compositor_morphological_distance.glsl
@@ -0,0 +1,24 @@
+#pragma BLENDER_REQUIRE(common_math_lib.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
+
+void main()
+{
+ ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
+
+ /* Find the minimum/maximum value in the circular window of the given radius around the pixel. By
+ * circular window, we mean that pixels in the window whose distance to the center of window is
+ * larger than the given radius are skipped and not considered. Consequently, the dilation or
+ * erosion that take place produces round results as opposed to squarish ones. This is
+ * essentially a morphological operator with a circular structuring element. The LIMIT value
+ * should be FLT_MAX if OPERATOR is min and FLT_MIN if OPERATOR is max. */
+ float value = LIMIT;
+ for (int y = -radius; y <= radius; y++) {
+ for (int x = -radius; x <= radius; x++) {
+ if (x * x + y * y <= radius * radius) {
+ value = OPERATOR(value, texture_load(input_tx, texel + ivec2(x, y), vec4(LIMIT)).x);
+ }
+ }
+ }
+
+ imageStore(output_img, texel, vec4(value));
+}