iced-rs/iced

Dark text on light background is hard to read on non-HiDPI displays

Open

#2,254 建立於 2024年2月15日

在 GitHub 查看
 (9 留言) (14 反應) (0 負責人)Rust (30,491 star) (1,572 fork)batch import
bughelp wantedquestionrenderingtextwgpu

描述

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

I've been checking out iced because 0.12 came out today. But immediately the text stood out as very wrongly rendered. Initially I thought the hinting just isn't very good, but comparing Paint (on the top) to Iced (at the bottom), the problem is much rather an issue with the "apparent font weight": image

This immediately stood out to me as an issue with sRGB linear vs. gamma corrected, so I pulled out RenderDoc where at first glance the textures seem to use the correct color space. Extracting the glyph cache by itself, we actually get a proper rendering of the glyphs, confirming that up until this point everything is done correctly: image

This strongly implied that the shader is causing the problems, and it probably needs to do a sRGB linear to gamma corrected conversion, and lo and behold, the text is now properly rendered: image

My quick fix amounted to the following in glyphon:

fn linear_to_srgb(x: f32) -> f32 {
    if x <= 0.00031308 {
        return 12.92 * x;
    } else {
        return 1.055 * pow(x,(1.0 / 2.4) ) - 0.055;
    }
}
return vec4<f32>(in_frag.color.rgb, in_frag.color.a * linear_to_srgb(textureSampleLevel(mask_atlas_texture, atlas_sampler, in_frag.uv, 0.0).x));

Almost certainly too hacky (although the same hack already exists), but it should give a good starting point for investigation where the color space mess up happens and what the correct fix may be.

I believe the main problem here is that what iced and glyphon are doing is technically the correct color space handling, but no other application interprets the alpha channel of glyphs this way, so while technically being more correct, it ends up looking very washed out and inconsistent with other applications.

The tiny-skia backend does NOT have this problem, solidifying that it's at least a bug in one of the two backends.

image

Interestingly both Paint and tiny-skia are still clearer, but that may just be the hacky sRGB conversion function.

What is the expected behavior?

See above

Version

crates.io release

Operating System

Windows

Do you have any log output?

No response

貢獻者指南