File: agg-glyph.frag

package info (click to toggle)
python-vispy 0.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,240 kB
  • sloc: python: 57,407; javascript: 6,810; makefile: 63; sh: 5
file content (60 lines) | stat: -rw-r--r-- 1,748 bytes parent folder | download | duplicates (5)
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
// ----------------------------------------------------------------------------
// Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
// Distributed under the (new) BSD License.
// ----------------------------------------------------------------------------

// Uniforms
// ------------------------------------
uniform sampler2D atlas_data;
uniform vec2      atlas_shape;

// Varyings
// ------------------------------------
varying vec4  v_color;
varying float v_offset;
varying vec2  v_texcoord;


// Main
// ------------------------------------
void main(void)
{
    <viewport.clipping>;

    vec2 viewport = <viewport.viewport_global>.zw;

    vec4 current = texture2D(atlas_data, v_texcoord);
    vec4 previous= texture2D(atlas_data, v_texcoord+vec2(-1.0,0.0)/viewport);
    vec4 next    = texture2D(atlas_data, v_texcoord+vec2(+1.0,0.0)/viewport);

    float r = current.r;
    float g = current.g;
    float b = current.b;

    if( v_offset < 1.0 )
    {
        float z = v_offset;
        r = mix(current.r, previous.b, z);
        g = mix(current.g, current.r,  z);
        b = mix(current.b, current.g,  z);
    }
    else if( v_offset < 2.0 )
    {
        float z = v_offset - 1.0;
        r = mix(previous.b, previous.g, z);
        g = mix(current.r,  previous.b, z);
        b = mix(current.g,  current.r,  z);
    }
   else //if( v_offset <= 1.0 )
    {
        float z = v_offset - 2.0;
        r = mix(previous.g, previous.r, z);
        g = mix(previous.b, previous.g, z);
        b = mix(current.r,  previous.b, z);
    }

   float t = max(max(r,g),b);
   vec4 color = vec4(v_color.rgb, (r+g+b)/3.0);
   color = t*color + (1.0-t)*vec4(r,g,b, min(min(r,g),b));
   gl_FragColor = vec4( color.rgb, v_color.a*color.a);
}