aboutsummaryrefslogtreecommitdiff
path: root/alacritty/res
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2022-02-08 20:47:31 +0300
committerGitHub <noreply@github.com>2022-02-08 20:47:31 +0300
commit73c3dd86280e98e11f080123aec47d08f3a76b49 (patch)
treec54d98dd763c12876235acc9880be5ec069c52b6 /alacritty/res
parent7263d223bf535fdffe00d5d9d398a8d188b3c185 (diff)
downloadr-alacritty-73c3dd86280e98e11f080123aec47d08f3a76b49.tar.gz
r-alacritty-73c3dd86280e98e11f080123aec47d08f3a76b49.tar.bz2
r-alacritty-73c3dd86280e98e11f080123aec47d08f3a76b49.zip
Add support for drawing undercurls
Fixes #1628.
Diffstat (limited to 'alacritty/res')
-rw-r--r--alacritty/res/rect.f.glsl45
1 files changed, 44 insertions, 1 deletions
diff --git a/alacritty/res/rect.f.glsl b/alacritty/res/rect.f.glsl
index 945eaf2d..00c2de83 100644
--- a/alacritty/res/rect.f.glsl
+++ b/alacritty/res/rect.f.glsl
@@ -1,10 +1,53 @@
#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()
{
- FragColor = color;
+ 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;
+
+ float undercurl_top = undercurl + undercurlThickness / 2.;
+ float undercurl_bottom = undercurl - undercurlThickness / 2.;
+
+
+ // 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);
}