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
This commit is contained in:
Jesse Yurkovich 2021-09-03 13:03:28 -07:00
parent 235655ee0d
commit 4fb7217043
Notes: blender-bot 2024-02-09 15:21:23 +01:00
Referenced by issue #90913, UDIM grid changes and enhancements
Referenced by issue #86873, UV Editor UDIM GRID disappear when add new image
Referenced by issue #118033, UV Grid only tiles 10 in X but can tile 100 in Y. Should be 100 in both.
7 changed files with 57 additions and 6 deletions

View File

@ -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

View File

@ -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)

View File

@ -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];

View File

@ -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);

View File

@ -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];

View File

@ -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;
}

View File

@ -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);