diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-12-01 21:40:20 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 21:40:20 +0400 |
commit | 546d5951aa369674e8a3c6e8ac716f07481368bd (patch) | |
tree | 2b0ce52a51b7ed0c2eab59edc2bd58fca248b356 | |
parent | 28d913cfd09df2a520a3d285f6abc0ece4e1035b (diff) | |
download | alacritty-546d5951aa369674e8a3c6e8ac716f07481368bd.tar.gz alacritty-546d5951aa369674e8a3c6e8ac716f07481368bd.zip |
Optimize undercurl shader
This removes the if and lowers amount of operations.
-rw-r--r-- | alacritty/res/rect.f.glsl | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/alacritty/res/rect.f.glsl b/alacritty/res/rect.f.glsl index 9951861f..5436aead 100644 --- a/alacritty/res/rect.f.glsl +++ b/alacritty/res/rect.f.glsl @@ -41,16 +41,17 @@ color_t draw_undercurl(float_t x, float_t y) { float_t undercurlTop = undercurl + max((underlineThickness - 1.), 0.) / 2.; float_t undercurlBottom = undercurl - max((underlineThickness - 1.), 0.) / 2.; - // Compute resulted alpha based on distance from `gl_FragCoord.y` to the - // cosine curve. - float_t alpha = 1.; - if (y > undercurlTop || y < undercurlBottom) { - // Doing proper SDF is complicated for this shader, so just make AA - // stronger by 1/x^2, which renders preserving underline thickness and - // being bold enough. - float_t dst = min(abs(undercurlTop - y), abs(undercurlBottom - y)); - alpha -= dst * dst; - } + // The distance to the curve boundary is always positive when it should + // be used for AA. When both `y - undercurlTop` and `undercurlBottom - y` + // expressions are negative, it means that the point is inside the curve + // and we should just use alpha 1. To do so, we max one value with 0 + // so it'll use the alpha 1 in the end. + float_t dst = max(y - undercurlTop, max(undercurlBottom - y, 0.)); + + // Doing proper SDF is complicated for this shader, so just make AA + // stronger by 1/x^2, which renders preserving underline thickness and + // being bold enough. + float_t alpha = 1. - dst * dst; // The result is an alpha mask on a rect, which leaves only curve opaque. return vec4(color.rgb, alpha); |