Make AA stronger for undercurl

This improves undercurl rendering preserving its original thickness.
This also makes it look not out-of place when places next to other
lines.
This commit is contained in:
Kirill Chibisov 2023-11-24 23:57:43 +04:00 committed by GitHub
parent 3bb4fb78b4
commit 54889fc4ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -45,7 +45,11 @@ color_t draw_undercurl(float_t x, float_t y) {
// cosine curve.
float_t alpha = 1.;
if (y > undercurlTop || y < undercurlBottom) {
alpha = 1. - min(abs(undercurlTop - y), abs(undercurlBottom - y));
// 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 result is an alpha mask on a rect, which leaves only curve opaque.