2014-05-10 10:13:12 +08:00
|
|
|
/*
|
|
|
|
* LICENSE ???
|
|
|
|
*/
|
2016-11-02 14:13:34 +08:00
|
|
|
const char* ccLabelOutline_frag = R"(
|
2016-10-26 16:03:08 +08:00
|
|
|
#ifdef GL_ES
|
2016-11-02 14:13:34 +08:00
|
|
|
precision lowp float;
|
2016-10-26 16:03:08 +08:00
|
|
|
#endif
|
2016-11-02 14:13:34 +08:00
|
|
|
|
|
|
|
varying vec4 v_fragmentColor;
|
2014-05-16 08:22:53 +08:00
|
|
|
varying vec2 v_texCoord;
|
|
|
|
|
|
|
|
uniform vec4 u_effectColor;
|
|
|
|
uniform vec4 u_textColor;
|
2016-11-02 14:13:34 +08:00
|
|
|
|
2016-12-16 14:56:36 +08:00
|
|
|
#ifdef GL_ES
|
|
|
|
uniform lowp int u_effectType; // 0: None (Draw text), 1: Outline, 2: Shadow
|
|
|
|
#else
|
|
|
|
uniform int u_effectType;
|
|
|
|
#endif
|
|
|
|
|
2014-05-10 07:45:42 +08:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 sample = texture2D(CC_Texture0, v_texCoord);
|
2016-12-16 14:56:36 +08:00
|
|
|
// fontAlpha == 1 means the area of solid text (without edge)
|
|
|
|
// fontAlpha == 0 means the area outside text, including outline area
|
|
|
|
// fontAlpha == (0, 1) means the edge of text
|
|
|
|
float fontAlpha = sample.a;
|
2016-10-19 10:19:14 +08:00
|
|
|
|
2016-12-16 14:56:36 +08:00
|
|
|
// outlineAlpha == 1 means the area of 'solid text' and 'solid outline'
|
|
|
|
// outlineAlpha == 0 means the transparent area outside text and outline
|
|
|
|
// outlineAlpha == (0, 1) means the edge of outline
|
|
|
|
float outlineAlpha = sample.r;
|
|
|
|
|
|
|
|
if (u_effectType == 0) // draw text
|
2016-10-19 10:19:14 +08:00
|
|
|
{
|
2016-12-16 14:56:36 +08:00
|
|
|
gl_FragColor = v_fragmentColor * vec4(u_textColor.rgb, u_textColor.a * fontAlpha);
|
2016-10-19 10:19:14 +08:00
|
|
|
}
|
2016-12-16 14:56:36 +08:00
|
|
|
else if (u_effectType == 1) // draw outline
|
2016-10-19 10:19:14 +08:00
|
|
|
{
|
2016-12-16 14:56:36 +08:00
|
|
|
// multipy (1.0 - fontAlpha) to make the inner edge of outline smoother and make the text itself transparent.
|
|
|
|
gl_FragColor = v_fragmentColor * vec4(u_effectColor.rgb, u_effectColor.a * outlineAlpha * (1.0 - fontAlpha));
|
2014-05-10 07:45:42 +08:00
|
|
|
}
|
2016-12-16 14:56:36 +08:00
|
|
|
else // draw shadow
|
2016-10-19 10:19:14 +08:00
|
|
|
{
|
2016-12-16 14:56:36 +08:00
|
|
|
gl_FragColor = v_fragmentColor * vec4(u_effectColor.rgb, u_effectColor.a * outlineAlpha);
|
2014-05-10 07:45:42 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 14:13:34 +08:00
|
|
|
)";
|