-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to control font smoothing #15368
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great; this is useful and I'm happy with this. Really quite simple! I would prefer if we can document how this relates to #15170 as well; maybe add cross-links to both the settings added here and those added there?
I think both are worth including, since exposing different levels of granularity can be important.
I'll add some cross-linking between the two. 👍 Looking at the UI antialias setting, it seems to be camera driven. Would it be desirable to also have the same for this? We won't be able to do that currently, unless we refactor the font atlases to also be per-camera. (Which might be necessary down the line for supporting non-global scaling factors per-view) |
IMO not at the current time: I'd prefer to have a simple fix in, and work towards a broader, more controversial refactor later. |
When we're writing the release notes we can and should cover how all of these options interact with each other :) Not fully documented (book chapter on pixel art games please), but it will at least be googleable. |
Do we already have a Camera -> Image target -> Sprite -> Camera -> Window pixel perfect scaling example? It could probably be combined with that. |
https://github.com/bevyengine/bevy/blob/main/examples/2d/pixel_grid_snap.rs is the closest. I'd really like to flesh it out though, yeah. |
Can't you do this by rendering to a texture and then scaling the texture? That's part of what #15256 would make easy, although I could be missing something about the rendering precision. EDIT: Actually, #15256 would probably scale the UI normally (and scale UI element positions relative to some fixed point) and then fit the texture size to line up with the adjusted contents. So no 'stretching' of the texture. |
crates/bevy_text/src/pipeline.rs
Outdated
@@ -209,6 +210,18 @@ impl TextPipeline { | |||
.map(move |layout_glyph| (layout_glyph, run.line_y)) | |||
}) | |||
.try_for_each(|(layout_glyph, line_y)| { | |||
let mut layout_glyph = layout_glyph.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you expect the compiler to elide this clone when not needed? Otherwise I would move the new variable outside the loop and branch on font_smoothing
to either update the outer variable and get a reference, or use the layout_glyph
reference from the iterator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't able to get the temp variable outside the loop, because it couldn't be left initialized across the closure boundary, and the LayoutGlyph
type doesn't have a Default
implementation, so instead I create it inside the closure and conditionally shadow the layout_glyph
with a reference to it (or with its original reference), which should have the same effect of preventing the extra clone when font smoothing is on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, well documented and FontAtlasKey is a much better name!
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1694 if you'd like to help out. |
Objective
Solution
FontSmoothing
enum, with two possible variants (FontSmoothing::None
andFontSmoothing::AntiAliased
):-webkit-font-smoothing
, in line with our practice of adopting CSS-like properties/names for UI;font-smooth
property that's also supported by browsers, but didn't since it's also non-standard, has an uglier name, and doesn't allow controlling the type of antialias applied.FontSmoothing::SubpixelAntiAliased
in the future, without a breaking change;FontSmoothing
information to where we rasterize the glyphs and store them in the atlas;Text
for setting the font smoothing;FontSmoothing
property to thetext2d
example.Testing
text2d
example, and also in my game.text2d
example and also by using it directly on your projects.Showcase
Migration Guide
Text
now contains afont_smoothing: FontSmoothing
property, make sure to include it or add..default()
when using the struct directly;FontSizeKey
has been renamed toFontAtlasKey
, and now also contains theFontSmoothing
setting;font_smoothing: FontSmoothing
argument:FontAtlas::new()
FontAtlasSet::add_glyph_to_atlas()
FontAtlasSet::get_glyph_atlas_info()
FontAtlasSet::get_outlined_glyph_texture()