From 6fe2bbd51c75dbafa15acee13e8c8e80e7cc9b7f Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Mon, 29 Jan 2024 20:13:04 +0200 Subject: [PATCH] Realtime Compositor: Anti-alias morphological threshold This patch anti-aliases the output of the morphological threshold operation in the Dilate/Erode node. This is done to match the CPU implementation. --- .../nodes/composite/nodes/node_composite_dilate.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/blender/nodes/composite/nodes/node_composite_dilate.cc b/source/blender/nodes/composite/nodes/node_composite_dilate.cc index 0535be74d97..ac92052660c 100644 --- a/source/blender/nodes/composite/nodes/node_composite_dilate.cc +++ b/source/blender/nodes/composite/nodes/node_composite_dilate.cc @@ -21,6 +21,7 @@ #include "COM_algorithm_morphological_distance.hh" #include "COM_algorithm_morphological_distance_feather.hh" +#include "COM_algorithm_smaa.hh" #include "COM_node_operation.hh" #include "COM_utilities.hh" @@ -195,7 +196,7 @@ class DilateErodeOperation : public NodeOperation { input_mask.bind_as_texture(shader, "input_tx"); const Domain domain = compute_domain(); - Result &output_mask = get_result("Mask"); + Result output_mask = context().create_temporary_result(ResultType::Float); output_mask.allocate_texture(domain); output_mask.bind_as_image(shader, "output_img"); @@ -204,6 +205,17 @@ class DilateErodeOperation : public NodeOperation { GPU_shader_unbind(); output_mask.unbind_as_image(); input_mask.unbind_as_texture(); + + /* For configurations where there is little user-specified inset, anti-alias the result for + * smoother edges. */ + Result &output = get_result("Mask"); + if (get_inset() < 2.0f) { + smaa(context(), output_mask, output); + output_mask.release(); + } + else { + output.steal_data(output_mask); + } } /* See the discussion in the implementation for more information. */