File: edge.frag

package info (click to toggle)
solvespace 3.1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 15,960 kB
  • sloc: cpp: 122,491; ansic: 11,375; javascript: 1,919; sh: 89; xml: 44; makefile: 25
file content (35 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download | duplicates (4)
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
//-----------------------------------------------------------------------------
// Edge rendering shader
//
// Copyright 2016 Aleksey Egorov
//-----------------------------------------------------------------------------
const float feather = 0.5;

uniform vec4 color;
uniform float pixel;
uniform float width;
uniform float patternLen;
uniform float patternScale;
uniform sampler2D pattern;

varying vec3 fragLoc;

void main() {
    // lookup distance texture
    vec4 v = texture2D(pattern, vec2(fragLoc.z / patternScale, 0.0));

    // decode distance value
    float val = dot(v, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));

    // calculate cap
    float dist = length(vec2(val * patternScale / (patternLen * width) + abs(fragLoc.x), fragLoc.y));

    // perform antialiasing
    float k = smoothstep(1.0 - 2.0 * feather * pixel / (width + feather * pixel), 1.0, abs(dist));

    // perform alpha-test
    if(k == 1.0) discard;

    // write resulting color
    gl_FragColor = vec4(color.rgb, color.a * (1.0 - k));
}