<commit_before>uniform sampler2D fontTexture;
uniform float opacity;
uniform bool showBorder;
uniform vec3 borderColor;
uniform float borderWidth;
uniform vec3 backgroundColor;
uniform float backgroundOpacity;

varying vec3 vViewPosition;
varying vec2 texCoord;

#include common
#include color_pars_fragment
#include fog_pars_fragment

#ifdef SDF
    const float smoothness = 16.0;
#else
    const float smoothness = 256.0;
#endif
const float gamma = 2.2;

void main(){

    if( texCoord.x == 10.0 ){

        gl_FragColor = vec4( backgroundColor, backgroundOpacity );

    }else{

        // retrieve signed distance
        float sdf = texture2D( fontTexture, texCoord ).a;
        if( showBorder ) sdf += borderWidth;

        // perform adaptive anti-aliasing of the edges
        float w = clamp(
            smoothness * ( abs( dFdx( texCoord.x ) ) + abs( dFdy( texCoord.y ) ) ),
            0.0,
            0.5
        );
        float a = smoothstep( 0.5 - w, 0.5 + w, sdf );

        // gamma correction for linear attenuation
        a = pow( a, 1.0 / gamma );
        if( a < 0.2 ) discard;
        a *= opacity;

        vec3 outgoingLight = vColor;
        if( showBorder && sdf < ( 0.5 + borderWidth ) ){
            outgoingLight = borderColor;
        }

        gl_FragColor = vec4( outgoingLight, a );

    }

    #include premultiplied_alpha_fragment
    #include tonemapping_fragment
    #include encodings_fragment
    #include fog_fragment

}<commit_msg>fixed precision issues rendering the background of SDF text<commit_after>uniform sampler2D fontTexture;
uniform float opacity;
uniform bool showBorder;
uniform vec3 borderColor;
uniform float borderWidth;
uniform vec3 backgroundColor;
uniform float backgroundOpacity;

varying vec3 vViewPosition;
varying vec2 texCoord;

#include common
#include color_pars_fragment
#include fog_pars_fragment

#ifdef SDF
    const float smoothness = 16.0;
#else
    const float smoothness = 256.0;
#endif
const float gamma = 2.2;

void main(){

    if( texCoord.x > 1.0 ){

        gl_FragColor = vec4( backgroundColor, backgroundOpacity );

    }else{

        // retrieve signed distance
        float sdf = texture2D( fontTexture, texCoord ).a;
        if( showBorder ) sdf += borderWidth;

        // perform adaptive anti-aliasing of the edges
        float w = clamp(
            smoothness * ( abs( dFdx( texCoord.x ) ) + abs( dFdy( texCoord.y ) ) ),
            0.0,
            0.5
        );
        float a = smoothstep( 0.5 - w, 0.5 + w, sdf );

        // gamma correction for linear attenuation
        a = pow( a, 1.0 / gamma );
        if( a < 0.2 ) discard;
        a *= opacity;

        vec3 outgoingLight = vColor;
        if( showBorder && sdf < ( 0.5 + borderWidth ) ){
            outgoingLight = borderColor;
        }

        gl_FragColor = vec4( outgoingLight, a );

    }

    #include premultiplied_alpha_fragment
    #include tonemapping_fragment
    #include encodings_fragment
    #include fog_fragment

}
{'fraction_non_alphanumeric': 0.08972648432288192, 'fraction_numerical': 0.023015343562374918, 'mean_word_length': 2.4352806414662083, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4704272', 'n_tokens_mistral': 963, 'n_tokens_neox': 892, 'n_words': 280}