[Bf-blender-cvs] [eca0c95d51a] master: Mask Editor: Add mask blending factor for combined overlay

Simon Lenz noreply at git.blender.org
Mon Jun 20 16:08:28 CEST 2022


Commit: eca0c95d51a8cede2475d1c77d5f6615623bda01
Author: Simon Lenz
Date:   Wed Jun 15 15:15:23 2022 +0200
Branches: master
https://developer.blender.org/rBeca0c95d51a8cede2475d1c77d5f6615623bda01

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

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

M	release/scripts/startup/bl_ui/properties_mask_common.py
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/editors/include/ED_mask.h
M	source/blender/editors/mask/mask_draw.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/makesdna/DNA_space_defaults.h
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/properties_mask_common.py b/release/scripts/startup/bl_ui/properties_mask_common.py
index 3131833454b..47a25db20b1 100644
--- a/release/scripts/startup/bl_ui/properties_mask_common.py
+++ b/release/scripts/startup/bl_ui/properties_mask_common.py
@@ -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:
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 2cd753da9d3..20eb33c5d15 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -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
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 97b414d4b4a..5af42f9f1f6 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -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.
    *
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index f65976ee55f..91b2f509a7f 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -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;
     }
   }
 
diff --git a/source/blender/editors/include/ED_mask.h b/source/blender/editors/include/ED_mask.h
index 92df3d8d682..6d4d4fcff48 100644
--- a/source/blender/editors/include/ED_mask.h
+++ b/source/blender/editors/include/ED_mask.h
@@ -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,
diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c
index aab4007854f..1bd224fe763 100644
--- a/source/blender/editors/mask/mask_draw.c
+++ b/source/blender/editors/mask/mask_draw.c
@@ -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) {
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 5f52e1a3071..a73883e7624 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -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,
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index ab8143c5bf5..785a5419e04 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -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,
diff --git a/source/blender/makesdna/DNA_space_defaults.h b/source/blender/makesdna/DNA_space_defaults.h
index e826cb4c2ef..66a09bc82c3 100644
--- a/source/blender/makesdna/DNA_space_defaults.h
+++ b/source/blender/makesdna/DNA_space_defaults.h
@@ -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 \
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index be073ef2c15..2905ef06833 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -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 */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index cae86801402..910e78e7a58 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -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)



More information about the Bf-blender-cvs mailing list