IOS SpriteKit - SKLabel Outline Font (SKShader)

I'm currently studying SpriteKit's SKEffect + SKShader to apply gradient color on SKLabels, and I was wondering if there is a way to outline the font. Like this: Image

I am currently using this code which only makes beautiful, but that 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;
        }

}

Remember to check the repository. I just published yesterday to the public.

https://github.com/woguan/Legend-Wings

+4
source share

Source: https://habr.com/ru/post/1680948/


All Articles