Font: Distance Field Label Shader

Font: Distance Field Label Shader
0.0 0

#1

I use TTF with Distance Field Mode. When I scale down font using setScale method it looks little bit fuzzy.

I look on the fragment shader in the ccShader_Label_df.frag file.

It has a comment about this temporary issue. How to fix it?

const char* ccLabelDistanceFieldNormal_frag = R"(

#ifdef GL_ES
precision lowp float;
#endif

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

uniform vec4 u_textColor;

void main()
{
    vec4 color = texture2D(CC_Texture0, v_texCoord);
    //the texture use dual channel 16-bit output for distance_map
    //float dist = color.b+color.g/256.0;
    // the texture use single channel 8-bit output for distance_map
    float dist = color.a;
    //TODO: Implementation 'fwidth' for glsl 1.0
    //float width = fwidth(dist);
    //assign width for constant will lead to a little bit fuzzy,it's temporary measure.
    float width = 0.04;
    float alpha = smoothstep(0.5-width, 0.5+width, dist) * u_textColor.a;
    gl_FragColor = v_fragmentColor * vec4(u_textColor.rgb,alpha);
}
)";

I copied this file on my app folder and uncomment this line

#ifdef GL_ES
precision lowp float;
#endif

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

uniform vec4 u_textColor;

void main()
{
    vec4 color = texture2D(CC_Texture0, v_texCoord);
    //the texture use dual channel 16-bit output for distance_map
    //float dist = color.b+color.g/256.0;
    // the texture use single channel 8-bit output for distance_map
    float dist = color.a;
    //TODO: Implementation 'fwidth' for glsl 1.0
    float width = fwidth(dist);
    //assign width for constant will lead to a little bit fuzzy,it's temporary measure.
    //float width = 0.04;
    float alpha = smoothstep(0.5-width, 0.5+width, dist) * u_textColor.a;
    gl_FragColor = v_fragmentColor * vec4(u_textColor.rgb,alpha);
}

and apply it as a custom shader on first label. But now it has horizontal lines


How can i fix these problems?


V3.16 documentation requests
#2

Nobody knows?


#3

#4

Could it be related to distance field mipmaps?
Also: are you nodes scaled (total combined child-parent scale different than 1.0)?