I am currently learning the SKEffect+SKShader from SpriteKit to apply gradient color on SKLabels, and I was wondering if there is a way to outline the font as well. Like this: Image
Currently, I'm using this code which is doing just okish, but this should not be the right way. My goal is to make it thicker.
void main()
{
vec4 color = texture2D(u_texture, v_tex_coord);
float gradient = 0.0;
// Black Stroke if alpha value ranges from 0.1 to 0.99
if (color.a > 0.1 && color.a < 0.99){
gl_FragColor = vec4(0,0,0,1);
}
else{
if (v_tex_coord.y < 0.5){
gradient = 0.35 - v_tex_coord.y;
}
else if (v_tex_coord.y < 0.7){
gradient = -0.15 - v_tex_coord.y*0.005;
}
else if ( v_tex_coord.y >= 0.7){
gradient = -0.15 - 0.7*0.005;
}
color = vec4(gradient + color.r, gradient + color.g, gradient + color.b, color.a);
color.rgb *= color.a; // set background to alpha 0
gl_FragColor = color;
}
}
Feel free to check out the repository. I have just released yesterday for the public.