[Bf-blender-cvs] [bd5d93b29f7] greasepencil-object: Add flags for Stroke and for fill

Antonio Vazquez noreply at git.blender.org
Thu Jul 9 17:04:21 CEST 2020


Commit: bd5d93b29f7427e4ed61460507177fc88757394e
Author: Antonio Vazquez
Date:   Wed Jul 1 17:45:16 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rBbd5d93b29f7427e4ed61460507177fc88757394e

Add flags for Stroke and for fill

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

M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M	source/blender/draw/engines/gpencil/gpencil_draw_data.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index d1e1a87ea00..3e97ada6433 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -70,8 +70,6 @@ class GPENCIL_UL_matslots(UIList):
                 row.prop(ma, "name", text="", emboss=False, icon_value=icon)
 
                 row = layout.row(align=True)
-                icon_mask = 'MOD_MASK' if gpcolor.use_masking else 'LAYER_ACTIVE'
-                row.prop(gpcolor, "use_masking", text="", icon=icon_mask, emboss=False)
 
                 if gpcolor.ghost is True:
                     icon = 'ONIONSKIN_OFF'
@@ -171,6 +169,8 @@ class MATERIAL_PT_gpencil_strokecolor(GPMaterialButtonsPanel, Panel):
             if gpcolor.mode == 'LINE':
                 col.prop(gpcolor, "use_overlap_strokes")
 
+            col.prop(gpcolor, "use_stroke_masking", text="Masking")
+
 
 class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
     bl_label = "Fill"
@@ -225,6 +225,8 @@ class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
             col.prop(gpcolor, "texture_scale", text="Scale")
             col.prop(gpcolor, "texture_clamp", text="Clip Image")
 
+        col.prop(gpcolor, "use_fill_masking", text="Masking")
+
 
 class MATERIAL_PT_gpencil_preview(GPMaterialButtonsPanel, Panel):
     bl_label = "Preview"
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 35aac237f48..26349e10e0b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -62,7 +62,8 @@ GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob)
   tgp_ob->do_mat_masking = false;
   for (int i = 0; i < ob->totcol; i++) {
     MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, i + 1);
-    if (gp_style->flag & GP_MATERIAL_IS_MASK) {
+    if ((gp_style->flag & GP_MATERIAL_IS_STROKE_MASK) ||
+        ((gp_style->flag & GP_MATERIAL_IS_FILL_MASK))) {
       tgp_ob->do_mat_masking = true;
       break;
     }
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index 512a8b5e6a6..03342b2fb9f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -238,9 +238,12 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
     }
 
     /* Material with masking. */
-    if (gp_style->flag & GP_MATERIAL_IS_MASK) {
+    if (gp_style->flag & GP_MATERIAL_IS_STROKE_MASK) {
       mat_data->flag |= GP_STROKE_MASK;
     }
+    if (gp_style->flag & GP_MATERIAL_IS_FILL_MASK) {
+      mat_data->flag |= GP_FILL_MASK;
+    }
 
     gp_style = gpencil_viewport_material_overrides(pd, ob, color_type, gp_style);
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 28b6f437b79..a0f8276cf9a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -76,6 +76,7 @@ typedef struct gpMaterial {
 #define GP_STROKE_TEXTURE_PREMUL (1 << 5)
 #define GP_STROKE_DOTS (1 << 6)
 #define GP_STROKE_MASK (1 << 7)
+#define GP_FILL_MASK (1 << 8)
 #define GP_FILL_TEXTURE_USE (1 << 10)
 #define GP_FILL_TEXTURE_PREMUL (1 << 11)
 #define GP_FILL_TEXTURE_CLIP (1 << 12)
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
index 49aa36634b1..36e8882cc9f 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -25,6 +25,7 @@ struct gpMaterial {
 #define GP_STROKE_TEXTURE_PREMUL (1 << 5)
 #define GP_STROKE_DOTS (1 << 6)
 #define GP_STROKE_MASK (1 << 7)
+#define GP_FILL_MASK (1 << 8)
 #define GP_FILL_TEXTURE_USE (1 << 10)
 #define GP_FILL_TEXTURE_PREMUL (1 << 11)
 #define GP_FILL_TEXTURE_CLIP (1 << 12)
@@ -578,6 +579,9 @@ void fill_vertex()
   if (GP_FLAG_TEST(MATERIAL(m).flag, GP_STROKE_MASK)) {
     matFlag |= GP_STROKE_MASK;
   }
+  if (GP_FLAG_TEST(MATERIAL(m).flag, GP_FILL_MASK)) {
+    matFlag |= GP_FILL_MASK;
+  }
 
   matFlag |= m << GP_MATID_SHIFT;
 
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
index e20a0038b60..051ce4436f8 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
@@ -89,8 +89,10 @@ void main()
   fragColor *= stroke_round_cap_mask(
       strokePt1, strokePt2, strokeAspect, strokeThickness, strokeHardeness);
 
-  /* If material masking. */
-  if (GP_FLAG_TEST(matFlag, GP_STROKE_MASK)) {
+  /* If material masking. Use a hack to determine if the pixel is fill or not
+   * using the thickness. */
+  if (((GP_FLAG_TEST(matFlag, GP_STROKE_MASK)) && (strokeThickness != 1e18)) ||
+      (GP_FLAG_TEST(matFlag, GP_FILL_MASK) && (strokeThickness == 1e18))) {
     fragColor = vec4(0.0, 0.0, 0.0, 1.0);
     revealColor = vec4(1.0, 1.0, 1.0, 0.0);
   }
diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h
index 5f74a90825e..b6215078053 100644
--- a/source/blender/makesdna/DNA_material_types.h
+++ b/source/blender/makesdna/DNA_material_types.h
@@ -129,8 +129,10 @@ typedef enum eMaterialGPencilStyle_Flag {
   GP_MATERIAL_STROKE_TEX_MIX = (1 << 11),
   /* disable stencil clipping (overlap) */
   GP_MATERIAL_DISABLE_STENCIL = (1 << 12),
-  /* Material used as masking. */
-  GP_MATERIAL_IS_MASK = (1 << 13),
+  /* Material used as stroke masking. */
+  GP_MATERIAL_IS_STROKE_MASK = (1 << 13),
+  /* Material used as fill masking. */
+  GP_MATERIAL_IS_FILL_MASK = (1 << 14),
 } eMaterialGPencilStyle_Flag;
 
 typedef enum eMaterialGPencilStyle_Mode {
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index a3cc6e09917..06a3bb3454e 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -564,8 +564,13 @@ static void rna_def_material_greasepencil(BlenderRNA *brna)
       prop, "Self Overlap", "Disable stencil and overlap self intersections with alpha materials");
   RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialGpencil_update");
 
-  prop = RNA_def_property(srna, "use_masking", PROP_BOOLEAN, PROP_NONE);
-  RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_MATERIAL_IS_MASK);
+  prop = RNA_def_property(srna, "use_stroke_masking", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_MATERIAL_IS_STROKE_MASK);
+  RNA_def_property_ui_text(prop, "Mask", "Use the material as a transparent mask");
+  RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialGpencil_update");
+
+  prop = RNA_def_property(srna, "use_fill_masking", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_MATERIAL_IS_FILL_MASK);
   RNA_def_property_ui_text(prop, "Mask", "Use the material as a transparent mask");
   RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialGpencil_update");



More information about the Bf-blender-cvs mailing list