[Bf-blender-cvs] [3aa787a23ab] greasepencil-object: GP: New option to enable masking

Antonioya noreply at git.blender.org
Sat Nov 24 12:02:46 CET 2018


Commit: 3aa787a23ab63537cecc2993acbbac3162564815
Author: Antonioya
Date:   Sat Nov 24 12:02:37 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB3aa787a23ab63537cecc2993acbbac3162564815

GP: New option to enable masking

Now the blend masking can be enabled or disabled

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_blend_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 cc107cb0aee..bf457a44f84 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -161,6 +161,7 @@ class DATA_PT_gpencil_datapanel(Panel):
         if gpl:
             row = layout.row(align=True)
             row.prop(gpl, "blend_mode", text="Blend")
+            row.prop(gpl, "use_mask", text="", icon='MOD_MASK')
             row = layout.row(align=True)
             row.enabled = gpl.blend_mode == 'NORMAL'
             row.prop(gpl, "opacity", text="Opacity", slider=True)
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 0109917a57a..ca0702e717f 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -542,6 +542,7 @@ class TOPBAR_PT_gpencil_layers(Panel):
         if gpl:
             row = layout.row(align=True)
             row.prop(gpl, "blend_mode", text="Blend")
+            row.prop(gpl, "use_mask", text="", icon='MOD_MASK')
             row = layout.row(align=True)
             row.enabled = gpl.blend_mode == 'NORMAL'
             row.prop(gpl, "opacity", text="Opacity", slider=True)
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 4fa6c11ab03..4f940d05703 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -1397,6 +1397,7 @@ static void DRW_gpencil_shgroups_create(
 		if ((shgrp != NULL) && (tag_first)) {
 			array_elm = &cache_ob->shgrp_array[idx];
 			array_elm->mode = idx == 0 ? eGplBlendMode_Normal: gpl->blend_mode;
+			array_elm->use_mask = gpl->flag & GP_LAYER_USE_MASK;
 			array_elm->init_shgrp = shgrp;
 			cache_ob->tot_layers++;
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 28db80ae0b1..647b20bd200 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -501,7 +501,9 @@ void GPENCIL_cache_init(void *vedata)
 		DRW_shgroup_uniform_texture_ref(blend_shgrp, "strokeColor", &e_data.temp_color_tx_a);
 		DRW_shgroup_uniform_texture_ref(blend_shgrp, "strokeDepth", &e_data.temp_depth_tx_a);
 		DRW_shgroup_uniform_texture_ref(blend_shgrp, "blendColor", &e_data.temp_color_tx_fx);
+		DRW_shgroup_uniform_texture_ref(blend_shgrp, "blendDepth", &e_data.temp_depth_tx_fx);
 		DRW_shgroup_uniform_int(blend_shgrp, "mode", &stl->storage->blend_mode, 1);
+		DRW_shgroup_uniform_int(blend_shgrp, "use_mask", &stl->storage->use_mask, 1);
 
 		/* create effects passes */
 		if (!stl->storage->simplify_fx) {
@@ -795,6 +797,7 @@ void GPENCIL_draw_scene(void *ved)
 								GPU_framebuffer_bind(fbl->temp_fb_b);
 								GPU_framebuffer_clear_color_depth(fbl->temp_fb_b, clearcol, 1.0f);
 								stl->storage->blend_mode = array_elm->mode;
+								stl->storage->use_mask = (int)array_elm->use_mask;
 								DRW_draw_pass(psl->blend_pass);
 
 								/* Copy B texture to A texture to follow loop */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 9bc6f26174d..ceb1e06b5a6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -60,6 +60,7 @@ struct RenderLayer;
  /* *********** OBJECTS CACHE *********** */
 typedef struct tGPencilObjectCache_shgrp {
 	int mode;
+	bool use_mask;
 	DRWShadingGroup *init_shgrp;
 	DRWShadingGroup *end_shgrp;
 } tGPencilObjectCache_shgrp;
@@ -136,6 +137,7 @@ typedef struct GPENCIL_Storage {
 	short multisamples;
 
 	int blend_mode;
+	int use_mask;
 
 	/* simplify settings*/
 	bool simplify_fill;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
index f6fd96051f9..8ddc8e56fbd 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
@@ -5,7 +5,9 @@ out vec4 FragColor;
 uniform sampler2D strokeColor;
 uniform sampler2D strokeDepth;
 uniform sampler2D blendColor;
+uniform sampler2D blendDepth;
 uniform int mode;
+uniform int use_mask;
 
 #define MODE_NORMAL   0
 #define MODE_OVERLAY  1
@@ -76,11 +78,11 @@ void main()
 {
 	ivec2 uv = ivec2(gl_FragCoord.xy);
 	vec4 stroke_color =  texelFetch(strokeColor, uv, 0).rgba;
-	if (stroke_color.a == 0) {
+	float stroke_depth = texelFetch(strokeDepth, uv, 0).r;
+	if ((stroke_color.a == 0) && (use_mask == 1)) {
 		discard;
 	}
 	
-	float stroke_depth = texelFetch(strokeDepth, uv, 0).r;
 	vec4 mix_color =  texelFetch(blendColor, uv, 0).rgba;
 
 	/* premult alpha factor to remove double blend effects */
@@ -92,6 +94,13 @@ void main()
 	}
 
 	vec4 outcolor = get_blend_color(mode, stroke_color, mix_color);
+
+	/* if not using mask, return mix color */
+	if ((stroke_color.a == 0) && (use_mask == 0)) {
+		FragColor = mix_color;
+		gl_FragDepth = texelFetch(blendDepth, uv, 0).r;
+		return;
+	}
 	
 	FragColor = outcolor;
 	gl_FragDepth = stroke_depth;
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 0a46b85ded5..cebdc4b29b9 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -295,6 +295,8 @@ typedef enum eGPDlayer_Flag {
 	GP_LAYER_VOLUMETRIC		= (1 << 10),
 	/* Unlock color */
 	GP_LAYER_UNLOCK_COLOR 	= (1 << 12),
+	/* Mask Layer */
+	GP_LAYER_USE_MASK = (1 << 13),
 } eGPDlayer_Flag;
 
 /* bGPDlayer->onion_flag */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index c5a19d25640..be64e52f0b5 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1200,6 +1200,12 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Lock Material", "Disable Material editing");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
 
+	prop = RNA_def_property(srna, "use_mask", 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", "Use underlying layers as mask");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
+
 
 	/* exposed as layers.active */
 #if 0



More information about the Bf-blender-cvs mailing list