diff options
author | Omar Emara <mail@OmarEmara.dev> | 2022-08-18 18:14:29 +0300 |
---|---|---|
committer | Omar Emara <mail@OmarEmara.dev> | 2022-08-18 18:16:14 +0300 |
commit | 885e7abed13b204a701466a203f6d96773de902a (patch) | |
tree | e6f65aaf2ab2776d871025886d43d21117bc5717 /source/blender/nodes | |
parent | d8be33333f320ac8f21a3f67d361aee25fb78cd7 (diff) |
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
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc | 51 |
1 files changed, 50 insertions, 1 deletions
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<NodeBilateralBlurData *>(bnode().storage); } }; |