File: marker-sdf.frag

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (74 lines) | stat: -rw-r--r-- 2,936 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// ----------------------------------------------------------------------------
// Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
// Distributed under the (new) BSD License.
// ----------------------------------------------------------------------------
#version 120

// Constants
// ------------------------------------
const float SQRT_2 = 1.4142135623730951;

// Uniforms
// ------------------------------------
uniform sampler2D u_texture;
uniform vec2 u_texture_shape;

// Varyings
// ------------------------------------
varying float v_antialias;
varying float v_linewidth;
varying vec4  v_fg_color;
varying vec4  v_bg_color;
varying float v_size;
varying vec2  v_rotation;

vec4 Nearest(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Bilinear(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Hanning(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Hamming(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Hermite(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Kaiser(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Quadric(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Bicubic(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 CatRom(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Mitchell(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Spline16(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Spline36(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Gaussian(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Bessel(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Sinc(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Lanczos(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);
vec4 Blackman(sampler2D u_data, vec2 u_shape, vec2 v_texcoord);

void main()
{
    vec2 P = gl_PointCoord.xy - vec2(0.5,0.5);
    P = vec2(v_rotation.x*P.x - v_rotation.y*P.y,
             v_rotation.y*P.x + v_rotation.x*P.y);
    P += vec2(0.5,0.5);

    float r = v_size + 2*(v_linewidth + 1.5*v_antialias);
    // float signed_distance = r * (texture2D(u_texture, P).r - 0.5);
    float signed_distance = r * (Bicubic(u_texture, u_texture_shape, P).r - 0.5);
    float t = v_linewidth/2.0 - v_antialias;
    float border_distance = abs(signed_distance) - t;
    float alpha = border_distance/v_antialias;
    alpha = exp(-alpha*alpha);


    // Within linestroke
    if( border_distance < 0 )
        gl_FragColor = v_fg_color;
    else if( signed_distance < 0 )
        // Inside shape
        if( border_distance > (v_linewidth/2.0 + v_antialias) )
            gl_FragColor = v_bg_color;
        else // Line stroke interior border
            gl_FragColor = mix(v_bg_color,v_fg_color,alpha);
    else
        // Outide shape
        if( border_distance > (v_linewidth/2.0 + v_antialias) )
            discard;
        else // Line stroke exterior border
            gl_FragColor = vec4(v_fg_color.rgb, v_fg_color.a * alpha);
}