File: moglFDFRectTexturedDotsRenderShader.frag.txt

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (40 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* 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);
    }
}