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.
This commit is contained in:
Antonio Vazquez 2019-03-06 17:56:55 +01:00
parent 8eca5c3f7a
commit 59f30e9390
Notes: blender-bot 2023-02-14 06:42:54 +01:00
Referenced by issue #62279, Rendering simple geometry corrupts with greasepencil layer
2 changed files with 24 additions and 15 deletions

View File

@ -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);

View File

@ -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;