[Bf-blender-cvs] [78c8a26322b] greasepencil-object: Invert Mask flag to be ON by default

Antonioya noreply at git.blender.org
Sun Nov 25 14:18:18 CET 2018


Commit: 78c8a26322b18f3b106e42c9dfd249a74c1bc095
Author: Antonioya
Date:   Sun Nov 25 09:44:25 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB78c8a26322b18f3b106e42c9dfd249a74c1bc095

Invert Mask flag to be ON by default

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	release/scripts/startup/bl_ui/properties_grease_pencil_common.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/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 d99c3ca2f80..4a058a743b8 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -163,7 +163,7 @@ class DATA_PT_gpencil_datapanel(Panel):
             row.prop(gpl, "blend_mode", text="Blend")
             subrow = row.row(align=True)
             subrow.enabled = gpl.blend_mode != 'NORMAL'
-            subrow.prop(gpl, "use_mask", text="", icon='MOD_MASK')
+            subrow.prop(gpl, "disable_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/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index c1f883bad0b..3550bcdf3c8 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -867,7 +867,7 @@ class GPENCIL_UL_layer(UIList):
             row = layout.row(align=True)
             row.label(
                 text="",
-                icon='MOD_MASK' if gpl.blend_mode != 'NORMAL' and gpl.use_mask else 'BLANK1'
+                icon='MOD_MASK' if gpl.blend_mode != 'NORMAL' and gpl.disable_mask else 'BLANK1'
             )
             row.label(
                 text="",
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 1847dc70765..728b7edba92 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -544,7 +544,7 @@ class TOPBAR_PT_gpencil_layers(Panel):
             row.prop(gpl, "blend_mode", text="Blend")
             subrow = row.row(align=True)
             subrow.enabled = gpl.blend_mode != 'NORMAL'
-            subrow.prop(gpl, "use_mask", text="", icon='MOD_MASK')
+            subrow.prop(gpl, "disable_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 4f940d05703..7c59c7cd396 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -1397,7 +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->disable_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 92b39812a14..08d32d33e25 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -503,7 +503,7 @@ void GPENCIL_cache_init(void *vedata)
 		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);
+		DRW_shgroup_uniform_int(blend_shgrp, "disable_mask", &stl->storage->disable_mask, 1);
 
 		/* create effects passes */
 		if (!stl->storage->simplify_fx) {
@@ -771,53 +771,53 @@ void GPENCIL_draw_scene(void *ved)
 				/* Stroke Pass:
 				 * draw only a subset that usually starts with a fill and ends with stroke
 				 */
+				bool use_blend = false;
 				if (cache_ob->tot_layers > 0) {
 					for (int e = 0; e < cache_ob->tot_layers; e++) {
 						array_elm = &cache_ob->shgrp_array[e];
-						if ((array_elm->mode == eGplBlendMode_Normal) && (init_shgrp == NULL))
+
+						if ((array_elm->mode == eGplBlendMode_Normal) && (!use_blend))
 						{
-							init_shgrp = array_elm->init_shgrp;
+							if (init_shgrp == NULL) {
+								init_shgrp = array_elm->init_shgrp;
+							}
 							end_shgrp = array_elm->end_shgrp;
 						}
 						else {
-							if (array_elm->mode == eGplBlendMode_Normal) {
-								end_shgrp = array_elm->end_shgrp;
-							}
-							else {
-								/* draw pending groups */
-								gpencil_draw_pass_range(fbl, stl, psl, txl, init_shgrp, end_shgrp);
+							use_blend = true;
+							/* draw pending groups */
+							gpencil_draw_pass_range(fbl, stl, psl, txl, init_shgrp, end_shgrp);
 
-								/* draw current group in separated texture */
-								init_shgrp = array_elm->init_shgrp;
-								end_shgrp = array_elm->end_shgrp;
-
-								GPU_framebuffer_bind(fbl->temp_fb_fx);
-								GPU_framebuffer_clear_color_depth(fbl->temp_fb_fx, clearcol, 1.0f);
-								DRW_draw_pass_subset(psl->stroke_pass, init_shgrp, end_shgrp);
-
-								/* Blend A texture and FX texture */
-								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 */
-								e_data.input_depth_tx = e_data.temp_depth_tx_b;
-								e_data.input_color_tx = e_data.temp_color_tx_b;
-
-								GPU_framebuffer_bind(fbl->temp_fb_a);
-								GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
-								DRW_draw_pass(psl->mix_pass_noblend);
-								/* prepare next group */
-								init_shgrp = NULL;
-							}
+							/* draw current group in separated texture */
+							init_shgrp = array_elm->init_shgrp;
+							end_shgrp = array_elm->end_shgrp;
+
+							GPU_framebuffer_bind(fbl->temp_fb_fx);
+							GPU_framebuffer_clear_color_depth(fbl->temp_fb_fx, clearcol, 1.0f);
+							DRW_draw_pass_subset(psl->stroke_pass, init_shgrp, end_shgrp);
+
+							/* Blend A texture and FX texture */
+							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->disable_mask = (int)array_elm->disable_mask;
+							DRW_draw_pass(psl->blend_pass);
+
+							/* Copy B texture to A texture to follow loop */
+							e_data.input_depth_tx = e_data.temp_depth_tx_b;
+							e_data.input_color_tx = e_data.temp_color_tx_b;
+
+							GPU_framebuffer_bind(fbl->temp_fb_a);
+							GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
+							DRW_draw_pass(psl->mix_pass_noblend);
+
+							/* prepare next group */
+							init_shgrp = NULL;
 						}
 
 					}
 					/* last group */
 					gpencil_draw_pass_range(fbl, stl, psl, txl, init_shgrp, end_shgrp);
-
 				}
 
 				/* Current buffer drawing */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ceb1e06b5a6..70e37365f19 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -60,7 +60,7 @@ struct RenderLayer;
  /* *********** OBJECTS CACHE *********** */
 typedef struct tGPencilObjectCache_shgrp {
 	int mode;
-	bool use_mask;
+	bool disable_mask;
 	DRWShadingGroup *init_shgrp;
 	DRWShadingGroup *end_shgrp;
 } tGPencilObjectCache_shgrp;
@@ -137,7 +137,7 @@ typedef struct GPENCIL_Storage {
 	short multisamples;
 
 	int blend_mode;
-	int use_mask;
+	int disable_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 8ddc8e56fbd..b0f194db51c 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
@@ -7,7 +7,10 @@ uniform sampler2D strokeDepth;
 uniform sampler2D blendColor;
 uniform sampler2D blendDepth;
 uniform int mode;
-uniform int use_mask;
+uniform int disable_mask;
+
+const float weight = 1.0 / 9.0;
+#define THRESHOLD 0.01f
 
 #define MODE_NORMAL   0
 #define MODE_OVERLAY  1
@@ -37,9 +40,6 @@ vec4 get_blend_color(int mode, vec4 src_color, vec4 blend_color)
 	if (mix_color.a == 0) {
 		outcolor = src_color;
 	}
-	else if (mode == MODE_NORMAL) {
-		outcolor = mix_color;
-	}
 	else if (mode == MODE_OVERLAY) {
 		mix_color.rgb = mix_color.rgb * mix_color.a;
 		outcolor.r = overlay_color(src_color.r, mix_color.r);
@@ -74,16 +74,24 @@ vec4 get_blend_color(int mode, vec4 src_color, vec4 blend_color)
 	return outcolor;
 }
 
+vec4 get_blurcolor(ivec2 uv, ivec2 xy)
+{
+	vec4 blend_color =  texelFetch(blendColor, uv + xy, 0).rgba;
+	return blend_color; // * weight;
+}
+
 void main()
 {
+	vec4 outcolor;
 	ivec2 uv = ivec2(gl_FragCoord.xy);
 	vec4 stroke_color =  texelFetch(strokeColor, uv, 0).rgba;
 	float stroke_depth = texelFetch(strokeDepth, uv, 0).r;
-	if ((stroke_color.a == 0) && (use_mask == 1)) {
+	if ((stroke_color.a == 0) && (disable_mask == 1)) {
 		discard;
 	}
 	
 	vec4 mix_color =  texelFetch(blendColor, uv, 0).rgba;
+	float mix_depth = texelFetch(blendDepth, uv, 0).r;
 
 	/* premult alpha factor to remove double blend effects */
 	if (stroke_color.a > 0) {
@@ -92,16 +100,44 @@ void main()
 	if (mix_color.a > 0) {
 		mix_color = vec4(vec3(mix_color.rgb / mix_color.a), mix_color.a);
 	}
+	
+	/* Normal mode */
+	if (mode == MODE_NORMAL) {
+		if (mix_color.a > THRESHOLD) {
+			outcolor =  mix_color;
+			gl_FragDepth = mix_depth;
+		}
+		else {
+			/* blur edges with box blur */
+			vec4 blur = mix_color * weight;
+			blur += get_blurcolor(uv, ivec2(-1, -1));
+			blur += get_blurcolor(uv, ivec2(0, -1));
+			blur += get_blurcolor(uv, ivec2(+1, -1));
 
-	vec4 outcolor = get_blend_color(mode, stroke_color, mix_color);
+			blur +=

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list