aboutsummaryrefslogtreecommitdiff
path: root/alacritty/res/rect.f.glsl
blob: ab1d9dcd22d8a5086ecf77af68763480029c6658 (plain) (blame)
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
#version 330 core

// We're using `origin_upper_left`, since we only known about padding from left
// and top. If we use default `origin_bottom_left` we won't be able to offset
// `gl_FragCoord` properly to align with the terminal grid.
layout(origin_upper_left) in vec4 gl_FragCoord;

flat in vec4 color;

out vec4 FragColor;

uniform int isUndercurl;

uniform float cellWidth;
uniform float cellHeight;
uniform float paddingY;
uniform float paddingX;

uniform float undercurlThickness;
uniform float undercurlPosition;

#define PI 3.1415926538

void main()
{
    if (isUndercurl == 0) {
        FragColor = color;
        return;
    }

    int x = int(gl_FragCoord.x - paddingX) % int(cellWidth);
    int y = int(gl_FragCoord.y - paddingY) % int(cellHeight);

    // We use `undercurlPosition` as amplitude, since it's half of the descent
    // value.
    float undercurl = -1. * undercurlPosition / 2.
        * cos(float(x) * 2 * PI / float(cellWidth))
        + cellHeight - undercurlPosition;

    // We subtract one, since curve is already 1px thick.
    float undercurl_top = undercurl + max((undercurlThickness - 1), 0);
    float undercurl_bottom = undercurl - max((undercurlThickness - 1), 0);


    // Compute resulted alpha based on distance from `gl_FragCoord.y` to the
    // cosine curve.
    float alpha = 1.;
    if (y > undercurl_top || y < undercurl_bottom) {
        alpha = 1. - min(abs(undercurl_top - y), abs(undercurl_bottom - y));
    }

    // The result is an alpha mask on a rect, which leaves only curve opaque.
    FragColor = vec4(color.xyz, alpha);
}