[Bf-blender-cvs] [16b0a742280] master: GP: Fix unreported pixel glitches

Antonioya noreply at git.blender.org
Thu Jan 10 13:14:14 CET 2019


Commit: 16b0a742280ad557c7921abfc6c6cf4b8e783a92
Author: Antonioya
Date:   Thu Jan 10 13:10:46 2019 +0100
Branches: master
https://developer.blender.org/rB16b0a742280ad557c7921abfc6c6cf4b8e783a92

GP: Fix unreported pixel glitches

There was a problem in the caps start and in some situations, the pixel was wrong.

Also changed the way the caps are detected because use the alpha in negative was a hack that maybe will not work with all drivers.

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

M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl

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

diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
index 9a82e871f56..79b0f60d8c6 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
@@ -3,7 +3,7 @@ uniform sampler2D myTexture;
 
 in vec4 mColor;
 in vec2 mTexCoord;
-in float uvfac;
+in vec2 uvfac;
 
 out vec4 fragColor;
 
@@ -17,10 +17,9 @@ out vec4 fragColor;
 void main()
 {
 	vec4 tColor = vec4(mColor);
-	/* if alpha < 0, then encap (only solid mode ) */
-	if ((mColor.a < 0) && (color_type == GPENCIL_COLOR_SOLID)) {
-		vec2 center = vec2(uvfac, 1.0);
-		tColor.a = tColor.a * -1.0;
+	/* if uvfac[1]  == 1, then encap (only solid mode ) */
+	if ((uvfac[1] == 1.0) && (color_type == GPENCIL_COLOR_SOLID)) {
+		vec2 center = vec2(uvfac[0], 1.0);
 		float dist = length(mTexCoord - center);
 		if (dist > 0.50) {
 			discard;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
index 748f69ab21a..c2a5f6b0b84 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
@@ -12,7 +12,7 @@ in vec2 finaluvdata[4];
 
 out vec4 mColor;
 out vec2 mTexCoord;
-out float uvfac;
+out vec2 uvfac;
 
 #define GP_XRAY_FRONT 0
 #define GP_XRAY_3DSPACE 1
@@ -64,7 +64,7 @@ bool is_equal(vec4 p1, vec4 p2)
 void main(void)
 {
 	float MiterLimit = 0.75;
-	uvfac = 0;
+	uvfac = vec2(0.0, 0.0);
 
 	/* receive 4 points */
 	vec4 P0 = gl_in[0].gl_Position;
@@ -158,26 +158,32 @@ void main(void)
 		length_b = finalThickness[2];
 	}
 
-	/* generate the start endcap (alpha < 0 used as endcap flag)*/
+	/* generate the start endcap */
 	if (is_equal(P0,P2) && (color_type == GPENCIL_COLOR_SOLID)){
-		mTexCoord = vec2(2, 1);
-		mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0) ;
+		vec4 cap_color = finalColor[1];
+
+		mTexCoord = vec2(2.0, 1.0);
+		mColor = cap_color;
 		vec2 svn1 =  normalize(sp1 - sp2) * length_a * 4.0;
+		uvfac = vec2(0.0, 1.0);
 		gl_Position = vec4((sp1 + svn1) / Viewport, getZdepth(P1), 1.0);
 		EmitVertex();
 
-		mTexCoord = vec2(0, 0);
-		mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0) ;
+		mTexCoord = vec2(0.0, 0.0);
+		mColor = cap_color;
+		uvfac = vec2(0.0, 1.0);
 		gl_Position = vec4((sp1 - (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0);
 		EmitVertex();
 
-		mTexCoord = vec2(0, 2);
-		mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0) ;
+		mTexCoord = vec2(0.0, 2.0);
+		mColor = cap_color;
+		uvfac = vec2(0.0, 1.0);
 		gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0);
 		EmitVertex();
 	}
 
 	/* generate the triangle strip */
+	uvfac = vec2(0.0, 0.0);
 	mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(0, 0) : vec2(finaluvdata[1].x, 0);
 	mColor = finalColor[1];
 	gl_Position = vec4((sp1 + length_a * miter_a) / Viewport, getZdepth(P1), 1.0);
@@ -198,23 +204,25 @@ void main(void)
 	gl_Position = vec4((sp2 - length_b * miter_b) / Viewport, getZdepth(P2), 1.0);
 	EmitVertex();
 
-	/* generate the end endcap (alpha < 0 used as endcap flag)*/
+	/* generate the end endcap */
 	if (is_equal(P1,P3) && (color_type == GPENCIL_COLOR_SOLID) && (finaluvdata[2].x > 0)){
-		mTexCoord = vec2(finaluvdata[2].x, 2);
-		mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0) ;
-		uvfac = finaluvdata[2].x;
+		vec4 cap_color = finalColor[2];
+
+		mTexCoord = vec2(finaluvdata[2].x, 2.0);
+		mColor = cap_color;
+		uvfac = vec2(finaluvdata[2].x, 1.0);
 		gl_Position = vec4((sp2 + (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0);
 		EmitVertex();
 
-		mTexCoord = vec2(finaluvdata[2].x, 0);
-		mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0) ;
-		uvfac = finaluvdata[2].x;
+		mTexCoord = vec2(finaluvdata[2].x, 0.0);
+		mColor = cap_color;
+		uvfac = vec2(finaluvdata[2].x, 1.0);
 		gl_Position = vec4((sp2 - (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0);
 		EmitVertex();
 
-		mTexCoord = vec2(finaluvdata[2].x + 2, 1);
-		mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0) ;
-		uvfac = finaluvdata[2].x;
+		mTexCoord = vec2(finaluvdata[2].x + 2, 1.0);
+		mColor = cap_color;
+		uvfac = vec2(finaluvdata[2].x, 1.0);
 		vec2 svn2 =  normalize(sp2 - sp1) * length_b * 4.0;
 		gl_Position = vec4((sp2 + svn2) / Viewport, getZdepth(P2), 1.0);
 		EmitVertex();
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
index 0983e6c4d87..f4b6201e503 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
@@ -40,6 +40,6 @@ void main()
 		stroke_color.b = srgb_to_linearrgb(stroke_color.b);
 	}
 
-	FragColor = stroke_color;
-	gl_FragDepth = stroke_depth;
+	FragColor = clamp(stroke_color, 0.0, 1.0);
+	gl_FragDepth = clamp(stroke_depth, 0.0, 1.0);
 }



More information about the Bf-blender-cvs mailing list