File: moglFDFForegroundDotsRenderShader.frag.txt

package info (click to toggle)
psychtoolbox-3 3.0.17.9.dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 84,408 kB
  • sloc: ansic: 171,572; cpp: 20,885; objc: 5,164; sh: 1,878; python: 1,366; php: 384; makefile: 193; java: 113
file content (66 lines) | stat: -rw-r--r-- 2,580 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* FDF shader for sampling of tracked object surface at provided sampling
 * positions from sample distribution in order to update foreground dot
 * position distribution.
 *
 * (c) 2008 by Mario Kleiner, licensed under MIT license.
 */

#extension GL_ARB_texture_rectangle : enable


uniform sampler2DRect SampleBuffer;
uniform sampler2DRect GeometryBuffer;
uniform sampler2DRect Silhouette;

uniform float zThreshold;
uniform float ViewportHeight;
uniform vec2  texWrapAround;
uniform vec4  TextureOffsetBias;
uniform vec4  clipVertex;

void main(void)
{
    /* Read sample definition from SampleBuffer: */
    vec3 sample = texture2DRect(SampleBuffer, gl_TexCoord[0].st).rgb;

    /* Valid sample, ie. blue channel greater zero? */
    if (sample.b > 0.0) {
        /* Valid sample: Readout (x,y) position from trackbuffer: */
        /* Use bilinear filtering to reduce aliasing artifacts: */
        vec2 texinpos = sample.rg;

        vec4 tl=texture2DRect(GeometryBuffer, mod(floor(texinpos), texWrapAround));
        vec4 tr=texture2DRect(GeometryBuffer, mod(floor(texinpos) + vec2(1.0, 0.0), texWrapAround));
        vec4 bl=texture2DRect(GeometryBuffer, mod(floor(texinpos) + vec2(0.0, 1.0), texWrapAround));
        vec4 br=texture2DRect(GeometryBuffer, mod(floor(texinpos) + vec2(1.0, 1.0), texWrapAround));

        /* Perform weighted linear interpolation -- bilinear interpolation of the 4: */
        tl=mix(tl,tr,fract(texinpos.x));
        bl=mix(bl,br,fract(texinpos.x));
        vec4 position = mix(tl, bl, fract(texinpos.y));

        /* Potential zpos from GeometryBuffer: */
        float zpos = position.b;

        /* Reference zdepth from Silhouette: */
        float refz = texture2DRect(Silhouette, position.xy).a;

        /* Check for occlusion - Discard this vertex if z-values do not match aka occluded: */
        if (abs(zpos - refz) > zThreshold) {
            /* Discard this hidden vertex: Set it to a position that will get clipped away: */
            gl_FragColor = clipVertex;
        }
        else {
            /* Return dot (x,y) image plane position in R and G channels: */
            gl_FragColor.rg = vec2(position.x, ViewportHeight - position.y);

            /* Set (z,w) components (aka (b,a)) to remapped 'texinpos' texture coordinates of sample: */
            gl_FragColor.ba = (texinpos * TextureOffsetBias.zw) + TextureOffsetBias.xy;
        }
    }
    else {
        /* Dead/Invalid sample: Writeout a null vertex which will */
        /* get clipped away during rendering: */
        gl_FragColor = clipVertex; 
    }
}