Commit: dc44f844c9c59756990f9593cda1060b0094c722 Author: Omar Emara Date: Fri Apr 1 14:15:33 2022 +0200 Branches: temp-viewport-compositor-compiler https://developer.blender.org/rBdc44f844c9c59756990f9593cda1060b0094c722
Viewport Compositor: Implement Flip node =================================================================== M source/blender/gpu/CMakeLists.txt A source/blender/gpu/shaders/compositor/compositor_flip.glsl A source/blender/gpu/shaders/compositor/infos/compositor_flip_info.hh M source/blender/nodes/composite/nodes/node_composite_flip.cc =================================================================== diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 68a6b5d22c1..690c96bd940 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -312,6 +312,7 @@ set(GLSL_SRC shaders/compositor/compositor_alpha_crop.glsl shaders/compositor/compositor_convert.glsl shaders/compositor/compositor_filter.glsl + shaders/compositor/compositor_flip.glsl shaders/compositor/compositor_image_crop.glsl shaders/compositor/compositor_realize_on_domain.glsl shaders/compositor/compositor_split_viewer.glsl @@ -500,6 +501,7 @@ set(SHADER_CREATE_INFOS shaders/compositor/infos/compositor_alpha_crop_info.hh shaders/compositor/infos/compositor_convert_info.hh shaders/compositor/infos/compositor_filter_info.hh + shaders/compositor/infos/compositor_flip_info.hh shaders/compositor/infos/compositor_image_crop_info.hh shaders/compositor/infos/compositor_realize_on_domain_info.hh shaders/compositor/infos/compositor_split_viewer_info.hh diff --git a/source/blender/gpu/shaders/compositor/compositor_flip.glsl b/source/blender/gpu/shaders/compositor/compositor_flip.glsl new file mode 100644 index 00000000000..2f4d1374c1c --- /dev/null +++ b/source/blender/gpu/shaders/compositor/compositor_flip.glsl @@ -0,0 +1,15 @@ +#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utils.glsl) + +void main() +{ + ivec2 xy = ivec2(gl_GlobalInvocationID.xy); + ivec2 size = texture_size(input_image); + ivec2 flipped_xy = xy; +#if defined(FLIP_X) + flipped_xy.x = size.x - xy.x - 1; +#endif +#if defined(FLIP_Y) + flipped_xy.y = size.y - xy.y - 1; +#endif + imageStore(output_image, xy, texture_load(input_image, flipped_xy)); +} diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_flip_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_flip_info.hh new file mode 100644 index 00000000000..0f27c5b1676 --- /dev/null +++ b/source/blender/gpu/shaders/compositor/infos/compositor_flip_info.hh @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 Blender Foundation. All rights reserved. */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(compositor_flip_shared) + .local_group_size(16, 16) + .sampler(0, ImageType::FLOAT_2D, "input_image") + .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image") + .compute_source("compositor_flip.glsl"); + +GPU_SHADER_CREATE_INFO(compositor_flip_x) + .additional_info("compositor_flip_shared") + .define("FLIP_X") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(compositor_flip_y) + .additional_info("compositor_flip_shared") + .define("FLIP_Y") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(compositor_flip_x_and_y) + .additional_info("compositor_flip_shared") + .define("FLIP_X") + .define("FLIP_Y") + .do_static_compilation(true); diff --git a/source/blender/nodes/composite/nodes/node_composite_flip.cc b/source/blender/nodes/composite/nodes/node_composite_flip.cc index dba98a42e93..0e2384a8d5d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_flip.cc +++ b/source/blender/nodes/composite/nodes/node_composite_flip.cc @@ -21,9 +21,17 @@ * \ingroup cmpnodes */ +#include "BLI_assert.h" + #include "UI_interface.h" #include "UI_resources.h" +#include "GPU_compute.h" +#include "GPU_shader.h" +#include "GPU_texture.h" + +#include "NOD_compositor_execute.hh" + #include "node_composite_util.hh" /* **************** Flip ******************** */ @@ -32,7 +40,9 @@ namespace blender::nodes::node_composite_flip_cc { static void cmp_node_flip_declare(NodeDeclarationBuilder &b) { - b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f}); + b.add_input<decl::Color>(N_("Image")) + .default_value({1.0f, 1.0f, 1.0f, 1.0f}) + .compositor_domain_priority(0); b.add_output<decl::Color>(N_("Image")); } @@ -41,6 +51,68 @@ static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), Point uiItemR(layout, ptr, "axis", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE); } +using namespace blender::viewport_compositor; + +class FlipOperation : public NodeOperation { + public: + using NodeOperation::NodeOperation; + + void execute() override + { + Result &input = get_input("Image"); + Result &result = get_result("Image"); + + /* Can't flip a single value, pass it through to the output. */ + if (input.is_single_value()) { + input.pass_through(result); + } + + GPUShader *shader = get_flip_shader(); + GPU_shader_bind(shader); + + input.bind_as_texture(shader, "input_image"); + + result.allocate_texture(compute_domain()); + result.bind_as_image(shader, "output_image"); + + const int2 size = compute_domain().size; + GPU_compute_dispatch(shader, size.x / 16 + 1, size.y / 16 + 1, 1); + + input.unbind_as_texture(); + result.unbind_as_image(); + GPU_shader_unbind(); + GPU_shader_free(shader); + } + + GPUShader *get_flip_shader() + { + switch (get_flip_mode()) { + case 0: + return GPU_shader_create_from_info_name("compositor_flip_x"); + case 1: + return GPU_shader_create_from_info_name("compositor_flip_y"); + case 2: + return GPU_shader_create_from_info_name("compositor_flip_x_and_y"); + } + + BLI_assert_unreachable(); + return nullptr; + } + + /* 0 -> Flip along x. + * 1 -> Flip along y. + * 2 -> Flip along both x and y. */ + int get_flip_mode() + { + return node().custom1; + } +}; + +static NodeOperation *get_compositor_operation(Context &context, DNode node) +{ + return new FlipOperation(context, node); +} + } // namespace blender::nodes::node_composite_flip_cc void register_node_type_cmp_flip() @@ -52,6 +124,7 @@ void register_node_type_cmp_flip() cmp_node_type_base(&ntype, CMP_NODE_FLIP, "Flip", NODE_CLASS_DISTORT); ntype.declare = file_ns::cmp_node_flip_declare; ntype.draw_buttons = file_ns::node_composit_buts_flip; + ntype.get_compositor_operation = file_ns::get_compositor_operation; nodeRegisterType(&ntype); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs