mirror of https://github.com/axmolengine/axmol.git
Fixes label wrong blending and improves performance while enabling outline. (#16717)
This commit is contained in:
parent
90db0eb6bf
commit
a5fdc07fca
|
@ -15,13 +15,28 @@ uniform vec4 u_textColor;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 sample = texture2D(CC_Texture0, v_texCoord);
|
vec4 sample = texture2D(CC_Texture0, v_texCoord);
|
||||||
float fontAlpha = sample.a;
|
float fontAlpha = sample.a; // sample.a == 1 indicates text, a == 0 indicates outline
|
||||||
float outlineAlpha = sample.r;
|
float outlineAlpha = sample.r; // sample.r always > 0
|
||||||
if ((fontAlpha + outlineAlpha) > 0.0){
|
|
||||||
vec4 color = u_textColor * fontAlpha + u_effectColor * (1.0 - fontAlpha);
|
if (u_effectColor.a > 0.0) // draw outline
|
||||||
gl_FragColor = v_fragmentColor * vec4( color.rgb,max(fontAlpha,outlineAlpha)*color.a);
|
{
|
||||||
|
if (fontAlpha < 1.0)
|
||||||
|
{
|
||||||
|
gl_FragColor = v_fragmentColor * vec4(u_effectColor.rgb, u_effectColor.a * outlineAlpha);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
discard; // While drawing outline, text should not be drawn since it will be drawn in next step.
|
||||||
|
// discard this pixel could improve a little and fix wrong alpha blending if text contains
|
||||||
|
// alpha channel.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (fontAlpha > 0.0) // draw text
|
||||||
|
{
|
||||||
|
gl_FragColor = v_fragmentColor * vec4(u_textColor.rgb, u_textColor.a * fontAlpha);
|
||||||
|
}
|
||||||
|
else // discard the pixel in texture rectangle which is transparent
|
||||||
|
{
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue