[Bf-blender-cvs] [59f30e9390d] master: GPencil: Improve quality to stroke encaps for textured materials

Antonioya noreply at git.blender.org
Wed Mar 6 17:57:13 CET 2019


Commit: 59f30e9390d446b5ef0ab4048f654507fc51a822
Author: Antonioya
Date:   Wed Mar 6 17:56:55 2019 +0100
Branches: master
https://developer.blender.org/rB59f30e9390d446b5ef0ab4048f654507fc51a822

GPencil: Improve quality to stroke encaps for textured materials

Before, the caps were not generated for texture materials, now, the endcaps are generated and  adapt the texture.

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

M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.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 79b0f60d8c6..dad482bfa23 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
@@ -14,12 +14,14 @@ out vec4 fragColor;
 #define GPENCIL_COLOR_TEXTURE 1
 #define GPENCIL_COLOR_PATTERN 2
 
+#define ENDCAP 1.0
+
 void main()
 {
 	vec4 tColor = vec4(mColor);
-	/* 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);
+	/* if uvfac[1]  == 1, then encap */
+	if (uvfac[1] == ENDCAP) {
+		vec2 center = vec2(uvfac[0], 0.5);
 		float dist = length(mTexCoord - center);
 		if (dist > 0.50) {
 			discard;
@@ -29,15 +31,24 @@ void main()
 	if (color_type == GPENCIL_COLOR_SOLID) {
 		fragColor = tColor;
 	}
+	
+	/* texture for endcaps */
+	vec4 text_color;
+	if (uvfac[1] == ENDCAP) {
+		text_color = texture2D(myTexture, vec2(mTexCoord.x,  mTexCoord.y));
+	}
+	else {
+		text_color = texture2D(myTexture, mTexCoord);
+	}
+	
 	/* texture */
 	if (color_type == GPENCIL_COLOR_TEXTURE) {
-		fragColor =  texture2D(myTexture, mTexCoord);
+		fragColor =  text_color;
 		/* mult both alpha factor to use strength factor */
 		fragColor.a = min(fragColor.a * tColor.a, fragColor.a);
 	}
 	/* pattern */
 	if (color_type == GPENCIL_COLOR_PATTERN) {
-		vec4 text_color = texture2D(myTexture, mTexCoord);
 		fragColor = tColor;
 		/* mult both alpha factor to use strength factor with color alpha limit */
 		fragColor.a = min(text_color.a * tColor.a, tColor.a);
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 0caeb4c9d63..a3780a3dd4f 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
@@ -158,25 +158,24 @@ void main(void)
 	}
 
 	/* generate the start endcap */
-	if ((caps_mode[0] != GPENCIL_FLATCAP) && is_equal(P0,P2) &&
-		(color_type == GPENCIL_COLOR_SOLID))
+	if ((caps_mode[0] != GPENCIL_FLATCAP) && is_equal(P0,P2))
 	{
 		vec4 cap_color = finalColor[1];
 
-		mTexCoord = vec2(2.0, 1.0);
+		mTexCoord = vec2(2.0, 0.5);
 		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, 0.0);
+		mTexCoord = vec2(0.0, -0.5);
 		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.0, 2.0);
+		mTexCoord = vec2(0.0, 1.5);
 		mColor = cap_color;
 		uvfac = vec2(0.0, 1.0);
 		gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0);
@@ -206,24 +205,23 @@ void main(void)
 	EmitVertex();
 
 	/* generate the end endcap */
-	if ((caps_mode[1] != GPENCIL_FLATCAP) && is_equal(P1,P3) &&
-		(color_type == GPENCIL_COLOR_SOLID) && (finaluvdata[2].x > 0))
+	if ((caps_mode[1] != GPENCIL_FLATCAP) && is_equal(P1,P3) && (finaluvdata[2].x > 0))
 	{
 		vec4 cap_color = finalColor[2];
 
-		mTexCoord = vec2(finaluvdata[2].x, 2.0);
+		mTexCoord = vec2(finaluvdata[2].x, 1.5);
 		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.0);
+		mTexCoord = vec2(finaluvdata[2].x, -0.5);
 		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.0);
+		mTexCoord = vec2(finaluvdata[2].x + 2, 0.5);
 		mColor = cap_color;
 		uvfac = vec2(finaluvdata[2].x, 1.0);
 		vec2 svn2 =  normalize(sp2 - sp1) * length_b * 4.0;



More information about the Bf-blender-cvs mailing list