[Bf-blender-cvs] [4fb72170436] master: UDIM: Show the UV grid even when images are loaded

Jesse Yurkovich noreply at git.blender.org
Fri Sep 3 22:07:07 CEST 2021


Commit: 4fb7217043627ce952583d99c4b8537e10ee2903
Author: Jesse Yurkovich
Date:   Fri Sep 3 13:03:28 2021 -0700
Branches: master
https://developer.blender.org/rB4fb7217043627ce952583d99c4b8537e10ee2903

UDIM: Show the UV grid even when images are loaded

Allow the UDIM grid to be shown and adjusted when there are images
loaded in UV edit mode. Right now the grid feature disappears once an
image is loaded and many have found this to be confusing.

Based on community and artist feedback, there was support to change this
behavior[1]

This patch does the following:
- Allows the grid to be shown even when images are present
- The max allowable dimensions for the grid has been increased from
10x10 to 10x100 to match the underlying maximum UDIM range that blender
supports

Note: This should not affect other Image editor modes like Paint/Mask or
the Render Result viewer etc. Future work in this area is currently
documented in a dedicated design task[2]

[1] https://devtalk.blender.org/t/the-udim-tile-grid-design-and-feedback-thread/20136
[2] https://developer.blender.org/T90913

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

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

M	release/scripts/startup/bl_ui/space_image.py
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_grid.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/overlay_shader.c
A	source/blender/draw/engines/overlay/shaders/grid_background_frag.glsl
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index dcb0ab2e9e5..3ee668888f3 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -1453,7 +1453,7 @@ class IMAGE_PT_udim_grid(Panel):
     def poll(cls, context):
         sima = context.space_data
 
-        return sima.show_uvedit and sima.image is None
+        return sima.show_uvedit
 
     def draw(self, context):
         layout = self.layout
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 8bf74dae7f8..71115c5ceb9 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -447,6 +447,7 @@ data_to_c_simple(engines/overlay/shaders/extra_wire_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/extra_wire_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/facing_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/facing_vert.glsl SRC)
+data_to_c_simple(engines/overlay/shaders/grid_background_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/grid_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/grid_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/image_vert.glsl SRC)
diff --git a/source/blender/draw/engines/overlay/overlay_grid.c b/source/blender/draw/engines/overlay/overlay_grid.c
index 5bb157ed081..60cda9f2d61 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -61,10 +61,19 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 
   if (pd->space_type == SPACE_IMAGE) {
     SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
-    shd->grid_flag = ED_space_image_has_buffer(sima) ? 0 : PLANE_IMAGE | SHOW_GRID;
+    if (sima->mode == SI_MODE_UV || !ED_space_image_has_buffer(sima)) {
+      shd->grid_flag = GRID_BACK | PLANE_IMAGE | SHOW_GRID;
+    }
+    else {
+      shd->grid_flag = 0;
+    }
+
     shd->grid_distance = 1.0f;
-    copy_v3_fl3(
-        shd->grid_size, (float)sima->tile_grid_shape[0], (float)sima->tile_grid_shape[1], 1.0f);
+    copy_v3_fl3(shd->grid_size, 1.0f, 1.0f, 1.0f);
+    if (sima->mode == SI_MODE_UV) {
+      shd->grid_size[0] = (float)sima->tile_grid_shape[0];
+      shd->grid_size[1] = (float)sima->tile_grid_shape[1];
+    }
     for (int step = 0; step < 8; step++) {
       shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f);
     }
@@ -209,11 +218,12 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
     float mat[4][4];
 
     /* add quad background */
-    sh = OVERLAY_shader_grid_image();
+    sh = OVERLAY_shader_grid_background();
     grp = DRW_shgroup_create(sh, psl->grid_ps);
     float color_back[4];
     interp_v4_v4v4(color_back, G_draw.block.colorBackground, G_draw.block.colorGrid, 0.5);
     DRW_shgroup_uniform_vec4_copy(grp, "color", color_back);
+    DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
     unit_m4(mat);
     mat[0][0] = shd->grid_size[0];
     mat[1][1] = shd->grid_size[1];
diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h
index 68f60bee779..23df571e8de 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -722,6 +722,7 @@ GPUShader *OVERLAY_shader_extra_point(void);
 GPUShader *OVERLAY_shader_facing(void);
 GPUShader *OVERLAY_shader_gpencil_canvas(void);
 GPUShader *OVERLAY_shader_grid(void);
+GPUShader *OVERLAY_shader_grid_background(void);
 GPUShader *OVERLAY_shader_grid_image(void);
 GPUShader *OVERLAY_shader_image(void);
 GPUShader *OVERLAY_shader_motion_path_line(void);
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c
index edf9148c8c0..389704b3d66 100644
--- a/source/blender/draw/engines/overlay/overlay_shader.c
+++ b/source/blender/draw/engines/overlay/overlay_shader.c
@@ -91,6 +91,7 @@ extern char datatoc_extra_wire_frag_glsl[];
 extern char datatoc_extra_wire_vert_glsl[];
 extern char datatoc_facing_frag_glsl[];
 extern char datatoc_facing_vert_glsl[];
+extern char datatoc_grid_background_frag_glsl[];
 extern char datatoc_grid_frag_glsl[];
 extern char datatoc_grid_vert_glsl[];
 extern char datatoc_image_frag_glsl[];
@@ -198,6 +199,7 @@ typedef struct OVERLAY_Shaders {
   GPUShader *facing;
   GPUShader *gpencil_canvas;
   GPUShader *grid;
+  GPUShader *grid_background;
   GPUShader *grid_image;
   GPUShader *image;
   GPUShader *motion_path_line;
@@ -1053,6 +1055,20 @@ GPUShader *OVERLAY_shader_grid(void)
   return sh_data->grid;
 }
 
+GPUShader *OVERLAY_shader_grid_background(void)
+{
+  OVERLAY_Shaders *sh_data = &e_data.sh_data[0];
+  if (!sh_data->grid_background) {
+    sh_data->grid_background = GPU_shader_create_from_arrays({
+        .vert = (const char *[]){datatoc_common_view_lib_glsl,
+                                 datatoc_edit_uv_tiled_image_borders_vert_glsl,
+                                 NULL},
+        .frag = (const char *[]){datatoc_grid_background_frag_glsl, NULL},
+    });
+  }
+  return sh_data->grid_background;
+}
+
 GPUShader *OVERLAY_shader_grid_image(void)
 {
   OVERLAY_Shaders *sh_data = &e_data.sh_data[0];
diff --git a/source/blender/draw/engines/overlay/shaders/grid_background_frag.glsl b/source/blender/draw/engines/overlay/shaders/grid_background_frag.glsl
new file mode 100644
index 00000000000..fcc05414ea3
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/grid_background_frag.glsl
@@ -0,0 +1,12 @@
+
+uniform vec4 color;
+uniform sampler2D depthBuffer;
+
+out vec4 fragColor;
+
+void main()
+{
+    fragColor = color;
+    float scene_depth = texelFetch(depthBuffer, ivec2(gl_FragCoord.xy), 0).r;
+    fragColor.a = (scene_depth == 1.0) ? 1.0 : 0.0;
+}
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index d391b09189a..7aee6944d8d 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1796,6 +1796,16 @@ static const EnumPropertyItem *rna_SpaceImageEditor_pivot_itemf(bContext *UNUSED
   }
 }
 
+static void rna_SpaceUVEditor_tile_grid_shape_set(PointerRNA *ptr, const int *values)
+{
+  SpaceImage *data = (SpaceImage *)(ptr->data);
+
+  int clamp[2] = {10, 100};
+  for (int i = 0; i < 2; i++) {
+    data->tile_grid_shape[i] = CLAMPIS(values[i], 1, clamp[i]);
+  }
+}
+
 /* Space Text Editor */
 
 static void rna_SpaceTextEditor_word_wrap_set(PointerRNA *ptr, bool value)
@@ -3417,7 +3427,8 @@ static void rna_def_space_image_uv(BlenderRNA *brna)
   RNA_def_property_int_sdna(prop, NULL, "tile_grid_shape");
   RNA_def_property_array(prop, 2);
   RNA_def_property_int_default(prop, 1);
-  RNA_def_property_range(prop, 1, 10);
+  RNA_def_property_range(prop, 1, 100);
+  RNA_def_property_int_funcs(prop, NULL, "rna_SpaceUVEditor_tile_grid_shape_set", NULL);
   RNA_def_property_ui_text(
       prop, "Tile Grid Shape", "How many tiles will be shown in the background");
   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL);



More information about the Bf-blender-cvs mailing list