/* FDF shader for drawing 2D dots, applying a texture to them.
 * The shader just implements standard texture mapping, the only
 * speciality is that it mixes a constant settable color with the
 * texels color, controlled by a mix weight.
 *
 * This to control the amount of object color information present in
 * the 2D dot stimuli, kind of a SNR between dynamic and static form.
 *
 * (c) 2009 by Mario Kleiner, licensed under MIT license.
 */

#extension GL_ARB_texture_rectangle : enable

uniform sampler2DRect Image;
uniform int        doSmooth;
uniform float     texWeight;

void main(void)
{
    const float b = 0.1;
    float r;

    /* Read texel from texture: */
    vec4 texel = texture2DRect(Image, gl_TexCoord[0].st);

    /* Mix RGB colors between constant color and texel: */
    gl_FragColor.rgb = mix(gl_Color.rgb, texel.rgb, texWeight);

    /* Take alpha component from constant color: */
    gl_FragColor.a = gl_Color.a;

    if (doSmooth > 0) {
        /* We adapt alpha value dependent on radius within a dot: */
        /* This for point smoothing on GPU's that don't support this with shaders: */
        /* 'b' controls smoothness of transition area, 0.5 is max radius at which */
        /* point completely disappears, ie., alpha = 0. */
        r = length(gl_TexCoord[1].st - vec2(0.5, 0.5));
        gl_FragColor.a = gl_FragColor.a * smoothstep(r, r + b, 0.5);
    }
}
