From 885e7abed13b204a701466a203f6d96773de902a Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Thu, 18 Aug 2022 17:14:29 +0200 Subject: Realtime Compositor: Implement bilateral blur node This patch implements the bilateral blur node for the realtime compositor. Differential Revision: https://developer.blender.org/D15674 Reviewed By: Clement Foucault --- .../nodes/node_composite_bilateralblur.cc | 51 +++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc index 66a321eb088..355ec42f221 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc +++ b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc @@ -5,10 +5,15 @@ * \ingroup cmpnodes */ +#include "BLI_math_base.hh" + #include "UI_interface.h" #include "UI_resources.h" +#include "GPU_shader.h" + #include "COM_node_operation.hh" +#include "COM_utilities.hh" #include "node_composite_util.hh" @@ -52,7 +57,51 @@ class BilateralBlurOperation : public NodeOperation { void execute() override { - get_input("Image").pass_through(get_result("Image")); + const Result &input_image = get_input("Image"); + /* Single value inputs can't be blurred and are returned as is. */ + if (input_image.is_single_value()) { + get_input("Image").pass_through(get_result("Image")); + return; + } + + GPUShader *shader = shader_manager().get("compositor_bilateral_blur"); + GPU_shader_bind(shader); + + GPU_shader_uniform_1i(shader, "radius", get_blur_radius()); + GPU_shader_uniform_1f(shader, "threshold", get_threshold()); + + input_image.bind_as_texture(shader, "input_tx"); + + const Result &determinator_image = get_input("Determinator"); + determinator_image.bind_as_texture(shader, "determinator_tx"); + + const Domain domain = compute_domain(); + Result &output_image = get_result("Image"); + output_image.allocate_texture(domain); + output_image.bind_as_image(shader, "output_img"); + + compute_dispatch_threads_at_least(shader, domain.size); + + GPU_shader_unbind(); + output_image.unbind_as_image(); + input_image.unbind_as_texture(); + determinator_image.unbind_as_texture(); + } + + int get_blur_radius() + { + return math::ceil(get_node_bilateral_blur_data().iter + + get_node_bilateral_blur_data().sigma_space); + } + + float get_threshold() + { + return get_node_bilateral_blur_data().sigma_color; + } + + NodeBilateralBlurData &get_node_bilateral_blur_data() + { + return *static_cast(bnode().storage); } }; -- cgit v1.2.3