Mask Editor: Add mask blending factor for combined overlay

This adds a new parameter to the "Combined" overlay mode of the mask editor.
The "blending factor" allows users to blend the mask exterior with the original
footage to visualise the content of the mask in a more intuitive way.  The
"Alpha" overlay is unaffected by this change.

The existing "Combined" overlay is used like before (covering everything
outside the mask in black), but can be blended with the slider in the mask
overlay to look at the exterior.

This is part of an effort to make mask editing more intuitive & easy to use:
https://developer.blender.org/T93097

Differential Revision: https://developer.blender.org/D13284
This commit is contained in:
Simon Lenz 2022-06-15 15:15:23 +02:00 committed by Sergey Sharybin
parent 72a5bb8ba9
commit eca0c95d51
Notes: blender-bot 2023-02-14 04:46:12 +01:00
Referenced by issue #101795, Blending Factor Slider in Image Editors not working
11 changed files with 46 additions and 7 deletions

View File

@ -239,6 +239,9 @@ class MASK_PT_display:
sub = row.row()
sub.active = space_data.show_mask_overlay
sub.prop(space_data, "mask_overlay_mode", text="")
row = layout.row()
row.active = (space_data.mask_overlay_mode in ['COMBINED'] and space_data.show_mask_overlay)
row.prop(space_data, "blend_factor", text="Blending Factor")
class MASK_PT_transforms:

View File

@ -25,7 +25,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 1
#define BLENDER_FILE_SUBVERSION 2
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -3084,6 +3084,18 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
FOREACH_NODETREE_END;
}
if (!MAIN_VERSION_ATLEAST(bmain, 303, 2)) {
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_CLIP) {
((SpaceClip *)sl)->mask_info.blend_factor = 1.0;
}
}
}
}
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -184,6 +184,7 @@ static void blo_update_defaults_screen(bScreen *screen,
else if (area->spacetype == SPACE_CLIP) {
SpaceClip *sclip = area->spacedata.first;
sclip->around = V3D_AROUND_CENTER_MEDIAN;
sclip->mask_info.blend_factor = 0.7f;
}
}

View File

@ -86,6 +86,7 @@ void ED_mask_draw_region(struct Depsgraph *depsgraph,
char draw_flag,
char draw_type,
eMaskOverlayMode overlay_mode,
float blend_factor,
int width_i,
int height_i,
float aspx,

View File

@ -663,6 +663,7 @@ void ED_mask_draw_region(
const char draw_flag,
const char draw_type,
const eMaskOverlayMode overlay_mode,
const float blend_factor,
/* convert directly into aspect corrected vars */
const int width_i,
const int height_i,
@ -721,12 +722,14 @@ void ED_mask_draw_region(
}
if (draw_flag & MASK_DRAWFLAG_OVERLAY) {
const float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
float buf_col[4] = {1.0f, 0.0f, 0.0f, 0.0f};
float *buffer = mask_rasterize(mask_eval, width, height);
if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
/* More blending types could be supported in the future. */
GPU_blend(GPU_BLEND_MULTIPLY);
GPU_blend(GPU_BLEND_ALPHA);
buf_col[0] = -1.0f;
buf_col[3] = 1.0f;
}
GPU_matrix_push();
@ -737,10 +740,18 @@ void ED_mask_draw_region(
}
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
GPU_shader_uniform_vector(
state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
immDrawPixelsTexTiled(
&state, 0.0f, 0.0f, width, height, GPU_R16F, false, buffer, 1.0f, 1.0f, NULL);
state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, buf_col);
if (overlay_mode == MASK_OVERLAY_COMBINED) {
const float blend_col[4] = {0.0f, 0.0f, 0.0f, blend_factor};
immDrawPixelsTexTiled(
&state, 0.0f, 0.0f, width, height, GPU_R16F, false, buffer, 1.0f, 1.0f, blend_col);
}
else {
immDrawPixelsTexTiled(
&state, 0.0f, 0.0f, width, height, GPU_R16F, false, buffer, 1.0f, 1.0f, NULL);
}
GPU_matrix_pop();
if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {

View File

@ -860,6 +860,7 @@ static void clip_main_region_draw(const bContext *C, ARegion *region)
sc->mask_info.draw_flag,
sc->mask_info.draw_type,
sc->mask_info.overlay_mode,
sc->mask_info.blend_factor,
mask_width,
mask_height,
aspx,

View File

@ -694,6 +694,7 @@ static void image_main_region_draw(const bContext *C, ARegion *region)
sima->mask_info.draw_flag & ~MASK_DRAWFLAG_OVERLAY,
sima->mask_info.draw_type,
sima->mask_info.overlay_mode,
sima->mask_info.blend_factor,
width,
height,
aspx,

View File

@ -18,6 +18,7 @@
.draw_flag = 0, \
.draw_type = MASK_DT_OUTLINE, \
.overlay_mode = MASK_OVERLAY_ALPHACHANNEL, \
.blend_factor = 0.7f, \
}
#define _DNA_DEFAULT_SpaceClip \

View File

@ -732,7 +732,8 @@ typedef struct MaskSpaceInfo {
char draw_flag;
char draw_type;
char overlay_mode;
char _pad3[5];
char _pad3[1];
float blend_factor;
} MaskSpaceInfo;
/** #SpaceSeq.gizmo_flag */

View File

@ -3493,6 +3493,13 @@ static void rna_def_space_mask_info(StructRNA *srna, int noteflag, const char *m
RNA_def_property_enum_items(prop, overlay_mode_items);
RNA_def_property_ui_text(prop, "Overlay Mode", "Overlay mode of rasterized mask");
RNA_def_property_update(prop, noteflag, NULL);
prop = RNA_def_property(srna, "blend_factor", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "mask_info.blend_factor");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_range(prop, 0, 1., 0.1, 1);
RNA_def_property_ui_text(prop, "Blending Factor", "Overlay blending factor of rasterized mask");
RNA_def_property_update(prop, noteflag, NULL);
}
static void rna_def_space_image_uv(BlenderRNA *brna)