[Bf-blender-cvs] [38f537c5888] greasepencil-refactor: GPencil: Refactor: Add invert masking
Clément Foucault
noreply at git.blender.org
Wed Dec 18 03:14:24 CET 2019
Commit: 38f537c5888fb8b648d9237ee897de26d59a9f66
Author: Clément Foucault
Date: Tue Dec 17 02:52:44 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB38f537c5888fb8b648d9237ee897de26d59a9f66
GPencil: Refactor: Add invert masking
===================================================================
M release/scripts/startup/bl_ui/properties_data_gpencil.py
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M source/blender/draw/engines/gpencil/shaders/gpencil_layer_mask_frag.glsl
M source/blender/makesdna/DNA_gpencil_types.h
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index 9c2f88173bf..150abd4ebf8 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -171,8 +171,9 @@ class DATA_PT_gpencil_layers(DataButtonsPanel, Panel):
layout.use_property_decorate = True
col = layout.column(align=True)
- col = layout.row(align=True)
- col.prop(gpl, "blend_mode", text="Blend")
+ if gpl.mask_layer:
+ col = layout.row(align=True)
+ col.prop(gpl, "blend_mode", text="Blend")
col = layout.row(align=True)
col.prop(gpl, "opacity", text="Opacity", slider=True)
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 5ecf001376b..484334c39a6 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -690,9 +690,12 @@ class GPENCIL_UL_layer(UIList):
row.prop(gpl, "info", text="", emboss=False)
row = layout.row(align=True)
- row.prop(gpl, "mask_layer", text="",
- icon='MOD_MASK' if gpl.mask_layer else 'LAYER_ACTIVE',
- emboss=False)
+
+ icon_mask = 'LAYER_ACTIVE'
+ if gpl.mask_layer:
+ icon_mask = 'HOLDOUT_ON' if gpl.invert_mask else 'MOD_MASK'
+
+ row.prop(gpl, "mask_layer", text="", icon=icon_mask, emboss=False)
subrow = row.row(align=True)
subrow.prop(
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index ba51465353a..22a235ddfb4 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -112,6 +112,7 @@ GPENCIL_tLayer *gpencil_layer_cache_add_new(GPENCIL_PrivateData *pd, Object *ob,
DRWShadingGroup *grp = DRW_shgroup_create(sh, tgp_layer->blend_ps);
DRW_shgroup_uniform_int_copy(grp, "isFirstPass", true);
DRW_shgroup_uniform_float_copy(grp, "maskOpacity", gpl->opacity);
+ DRW_shgroup_uniform_bool_copy(grp, "maskInvert", gpl->flag & GP_LAYER_MASK_INVERT);
DRW_shgroup_uniform_texture_ref(grp, "colorBuf", &pd->color_masked_tx);
DRW_shgroup_uniform_texture_ref(grp, "revealBuf", &pd->reveal_masked_tx);
DRW_shgroup_uniform_texture_ref(grp, "maskBuf", &pd->reveal_layer_tx);
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_layer_mask_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_layer_mask_frag.glsl
index 3889c42b04f..64899b147dc 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_layer_mask_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_layer_mask_frag.glsl
@@ -3,6 +3,7 @@ uniform sampler2D colorBuf;
uniform sampler2D revealBuf;
uniform sampler2D maskBuf;
uniform float maskOpacity;
+uniform bool maskInvert;
uniform bool isFirstPass;
in vec4 uvcoordsvar;
@@ -14,7 +15,13 @@ void main()
{
vec3 masked_color = texture(colorBuf, uvcoordsvar.xy).rgb;
vec3 masked_reveal = texture(revealBuf, uvcoordsvar.xy).rgb;
- float mask = 1.0 - maskOpacity * texture(maskBuf, uvcoordsvar.xy).r;
+ float mask = texture(maskBuf, uvcoordsvar.xy).r;
+
+ if (maskInvert) {
+ mask = 1.0 - mask;
+ }
+
+ mask = 1.0 - mask * maskOpacity;
if (isFirstPass) {
/* Blend mode is multiply. */
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index e8a23ef7466..ae8b1360b7c 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -422,6 +422,8 @@ typedef enum eGPDlayer_Flag {
GP_LAYER_USE_MASK = (1 << 13),
/* Ruler Layer */
GP_LAYER_IS_RULER = (1 << 14),
+ /* Invert masking behavior */
+ GP_LAYER_MASK_INVERT = (1 << 15),
} eGPDlayer_Flag;
/* bGPDlayer->onion_flag */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 3fc34c025c4..ed218e35f7a 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -472,6 +472,26 @@ static void rna_GPencilLayer_info_set(PointerRNA *ptr, const char *value)
BKE_animdata_fix_paths_rename_all(&gpd->id, "layers", oldname, gpl->info);
}
+static void rna_GPencil_layer_mask_set(PointerRNA *ptr, const bool value)
+{
+ bGPdata *gpd = (bGPdata *)ptr->owner_id;
+ bGPDlayer *gpl = ptr->data;
+
+ const bool use_mask = gpl->flag & GP_LAYER_USE_MASK;
+
+ /* Cycle through the 3 options */
+ if (value != use_mask) {
+ if (use_mask && (gpl->flag & GP_LAYER_MASK_INVERT) == 0) {
+ /* Switch to invert mask instead of removing the masking. */
+ gpl->flag |= GP_LAYER_MASK_INVERT;
+ }
+ else {
+ SET_FLAG_FROM_TEST(gpl->flag, value, GP_LAYER_USE_MASK);
+ gpl->flag &= ~GP_LAYER_MASK_INVERT;
+ }
+ }
+}
+
static bGPDstroke *rna_GPencil_stroke_point_find_stroke(const bGPdata *gpd,
const bGPDspoint *pt,
bGPDlayer **r_gpl,
@@ -1481,8 +1501,14 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
prop = RNA_def_property(srna, "mask_layer", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_USE_MASK);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_ui_text(
- prop, "Mask Layer", "Remove any pixel outside underlying layers drawing");
+ RNA_def_property_boolean_funcs(prop, NULL, "rna_GPencil_layer_mask_set");
+ RNA_def_property_ui_text(prop, "Mask Layer", "Mask pixels from underlying layers drawing");
+ RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
+ prop = RNA_def_property(srna, "invert_mask", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_MASK_INVERT);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Invert Mask", "Invert the masking behavior of the layer");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
/* solo mode: Only display frames with keyframe */
More information about the Bf-blender-cvs
mailing list