diff options
author | Michael Kowalski <makowalski@nvidia.com> | 2022-11-08 03:37:51 +0300 |
---|---|---|
committer | Michael Kowalski <makowalski@nvidia.com> | 2022-11-08 03:37:51 +0300 |
commit | a400935d29f54b9bd821d093873eb4643a279e59 (patch) | |
tree | 5dbd37ed111ee47c0dbe5696b834c3a16e96435c /source/blender/compositor/realtime_compositor/shaders/compositor_morphological_distance.glsl | |
parent | 036e10e5462b95ec6a12e9dd4a900ba7ff05032c (diff) | |
parent | d8dab1ba978e32af9af581fbd4c4bc0682278703 (diff) |
Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usdtmp-dynamic-usd
Diffstat (limited to 'source/blender/compositor/realtime_compositor/shaders/compositor_morphological_distance.glsl')
-rw-r--r-- | source/blender/compositor/realtime_compositor/shaders/compositor_morphological_distance.glsl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/compositor/realtime_compositor/shaders/compositor_morphological_distance.glsl b/source/blender/compositor/realtime_compositor/shaders/compositor_morphological_distance.glsl new file mode 100644 index 00000000000..09f896b7a9d --- /dev/null +++ b/source/blender/compositor/realtime_compositor/shaders/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)); +} |