[Bf-blender-cvs] [bd01a87b752] temp-viewport-compositor-compiler: Viewport Compositor: Implemenet basic output nodes
Omar Emara
noreply at git.blender.org
Fri Feb 18 09:06:52 CET 2022
Commit: bd01a87b752cb31b7c2a57e5eb68b7afc39b2d75
Author: Omar Emara
Date: Thu Feb 17 11:33:10 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBbd01a87b752cb31b7c2a57e5eb68b7afc39b2d75
Viewport Compositor: Implemenet basic output nodes
This patch implemenets basic versions of the viewer and composite nodes.
It is unclear is the alpha and depth inputs should be utilized.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/intern/gpu_material_library.c
D source/blender/gpu/shaders/composite/gpu_shader_composite_composite.glsl
M source/blender/nodes/composite/node_composite_util.hh
M source/blender/nodes/composite/nodes/node_composite_composite.cc
M source/blender/nodes/composite/nodes/node_composite_viewer.cc
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 25fdd60c379..79ff424f533 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -291,7 +291,6 @@ set(GLSL_SRC
shaders/composite/gpu_shader_composite_color_matte.glsl
shaders/composite/gpu_shader_composite_color_spill.glsl
shaders/composite/gpu_shader_composite_color_to_luminance.glsl
- shaders/composite/gpu_shader_composite_composite.glsl
shaders/composite/gpu_shader_composite_difference_matte.glsl
shaders/composite/gpu_shader_composite_distance_matte.glsl
shaders/composite/gpu_shader_composite_ellipse_mask.glsl
diff --git a/source/blender/gpu/intern/gpu_material_library.c b/source/blender/gpu/intern/gpu_material_library.c
index 283622732a6..800cae3ca58 100644
--- a/source/blender/gpu/intern/gpu_material_library.c
+++ b/source/blender/gpu/intern/gpu_material_library.c
@@ -59,7 +59,6 @@ extern char datatoc_gpu_shader_composite_color_correction_glsl[];
extern char datatoc_gpu_shader_composite_color_matte_glsl[];
extern char datatoc_gpu_shader_composite_color_spill_glsl[];
extern char datatoc_gpu_shader_composite_color_to_luminance_glsl[];
-extern char datatoc_gpu_shader_composite_composite_glsl[];
extern char datatoc_gpu_shader_composite_difference_matte_glsl[];
extern char datatoc_gpu_shader_composite_distance_matte_glsl[];
extern char datatoc_gpu_shader_composite_ellipse_mask_glsl[];
@@ -255,11 +254,6 @@ static GPUMaterialLibrary gpu_shader_composite_color_to_luminance_library = {
.dependencies = {&gpu_shader_common_color_util_library, NULL},
};
-static GPUMaterialLibrary gpu_shader_composite_composite_library = {
- .code = datatoc_gpu_shader_composite_composite_glsl,
- .dependencies = {NULL},
-};
-
static GPUMaterialLibrary gpu_shader_composite_difference_matte_library = {
.code = datatoc_gpu_shader_composite_difference_matte_glsl,
.dependencies = {NULL},
@@ -862,7 +856,6 @@ static GPUMaterialLibrary *gpu_material_libraries[] = {
&gpu_shader_composite_color_matte_library,
&gpu_shader_composite_color_spill_library,
&gpu_shader_composite_color_to_luminance_library,
- &gpu_shader_composite_composite_library,
&gpu_shader_composite_difference_matte_library,
&gpu_shader_composite_distance_matte_library,
&gpu_shader_composite_ellipse_mask_library,
diff --git a/source/blender/gpu/shaders/composite/gpu_shader_composite_composite.glsl b/source/blender/gpu/shaders/composite/gpu_shader_composite_composite.glsl
deleted file mode 100644
index a0931f15cac..00000000000
--- a/source/blender/gpu/shaders/composite/gpu_shader_composite_composite.glsl
+++ /dev/null
@@ -1,5 +0,0 @@
-
-void node_composite(vec4 image, float alpha, float Z, out vec4 result)
-{
- result = image;
-}
diff --git a/source/blender/nodes/composite/node_composite_util.hh b/source/blender/nodes/composite/node_composite_util.hh
index 27a18592ebb..2a479034263 100644
--- a/source/blender/nodes/composite/node_composite_util.hh
+++ b/source/blender/nodes/composite/node_composite_util.hh
@@ -45,7 +45,6 @@
#include "RE_pipeline.h"
#include "NOD_composite.h"
-#include "NOD_compositor_execute.hh"
#include "NOD_socket.h"
#include "NOD_socket_declarations.hh"
diff --git a/source/blender/nodes/composite/nodes/node_composite_composite.cc b/source/blender/nodes/composite/nodes/node_composite_composite.cc
index b91fb979132..b1aceef85a7 100644
--- a/source/blender/nodes/composite/nodes/node_composite_composite.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_composite.cc
@@ -24,6 +24,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_texture.h"
+
+#include "NOD_compositor_execute.hh"
+
#include "node_composite_util.hh"
/* **************** COMPOSITE ******************** */
@@ -37,23 +41,35 @@ static void cmp_node_composite_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Float>(N_("Z")).default_value(1.0f).min(0.0f).max(1.0f);
}
-static int node_composit_gpu_composite(GPUMaterial *mat,
- bNode *node,
- bNodeExecData *UNUSED(execdata),
- GPUNodeStack *in,
- GPUNodeStack *out)
+static void node_composit_buts_composite(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
- GPUNodeLink *outlink;
+ uiItemR(layout, ptr, "use_alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
+}
- GPU_stack_link(mat, node, "node_composite", in, out, &outlink);
- GPU_material_output_surface(mat, outlink);
+using namespace blender::viewport_compositor;
- return true;
-}
+class CompositeOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
-static void node_composit_buts_composite(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+ void execute() override
+ {
+ const Result &input_image = get_input("Image");
+ GPUTexture *viewport_texture = context().get_viewport_texture();
+ if (get_input("Image").is_texture) {
+ /* If the input image is a texture, copy the input texture to the viewport texture. */
+ GPU_texture_copy(viewport_texture, input_image.data.texture);
+ }
+ else {
+ /* If the input image is a single color value, clear the viewport texture to that color. */
+ GPU_texture_clear(viewport_texture, GPU_DATA_FLOAT, input_image.data.color);
+ }
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
{
- uiItemR(layout, ptr, "use_alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
+ return new CompositeOperation(context, node);
}
} // namespace blender::nodes::node_composite_composite_cc
@@ -65,9 +81,9 @@ void register_node_type_cmp_composite()
static bNodeType ntype;
cmp_node_type_base(&ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT);
- node_type_gpu(&ntype, file_ns::node_composit_gpu_composite);
ntype.declare = file_ns::cmp_node_composite_declare;
ntype.draw_buttons = file_ns::node_composit_buts_composite;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.flag |= NODE_PREVIEW;
ntype.no_muting = true;
diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.cc b/source/blender/nodes/composite/nodes/node_composite_viewer.cc
index 6874c92cf11..73484e1d07e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_viewer.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_viewer.cc
@@ -29,6 +29,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_texture.h"
+
+#include "NOD_compositor_execute.hh"
+
#include "node_composite_util.hh"
/* **************** VIEWER ******************** */
@@ -53,20 +57,6 @@ static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node)
node->id = (ID *)BKE_image_ensure_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node");
}
-static int node_composit_gpu_viewer(GPUMaterial *mat,
- bNode *node,
- bNodeExecData *UNUSED(execdata),
- GPUNodeStack *in,
- GPUNodeStack *out)
-{
- GPUNodeLink *outlink;
-
- GPU_stack_link(mat, node, "node_composite", in, out, &outlink);
- GPU_material_output_surface(mat, outlink);
-
- return true;
-}
-
static void node_composit_buts_viewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
@@ -85,6 +75,32 @@ static void node_composit_buts_viewer_ex(uiLayout *layout, bContext *UNUSED(C),
}
}
+using namespace blender::viewport_compositor;
+
+class ViewerOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ const Result &input_image = get_input("Image");
+ GPUTexture *viewport_texture = context().get_viewport_texture();
+ if (get_input("Image").is_texture) {
+ /* If the input image is a texture, copy the input texture to the viewport texture. */
+ GPU_texture_copy(viewport_texture, input_image.data.texture);
+ }
+ else {
+ /* If the input image is a single color value, clear the viewport texture to that color. */
+ GPU_texture_clear(viewport_texture, GPU_DATA_FLOAT, input_image.data.color);
+ }
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ViewerOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_viewer_cc
void register_node_type_cmp_viewer()
@@ -100,7 +116,7 @@ void register_node_type_cmp_viewer()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_viewer);
node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
- node_type_gpu(&ntype, file_ns::node_composit_gpu_viewer);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.no_muting = true;
More information about the Bf-blender-cvs
mailing list