UV: support changing the opacity of the UV stretching overlay #117381

Merged
Jeroen Bakker merged 9 commits from Samuel-Bilek-1/blender:add_uv_stretching_opacity_prop into main 2024-02-20 11:03:49 +01:00
10 changed files with 42 additions and 10 deletions

View File

@ -1575,10 +1575,10 @@ class IMAGE_PT_overlay_guides(Panel):
layout.prop(uvedit, "tile_grid_shape", text="Tiles")
class IMAGE_PT_overlay_uv_edit(Panel):
class IMAGE_PT_overlay_uv_stretch(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'HEADER'
bl_label = "UV Editing"
bl_label = "UV Stretch"
bl_parent_id = "IMAGE_PT_overlay"
@classmethod
@ -1595,12 +1595,12 @@ class IMAGE_PT_overlay_uv_edit(Panel):
layout.active = overlay.show_overlays
# UV Stretching
row = layout.row()
row.prop(uvedit, "show_stretch")
subrow = row.row(align=True)
row = layout.row(align=True)
row.row().prop(uvedit, "show_stretch", text="")
subrow = row.row()
subrow.active = uvedit.show_stretch
subrow.prop(uvedit, "display_stretch_type", text="")
subrow.prop(uvedit, "stretch_opacity", text="Opacity")
class IMAGE_PT_overlay_uv_edit_geometry(Panel):
@ -1752,7 +1752,7 @@ classes = (
IMAGE_PT_gizmo_display,
IMAGE_PT_overlay,
IMAGE_PT_overlay_guides,
IMAGE_PT_overlay_uv_edit,
IMAGE_PT_overlay_uv_stretch,
IMAGE_PT_overlay_uv_edit_geometry,
IMAGE_PT_overlay_texture_paint,
IMAGE_PT_overlay_image,

View File

@ -29,7 +29,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 3
#define BLENDER_FILE_SUBVERSION 4
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@ -2938,6 +2938,21 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
FOREACH_NODETREE_END;
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 402, 4)) {
if (!DNA_struct_member_exists(fd->filesdna, "SpaceImage", "float", "stretch_opacity")) {
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)sl;
sima->stretch_opacity = 0.9f;
}
}
}
}
}
}
/**
* Always bump subversion in BKE_blender_version.h when adding versioning
* code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check.

View File

@ -161,6 +161,7 @@ void OVERLAY_edit_uv_init(OVERLAY_Data *vedata)
pd->edit_uv.do_uv_stretching_overlay = show_overlays && do_uvstretching_overlay;
pd->edit_uv.uv_opacity = sima->uv_opacity;
pd->edit_uv.stretch_opacity = sima->stretch_opacity;
pd->edit_uv.do_tiled_image_overlay = show_overlays && is_image_type && is_tiled_image;
pd->edit_uv.do_tiled_image_border_overlay = is_image_type && is_tiled_image;
pd->edit_uv.dash_length = 4.0f * UI_SCALE_FAC;
@ -284,6 +285,8 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata)
pd->edit_uv_stretching_grp = DRW_shgroup_create(sh, psl->edit_uv_stretching_ps);
DRW_shgroup_uniform_block(pd->edit_uv_stretching_grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_vec2_copy(pd->edit_uv_stretching_grp, "aspect", pd->edit_uv.uv_aspect);
DRW_shgroup_uniform_float_copy(
pd->edit_uv_stretching_grp, "stretch_opacity", pd->edit_uv.stretch_opacity);
}
else /* SI_UVDT_STRETCH_AREA */ {
GPUShader *sh = OVERLAY_shader_edit_uv_stretching_area_get();
@ -291,6 +294,8 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_block(pd->edit_uv_stretching_grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_float(
pd->edit_uv_stretching_grp, "totalAreaRatio", &pd->edit_uv.total_area_ratio, 1);
DRW_shgroup_uniform_float_copy(
pd->edit_uv_stretching_grp, "stretch_opacity", pd->edit_uv.stretch_opacity);
}
}

View File

@ -395,6 +395,8 @@ struct OVERLAY_PrivateData {
float uv_opacity;
float stretch_opacity;
int image_size[2];
float image_aspect[2];

View File

@ -379,6 +379,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_uv_mask_image)
GPU_SHADER_CREATE_INFO(overlay_edit_uv_stretching)
.vertex_in(0, Type::VEC2, "pos")
.push_constant(Type::VEC2, "aspect")
.push_constant(Type::FLOAT, "stretch_opacity")
.vertex_out(overlay_edit_nopersp_color_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("overlay_edit_uv_stretching_vert.glsl")

View File

@ -82,5 +82,5 @@ void main()
#endif
finalColor = vec4(weight_to_rgb(stretch), 1.0);
finalColor = vec4(weight_to_rgb(stretch), stretch_opacity);
}

View File

@ -101,6 +101,7 @@ static SpaceLink *image_create(const ScrArea * /*area*/, const Scene * /*scene*/
simage->lock = true;
simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA | SI_COORDFLOATS;
simage->uv_opacity = 1.0f;
simage->stretch_opacity = 1.0f;
simage->overlay.flag = SI_OVERLAY_SHOW_OVERLAYS | SI_OVERLAY_SHOW_GRID_BACKGROUND;
BKE_imageuser_default(&simage->iuser);

View File

@ -1267,12 +1267,14 @@ typedef struct SpaceImage {
char gizmo_flag;
char grid_shape_source;
char _pad1[2];
char _pad1[6];
int flag;
float uv_opacity;
float stretch_opacity;
int tile_grid_shape[2];
/**
* UV editor custom-grid. Value of `{M,N}` will produce `MxN` grid.

View File

@ -3720,6 +3720,12 @@ static void rna_def_space_image_uv(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "UV Opacity", "Opacity of UV overlays");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, nullptr);
prop = RNA_def_property(srna, "stretch_opacity", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, nullptr, "stretch_opacity");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Stretch Opacity", "Opacity of the UV Stretch overlay");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, nullptr);
prop = RNA_def_property(srna, "pixel_round_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, pixel_round_mode_items);
RNA_def_property_ui_text(prop, "Round to Pixels", "Round UVs to pixels while editing");