[Bf-blender-cvs] [d2a102214d2] temp-viewport-compositor-compiler: Viewport Compositor: Fix off by one error in Crop node

Omar Emara noreply at git.blender.org
Fri Apr 1 14:24:25 CEST 2022


Commit: d2a102214d24941eef86115d44268edcbfc24a88
Author: Omar Emara
Date:   Fri Apr 1 14:23:52 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBd2a102214d24941eef86115d44268edcbfc24a88

Viewport Compositor: Fix off by one error in Crop node

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

M	source/blender/gpu/shaders/compositor/compositor_alpha_crop.glsl
M	source/blender/gpu/shaders/compositor/infos/compositor_alpha_crop_info.hh
M	source/blender/nodes/composite/nodes/node_composite_crop.cc

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

diff --git a/source/blender/gpu/shaders/compositor/compositor_alpha_crop.glsl b/source/blender/gpu/shaders/compositor/compositor_alpha_crop.glsl
index 344d34b30d4..ff75993c17e 100644
--- a/source/blender/gpu/shaders/compositor/compositor_alpha_crop.glsl
+++ b/source/blender/gpu/shaders/compositor/compositor_alpha_crop.glsl
@@ -3,8 +3,9 @@
 void main()
 {
   ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
+  /* The lower bound is inclusive and upper bound is exclusive. */
+  bool is_inside = all(greaterThanEqual(xy, lower_bound)) && all(lessThan(xy, upper_bound));
   /* Write the pixel color if it is inside the cropping region, otherwise, write zero. */
-  bool is_inside = all(greaterThan(xy, lower_bound)) && all(lessThan(xy, higher_bound));
   vec4 color = is_inside ? texture_load(input_image, xy) : vec4(0.0);
   imageStore(output_image, xy, color);
 }
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_alpha_crop_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_alpha_crop_info.hh
index 0f0be5f95bb..5b1c0451c33 100644
--- a/source/blender/gpu/shaders/compositor/infos/compositor_alpha_crop_info.hh
+++ b/source/blender/gpu/shaders/compositor/infos/compositor_alpha_crop_info.hh
@@ -6,7 +6,7 @@
 GPU_SHADER_CREATE_INFO(compositor_alpha_crop)
     .local_group_size(16, 16)
     .push_constant(Type::IVEC2, "lower_bound")
-    .push_constant(Type::IVEC2, "higher_bound")
+    .push_constant(Type::IVEC2, "upper_bound")
     .sampler(0, ImageType::FLOAT_2D, "input_image")
     .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
     .compute_source("compositor_alpha_crop.glsl")
diff --git a/source/blender/nodes/composite/nodes/node_composite_crop.cc b/source/blender/nodes/composite/nodes/node_composite_crop.cc
index 6d978389cfb..b0d68ddf7d7 100644
--- a/source/blender/nodes/composite/nodes/node_composite_crop.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_crop.cc
@@ -111,10 +111,10 @@ class CropOperation : public NodeOperation {
     GPUShader *shader = GPU_shader_create_from_info_name("compositor_alpha_crop");
     GPU_shader_bind(shader);
 
-    int2 lower_bound, higher_bound;
-    compute_cropping_bounds(lower_bound, higher_bound);
+    int2 lower_bound, upper_bound;
+    compute_cropping_bounds(lower_bound, upper_bound);
     GPU_shader_uniform_2iv(shader, "lower_bound", lower_bound);
-    GPU_shader_uniform_2iv(shader, "higher_bound", higher_bound);
+    GPU_shader_uniform_2iv(shader, "upper_bound", upper_bound);
 
     const Result &input_image = get_input("Image");
     input_image.bind_as_texture(shader, "input_image");
@@ -135,11 +135,11 @@ class CropOperation : public NodeOperation {
   /* Crop the image into a new size that matches the cropping bounds. */
   void execute_image_crop()
   {
-    int2 lower_bound, higher_bound;
-    compute_cropping_bounds(lower_bound, higher_bound);
+    int2 lower_bound, upper_bound;
+    compute_cropping_bounds(lower_bound, upper_bound);
 
     /* The image is cropped into nothing, so just return a single zero value. */
-    if (lower_bound.x == higher_bound.x || lower_bound.y == higher_bound.y) {
+    if (lower_bound.x == upper_bound.x || lower_bound.y == upper_bound.y) {
       Result &result = get_result("Image");
       result.allocate_single_value();
       result.set_color_value(float4(0.0f));
@@ -154,7 +154,7 @@ class CropOperation : public NodeOperation {
     const Result &input_image = get_input("Image");
     input_image.bind_as_texture(shader, "input_image");
 
-    const int2 size = higher_bound - lower_bound;
+    const int2 size = upper_bound - lower_bound;
 
     Result &output_image = get_result("Image");
     output_image.allocate_texture(Domain(size, compute_domain().transformation));
@@ -194,18 +194,18 @@ class CropOperation : public NodeOperation {
       return true;
     }
 
-    int2 lower_bound, higher_bound;
-    compute_cropping_bounds(lower_bound, higher_bound);
+    int2 lower_bound, upper_bound;
+    compute_cropping_bounds(lower_bound, upper_bound);
     const int2 input_size = input.domain().size;
     /* The cropping bounds cover the whole image, so no cropping happens. */
-    if (lower_bound == int2(0) && higher_bound == input_size) {
+    if (lower_bound == int2(0) && upper_bound == input_size) {
       return true;
     }
 
     return false;
   }
 
-  void compute_cropping_bounds(int2 &lower_bound, int2 &higher_bound)
+  void compute_cropping_bounds(int2 &lower_bound, int2 &upper_bound)
   {
     const NodeTwoXYs &node_two_xys = get_node_two_xys();
     const int2 input_size = get_input("Image").domain().size;
@@ -215,22 +215,22 @@ class CropOperation : public NodeOperation {
        * so it is guaranteed that they won't go over the input image size. */
       lower_bound.x = input_size.x * node_two_xys.fac_x1;
       lower_bound.y = input_size.y * node_two_xys.fac_y2;
-      higher_bound.x = input_size.x * node_two_xys.fac_x2;
-      higher_bound.y = input_size.y * node_two_xys.fac_y1;
+      upper_bound.x = input_size.x * node_two_xys.fac_x2;
+      upper_bound.y = input_size.y * node_two_xys.fac_y1;
     }
     else {
       /* Make sure the bounds don't go over the input image size. */
       lower_bound.x = min_ii(node_two_xys.x1, input_size.x);
       lower_bound.y = min_ii(node_two_xys.y2, input_size.y);
-      higher_bound.x = min_ii(node_two_xys.x2, input_size.x);
-      higher_bound.y = min_ii(node_two_xys.y1, input_size.y);
+      upper_bound.x = min_ii(node_two_xys.x2, input_size.x);
+      upper_bound.y = min_ii(node_two_xys.y1, input_size.y);
     }
 
-    /* Make sure higher bound is actually higher than the lower bound. */
-    lower_bound.x = min_ii(lower_bound.x, higher_bound.x);
-    lower_bound.y = min_ii(lower_bound.y, higher_bound.y);
-    higher_bound.x = max_ii(lower_bound.x, higher_bound.x);
-    higher_bound.y = max_ii(lower_bound.y, higher_bound.y);
+    /* Make sure upper bound is actually higher than the lower bound. */
+    lower_bound.x = min_ii(lower_bound.x, upper_bound.x);
+    lower_bound.y = min_ii(lower_bound.y, upper_bound.y);
+    upper_bound.x = max_ii(lower_bound.x, upper_bound.x);
+    upper_bound.y = max_ii(lower_bound.y, upper_bound.y);
   }
 };



More information about the Bf-blender-cvs mailing list