[Bf-blender-cvs] [cc78fd4e936] master: Realtime Compositor: Allow limited compositing region

Omar Emara noreply at git.blender.org
Fri Jan 6 13:43:41 CET 2023


Commit: cc78fd4e9364338126e5145ff96ae6c544939042
Author: Omar Emara
Date:   Fri Jan 6 14:42:00 2023 +0200
Branches: master
https://developer.blender.org/rBcc78fd4e9364338126e5145ff96ae6c544939042

Realtime Compositor: Allow limited compositing region

This patch allows the realtime compositor to be limited to a specific
compositing region that is a subset of the full render region. In the
context of the viewport compositor, when the viewport is in camera view
and has a completely opaque passepartout, the compositing region will be
limited to the visible camera region.

On the user-level, this gives the user the ability to make the result of
the compositor invariant of the aspect ratio, shift, and zoom of the
viewport, making the result in the viewport identical to the final
render compositor assuming size relative operations.

It should be noted that compositing region is the *visible* camera
region, that is, the result of the intersection of the camera region and
the render region. So the user should be careful not to shift or zoom
the view such that the camera border extends outside of the viewport to
have the aforementioned benefits. While we could implement logic to fill
the areas outside of the render region with zeros in some cases, there
are many other ambiguous cases where such a solution wouldn't work,
including the problematic case where the user zooms in very close,
making the camera region much bigger than that of the render region.

Differential Revision: https://developer.blender.org/D16899

Reviewed By: Clement Foucault

===================================================================

M	source/blender/compositor/realtime_compositor/CMakeLists.txt
M	source/blender/compositor/realtime_compositor/COM_context.hh
M	source/blender/compositor/realtime_compositor/intern/context.cc
A	source/blender/compositor/realtime_compositor/shaders/compositor_read_pass.glsl
D	source/blender/compositor/realtime_compositor/shaders/compositor_set_alpha.glsl
M	source/blender/compositor/realtime_compositor/shaders/compositor_split_viewer.glsl
A	source/blender/compositor/realtime_compositor/shaders/compositor_write_output.glsl
M	source/blender/compositor/realtime_compositor/shaders/infos/compositor_convert_info.hh
A	source/blender/compositor/realtime_compositor/shaders/infos/compositor_read_pass_info.hh
D	source/blender/compositor/realtime_compositor/shaders/infos/compositor_set_alpha_info.hh
M	source/blender/compositor/realtime_compositor/shaders/infos/compositor_split_viewer_info.hh
A	source/blender/compositor/realtime_compositor/shaders/infos/compositor_write_output_info.hh
M	source/blender/draw/engines/compositor/compositor_engine.cc
M	source/blender/nodes/composite/nodes/node_composite_boxmask.cc
M	source/blender/nodes/composite/nodes/node_composite_composite.cc
M	source/blender/nodes/composite/nodes/node_composite_ellipsemask.cc
M	source/blender/nodes/composite/nodes/node_composite_image.cc
M	source/blender/nodes/composite/nodes/node_composite_scale.cc
M	source/blender/nodes/composite/nodes/node_composite_split_viewer.cc
M	source/blender/nodes/composite/nodes/node_composite_viewer.cc

===================================================================

diff --git a/source/blender/compositor/realtime_compositor/CMakeLists.txt b/source/blender/compositor/realtime_compositor/CMakeLists.txt
index 5826c70793c..f9739972690 100644
--- a/source/blender/compositor/realtime_compositor/CMakeLists.txt
+++ b/source/blender/compositor/realtime_compositor/CMakeLists.txt
@@ -116,15 +116,16 @@ set(GLSL_SRC
   shaders/compositor_normalize.glsl
   shaders/compositor_parallel_reduction.glsl
   shaders/compositor_projector_lens_distortion.glsl
+  shaders/compositor_read_pass.glsl
   shaders/compositor_realize_on_domain.glsl
   shaders/compositor_screen_lens_distortion.glsl
-  shaders/compositor_set_alpha.glsl
   shaders/compositor_split_viewer.glsl
   shaders/compositor_symmetric_blur.glsl
   shaders/compositor_symmetric_blur_variable_size.glsl
   shaders/compositor_symmetric_separable_blur.glsl
   shaders/compositor_tone_map_photoreceptor.glsl
   shaders/compositor_tone_map_simple.glsl
+  shaders/compositor_write_output.glsl
 
   shaders/library/gpu_shader_compositor_alpha_over.glsl
   shaders/library/gpu_shader_compositor_blur_common.glsl
@@ -204,15 +205,16 @@ set(SRC_SHADER_CREATE_INFOS
   shaders/infos/compositor_normalize_info.hh
   shaders/infos/compositor_parallel_reduction_info.hh
   shaders/infos/compositor_projector_lens_distortion_info.hh
+  shaders/infos/compositor_read_pass_info.hh
   shaders/infos/compositor_realize_on_domain_info.hh
   shaders/infos/compositor_screen_lens_distortion_info.hh
-  shaders/infos/compositor_set_alpha_info.hh
   shaders/infos/compositor_split_viewer_info.hh
   shaders/infos/compositor_symmetric_blur_info.hh
   shaders/infos/compositor_symmetric_blur_variable_size_info.hh
   shaders/infos/compositor_symmetric_separable_blur_info.hh
   shaders/infos/compositor_tone_map_photoreceptor_info.hh
   shaders/infos/compositor_tone_map_simple_info.hh
+  shaders/infos/compositor_write_output_info.hh
 )
 
 set(SHADER_CREATE_INFOS_CONTENT "")
diff --git a/source/blender/compositor/realtime_compositor/COM_context.hh b/source/blender/compositor/realtime_compositor/COM_context.hh
index 80fb4f70ca4..7be89bfeb0e 100644
--- a/source/blender/compositor/realtime_compositor/COM_context.hh
+++ b/source/blender/compositor/realtime_compositor/COM_context.hh
@@ -6,6 +6,7 @@
 #include "BLI_string_ref.hh"
 
 #include "DNA_scene_types.h"
+#include "DNA_vec_types.h"
 
 #include "GPU_texture.h"
 
@@ -41,8 +42,17 @@ class Context {
   /* Get the active compositing scene. */
   virtual const Scene *get_scene() const = 0;
 
-  /* Get the dimensions of the output. */
-  virtual int2 get_output_size() = 0;
+  /* Get the width and height of the render passes and of the output texture returned by the
+   * get_input_texture and get_output_texture methods respectively. */
+  virtual int2 get_render_size() const = 0;
+
+  /* Get the rectangular region representing the area of the input that the compositor will operate
+   * on. Conversely, the compositor will only update the region of the output that corresponds to
+   * the compositing region. In the base case, the compositing region covers the entirety of the
+   * render region with a lower bound of zero and an upper bound of the render size returned by the
+   * get_render_size method. In other cases, the compositing region might be a subset of the render
+   * region. */
+  virtual rcti get_compositing_region() const = 0;
 
   /* Get the texture representing the output where the result of the compositor should be
    * written. This should be called by output nodes to get their target texture. */
@@ -60,6 +70,9 @@ class Context {
    * appropriate place, which can be directly in the UI or just logged to the output stream. */
   virtual void set_info_message(StringRef message) const = 0;
 
+  /* Get the size of the compositing region. See get_compositing_region(). */
+  int2 get_compositing_region_size() const;
+
   /* Get the current frame number of the active scene. */
   int get_frame_number() const;
 
diff --git a/source/blender/compositor/realtime_compositor/intern/context.cc b/source/blender/compositor/realtime_compositor/intern/context.cc
index 0b123a2c271..a53c839c365 100644
--- a/source/blender/compositor/realtime_compositor/intern/context.cc
+++ b/source/blender/compositor/realtime_compositor/intern/context.cc
@@ -1,5 +1,9 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
+#include "BLI_rect.h"
+
+#include "DNA_vec_types.h"
+
 #include "COM_context.hh"
 #include "COM_static_cache_manager.hh"
 #include "COM_static_shader_manager.hh"
@@ -11,6 +15,12 @@ Context::Context(TexturePool &texture_pool) : texture_pool_(texture_pool)
 {
 }
 
+int2 Context::get_compositing_region_size() const
+{
+  const rcti compositing_region = get_compositing_region();
+  return int2(BLI_rcti_size_x(&compositing_region), BLI_rcti_size_y(&compositing_region));
+}
+
 int Context::get_frame_number() const
 {
   return get_scene()->r.cfra;
diff --git a/source/blender/compositor/realtime_compositor/shaders/compositor_read_pass.glsl b/source/blender/compositor/realtime_compositor/shaders/compositor_read_pass.glsl
new file mode 100644
index 00000000000..ff8b33af655
--- /dev/null
+++ b/source/blender/compositor/realtime_compositor/shaders/compositor_read_pass.glsl
@@ -0,0 +1,8 @@
+#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
+
+void main()
+{
+  ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
+  vec4 pass_color = texture_load(input_tx, texel + compositing_region_lower_bound);
+  imageStore(output_img, texel, READ_EXPRESSION(pass_color));
+}
diff --git a/source/blender/compositor/realtime_compositor/shaders/compositor_set_alpha.glsl b/source/blender/compositor/realtime_compositor/shaders/compositor_set_alpha.glsl
deleted file mode 100644
index 7dd40581790..00000000000
--- a/source/blender/compositor/realtime_compositor/shaders/compositor_set_alpha.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
-
-void main()
-{
-  ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
-  vec4 color = vec4(texture_load(image_tx, texel).rgb, texture_load(alpha_tx, texel).x);
-  imageStore(output_img, texel, color);
-}
diff --git a/source/blender/compositor/realtime_compositor/shaders/compositor_split_viewer.glsl b/source/blender/compositor/realtime_compositor/shaders/compositor_split_viewer.glsl
index 866b9045da2..4ed378e9ec4 100644
--- a/source/blender/compositor/realtime_compositor/shaders/compositor_split_viewer.glsl
+++ b/source/blender/compositor/realtime_compositor/shaders/compositor_split_viewer.glsl
@@ -10,5 +10,5 @@ void main()
 #endif
   vec4 color = condition ? texture_load(first_image_tx, texel) :
                            texture_load(second_image_tx, texel);
-  imageStore(output_img, texel, color);
+  imageStore(output_img, texel + compositing_region_lower_bound, color);
 }
diff --git a/source/blender/compositor/realtime_compositor/shaders/compositor_write_output.glsl b/source/blender/compositor/realtime_compositor/shaders/compositor_write_output.glsl
new file mode 100644
index 00000000000..d22e2a9ee67
--- /dev/null
+++ b/source/blender/compositor/realtime_compositor/shaders/compositor_write_output.glsl
@@ -0,0 +1,18 @@
+#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
+
+void main()
+{
+  ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
+  vec4 input_color = texture_load(input_tx, texel);
+
+#if defined(DIRECT_OUTPUT)
+  vec4 output_color = input_color;
+#elif defined(OPAQUE_OUTPUT)
+  vec4 output_color = vec4(input_color.rgb, 1.0);
+#elif defined(ALPHA_OUTPUT)
+  float alpha = texture_load(alpha_tx, texel).x;
+  vec4 output_color = vec4(input_color.rgb, alpha);
+#endif
+
+  imageStore(output_img, texel + compositing_region_lower_bound, output_color);
+}
diff --git a/source/blender/compositor/realtime_compositor/shaders/infos/compositor_convert_info.hh b/source/blender/compositor/realtime_compositor/shaders/infos/compositor_convert_info.hh
index 35e60056736..235525b582b 100644
--- a/source/blender/compositor/realtime_compositor/shaders/infos/compositor_convert_info.hh
+++ b/source/blender/compositor/realtime_compositor/shaders/infos/compositor_convert_info.hh
@@ -61,9 +61,3 @@ GPU_SHADER_CREATE_INFO(compositor_convert_float_to_half_float)
     .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
     .define("CONVERT_EXPRESSION(value)", "vec4(value.r, vec3(0.0))")
     .do_static_compilation(true);
-
-GPU_SHADER_CREATE_INFO(compositor_convert_color_to_opaque)
-    .additional_info("compositor_convert_shared")
-    .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
-    .define("CONVERT_EXPRESSION(value)", "vec4(value.rgb, 1.0)")
-    .do_static_compilation(true);
diff --git a/source/blender/compositor/realtime_compositor/shaders/infos/compositor_read_pass_info.hh b/source/blender/compositor/realtime_compositor/shaders/infos/compositor_read_pass_info.hh
new file mode 100644
index 00000000000..e3e2d43f6f8
--- /dev/null
+++ b/source/blender/compositor/realtime_compositor/shaders/infos/compositor_read_pass_info.hh
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "gpu_shader_create_info.hh"
+
+GPU_SHADER_CREATE_INFO(compositor_read_pass_shared)
+    .local_group_size(16, 16)
+    .push_constant(Type::IVEC2, "compositing_region_lower_bound")
+    .sampler(0, ImageType::FLOAT_2D, "input_tx")
+    .compute_source("compositor_read_pass.glsl");
+
+GPU_SHADER_CREATE_INFO(compositor_read_pass)
+    .additional_info("compositor_read_pass_shared")
+    .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
+    .define("READ_EXPRESSION(pass_color)", "pass_color")
+    .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(compositor_read_pass_alpha)
+    .additional_info("compositor_read_pass_shared")
+    .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
+    .define("READ_EXPRESSION(pass_color)", "vec4(pass_color.a, vec3(0.0))")
+    .do_static_compilation(true);
diff --git a/source/blender/compositor/realtime_compositor/shaders/infos/compositor_set_alpha_info.hh b/source/blender/compositor/realtime_compositor/shaders/infos/compositor_set_alpha_info.hh
deleted file mode 100644
index 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list