wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.84k stars 799 forks source link

Antialiasing artifacts with dark on light text #413

Closed dmfay closed 3 years ago

dmfay commented 3 years ago

Some normal-weight dark text on lighter backgrounds appears extra-bold and slightly artifacted instead. The red-on-cyan messages in these neovim screenshots show it very well (termite above, wezterm below):

termite-wezterm-multiply

Switching to vim's default colorscheme, elements of the statusline are affected (again termite above):

1609615929

I initially thought it had something to do with the alpha blending after #331 and experimented a bit with that, but subpixel antialiasing is noticeably at least less bold than the greyscale above, if rather blurry:

1609615415

click for terminal font/color config ```lua font = wezterm.font_with_fallback({"InconsolataGo Nerd Font", "InconsolataGo", "Inconsolata-dz", "FontAwesome5Free", "JoyPixels"}), font_size = 15.0, font_hinting = "Vertical", font_antialias = "Greyscale", colors = { foreground = "#f5eff3", cursor_border = "#f5eff3", cursor_bg = "#f5eff3", cursor_fg = "#3c3445", background = "#3c3445", ansi = { "#3c3445", "#9c6b80", "#6e916e", "#9c8969", "#6582c7", "#a276b6", "#6698aa", "#cfc7cd" }, brights = { "#604c60", "#dc98ac", "#96c497", "#d9bd8f", "#98b2fb", "#d6ade8", "#9ccbdd", "#f5eff3" } } ```
uname -a:
Linux lamia 5.9.14-arch1-1 #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux

wezterm -V:
wezterm 20201101-103216-403d002d-213-gb8cabc50

Here's a recording of me opening nvim and changing the colorscheme to default: 2021-01-02.zip

wez commented 3 years ago

Just a quick comment for the moment; don't have time to dig in right now.

You may want to experiment with:

freetype_interpreter_version = 35

freetype_interpreter_version = 38

freetype_interpreter_version = 40

which is a new option that can impact this.

dmfay commented 3 years ago

No discernible changes with any of those, unfortunately.

wez commented 3 years ago

I've been idly looking at this on my mac this evening. I didn't try exactly your config so it's not an ideal test.

This prints black and red text on a cyan background to emulate the vim output:

$ printf "\e[46m\e[30m[foo\e[0m\e[46m\e[31mbar]\e[0m"

It doesn't look as bad with my font with those colors as the case in your OP (I'm lazily looking at this while watching tv).

There's some logic over here that doesn't use normal alpha blending to compensate for weirdness with wayland/mutter:

https://github.com/wez/wezterm/blob/master/wezterm-gui/src/gui/termwindow.rs#L2772-L2792

I'm not super sure that that is in the right spot any more (since adding transparency and background images, I think that compensation should happen in an earlier pass).

Ignoring that though, we can try normal blending for the pass that renders the glyphs themselves:

$ git diff
diff --git a/wezterm-gui/src/gui/termwindow.rs b/wezterm-gui/src/gui/termwindow.rs
index 2e54e66a..ff9db376 100644
--- a/wezterm-gui/src/gui/termwindow.rs
+++ b/wezterm-gui/src/gui/termwindow.rs
@@ -2807,6 +2807,11 @@ impl TermWindow {
             &draw_params,
         )?;

+        let draw_params = glium::DrawParameters {
+            blend: glium::Blend::alpha_blending(),
+            ..Default::default()
+        };
+
         // Pass 3: Draw glyphs
         frame.draw(
             &*vb,

with that in place, the text looks slightly brighter/smoother to me if I magnify the screen using the macOS screen zoom feature. I don't know that it's a slam-dunk, but it may be worth you trying that diff locally and see if it improves things?

I'll make another pass at this on my linux system when I've got a bit more bandwidth!

dmfay commented 3 years ago

That is a big improvement! I think the boldness by comparison with termite has something to do with my font fallbacks, and wezterm is actually rendering a bold face.

1612369308 1612369222

(both wezterm)

wez commented 3 years ago

I shipped the diff that I suggested as part of the 20210203-095643-70a364eb release. I think I agree that the boldness in the OP is a function of your font fallback. Do you consider this to be resolved, or is there more to investigate?

dmfay commented 3 years ago

I think we're set here!

evs-ch commented 3 years ago

I'll just hijack this issue, as my issue seems to be caused by the fix for this one – if I should open a separate issue instead, I'd happily oblige, of course!

Basically I have artifacts looking quite related only with all versions of wezterm with the fix from 70a364eb3fd5624d950f6ed87a239f97b00c6028 applied. To pinpoint it, I have build a version from 70a364eb3fd5624d950f6ed87a239f97b00c6028 as well as one from the parent commit (dafb429da0645bba6499b338f8c15f0a10619a1d).

My environment is: Linux Wayland with sway (Arch), but it also seems to happen for a colleague on X11 as well.

Things I have already tried: Using a different font, different font_antialias or font_hinting settings, enabling/disabling wayland, disabling bold_brightens_ansi_colors, removing allow_square_glyphs_to_overflow_width = 'Always', trying the different freetype_interpreter_version options and disabling my colors altogether.

It also does happen inside as well as outside of tmux.

Interestingly, those artifacts only begin to become really obvious towards the center of the screen.

To show the kind of artifacts that appear, here are two screenshots with the printf "\e[46m\e[30m[foo\e[0m\e[46m\e[31mbar]\e[0m" command from above run in different places with the two versions:

Using a build from dafb429da0645bba6499b338f8c15f0a10619a1d

image

Using a build from 70a364eb3fd5624d950f6ed87a239f97b00c6028

image

My unmodified (as in: without the attempts to mitigate it, as described above) wezterm.lua is:

local wezterm = require 'wezterm';
function font_with_fallback(name, params)
  local names = {name, "Hack NF JBM Ligatured", "JetBrains Mono", "Noto Color Emoji"}
  return wezterm.font_with_fallback(names, params)
end
return {
  font_size = 12.0,
  font_antialias = "Subpixel", -- None, Greyscale, Subpixel
  font_hinting = "Full",  -- None, Vertical, VerticalSubpixel, Full
  bold_brightens_ansi_colors = true,
  scrollback_lines = 10000,
  enable_wayland = true,
  font = font_with_fallback("Hack JBM Ligatured"),
  allow_square_glyphs_to_overflow_width = 'Always',
  colors = {
      foreground = "#7E8792",
      background = "#262626",
      cursor_bg = "#55606d",
      cursor_fg = "#262626",
      cursor_border = "#55606d",
      selection_bg = "#55606d",
      selection_fg = "#262626",
      ansi = {"#262626", "#5B738F", "#76efc7", "#df7c7c", "#3bba90", "#91c1f8", "#4d5653", "#55606d"},
      brights = {"#454545", "#4E8A76", "#6194CD", "#ef9999", "#404040", "#3D4349", "#56fbc4", "#3D4349"},
      tab_bar = {
        background = "#404040",
        active_tab = {
          bg_color = "#4E8A76",
          fg_color = "#262626",
        },
        inactive_tab = {
          bg_color = "#6e88a6",
          fg_color = "#262626",
        },
      },
  },
}
github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.