mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Optimize undercurl shader
This removes the if and lowers amount of operations.
This commit is contained in:
parent
28d913cfd0
commit
546d5951aa
1 changed files with 11 additions and 10 deletions
|
@ -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 undercurlTop = undercurl + max((underlineThickness - 1.), 0.) / 2.;
|
||||||
float_t undercurlBottom = 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
|
// The distance to the curve boundary is always positive when it should
|
||||||
// cosine curve.
|
// be used for AA. When both `y - undercurlTop` and `undercurlBottom - y`
|
||||||
float_t alpha = 1.;
|
// expressions are negative, it means that the point is inside the curve
|
||||||
if (y > undercurlTop || y < undercurlBottom) {
|
// 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
|
// Doing proper SDF is complicated for this shader, so just make AA
|
||||||
// stronger by 1/x^2, which renders preserving underline thickness and
|
// stronger by 1/x^2, which renders preserving underline thickness and
|
||||||
// being bold enough.
|
// being bold enough.
|
||||||
float_t dst = min(abs(undercurlTop - y), abs(undercurlBottom - y));
|
float_t alpha = 1. - dst * dst;
|
||||||
alpha -= dst * dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The result is an alpha mask on a rect, which leaves only curve opaque.
|
// The result is an alpha mask on a rect, which leaves only curve opaque.
|
||||||
return vec4(color.rgb, alpha);
|
return vec4(color.rgb, alpha);
|
||||||
|
|
Loading…
Reference in a new issue