-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Text rasterization is based on world units instead of pixels #1890
Comments
I hit this issue in Bevy 0.10 during Bevy Game Jam 3. We made a 2D pixel art game with scaled up pixels via camera zoom, and then I tried to add nametags to the player / enemies. I ended up working around this issue by rendering the nametag text with an absurd font size (EDIT: This was actually unnecessary), then scaling the text entity down. This was good enough for the jam, but it was a rough hack, the text still had artifacts due to the scaling (EDIT: Wrong), and it was an extra performance cost (EDIT: Only because I incorrectly used a larger font size). In retrospect we should have scaled our sprites up instead of zooming the camera in, but it's unfortunate that camera zoom is effectively incompatible with world-space text. |
This is effecting me on a current project in 0.11, I'd be happy to work on trying to fix it if someone with a bit more experience in the engine could point me in the right direction |
Can you elaborate on how this didn't work out for you / what artifacts you were experiencing?
(side note: I updated the repro for bevy 0.11 here: https://gist.github.com/rparrett/c9a485a313235d678dffa30f1bcba974 |
The above is totally wrong. The correct workaround is to simply have a system scale the text entity's transform by the inverse of the camera zoom (4x zoom => scale by 0.25). |
Font textures can be configured to use nearest sampling, although the easiest way to accomplish that is to set the default sampler globally. But that's probably the right call if you need it for text. |
For some reason I remember there being more to the story at the time, but going back and looking at the actual font size rendered + the actual pixels on screen (visually comparing to the same font rendered in my browser on Google Fonts), everything seems fine. The only difference is Google Fonts does subpixel anti-aliasing whereas bevy just does normal anti-aliasing, which makes a big difference for smaller text, but that's not related to this issue. |
TriageThis issue appears to persist with Bevy 0.12. Reproduction code: https://github.com/TimJentzsch/bevy_triage/tree/main/issues/issue_1890 |
Notably, this issue only happens with |
Workaround: Increase the let mut bundle = Text2dBundle {
transform: transform.with_scale(Vec3::splat(0.1)),
..Default::default()
};
bundle.text.sections.push(TextSection {
value: format!("test"),
style: TextStyle {
//...
font_size: font_size * 10,
..Default::default(),
},
}); |
You only need to scale the text's transform by the inverse of the camera zoom. No need to touch the font size. |
That would depend on if you want the text to scale up when zoomed in. If you want that behaviour then changing the font size is necessary. |
Bevy version
Operating system & version
Linux/Wayland
What you did
Modify the camera in the
text2d
example to use a scale of0.1
:What you expected to happen
The text should rasterize properly with no visible artifacts.
What actually happened
The text is rasterized to 10x10 pixel squares (1/scale).
Additional information
This can also be seen with
ScalingMode::FixedHorizontal
when the scale does not match the window's width:(The same applies to
ScalingMode::FixedVertical
, of course.)The text was updated successfully, but these errors were encountered: