uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
varying float sdist;

void main()
{
    vec4 fade = texture2D(tex0, gl_TexCoord[0].st);
    vec4 bright = texture2D(tex1, gl_TexCoord[0].st);
    vec4 noise = texture2D(tex2, gl_TexCoord[1].st);
    gl_FragColor.rgb = 
        (fade.rgb * gl_Color.rgb * fade.a * 0.4
        + mix(bright.rgb, gl_Color.rgb, min(1.0, sdist/20.0)) * bright.a * 0.25)
        * noise.rgb;
    gl_FragColor.a = 1.0;
}