Improve API for scaling orthographic cameras#15969
Merged
alice-i-cecile merged 8 commits intobevyengine:mainfrom Oct 17, 2024
Merged
Improve API for scaling orthographic cameras#15969alice-i-cecile merged 8 commits intobevyengine:mainfrom
alice-i-cecile merged 8 commits intobevyengine:mainfrom
Conversation
BenjaminBrienen
approved these changes
Oct 17, 2024
MiniaczQ
reviewed
Oct 17, 2024
MiniaczQ
reviewed
Oct 17, 2024
Co-authored-by: MiniaczQ <[email protected]>
MiniaczQ
approved these changes
Oct 17, 2024
Contributor
MiniaczQ
left a comment
There was a problem hiding this comment.
Just docs nits,
on the second though, maybe drop all the scale mentions on enum variant docs?
it's already explained in enum docs
Member
Author
|
@MiniaczQ I've improved the docs for ScalingMode to further elaborate on "what does a scale of 1" mean. This is an important point, so I've tried to be relatively exhaustive about all of the different factors that can affect things. |
Contributor
Looks good :) |
tim-blackbird
approved these changes
Oct 17, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Dec 15, 2024
# Objective Fixes #16773 ## Solution #15969 introduces a regression that causes image tearing when `ImageFilterMode::Nearest` is used as the sampler. Rounding the origin fixes the issue. Credits to @sophrosyne97 for bisecting and finding the commit that broke it. ## Testing You can test it with this repository: https://github.com/musjj/nearest_filter_bug ```bash git clone https://github.com/musjj/nearest_filter_bug cd nearest_filter_bug echo '[patch.crates-io]\nbevy = { git = "https://github.com/musjj/bevy.git", branch = "rounding-bug" }' >>Cargo.toml sed -i -e 's/0.15.0/0.15.0-dev/' Cargo.toml cargo update && cargo run ``` Gradually resize the window to various sizes, while paying attention to the sprite and font. No tearing should occur on any window resolution, even on odd numbers. Tested on Linux with Gnome. Tests on other platforms would be appreciated. --- ## Showcase Before:  After: 
ecoskey
pushed a commit
to ecoskey/bevy
that referenced
this pull request
Jan 6, 2025
# Objective Fixes bevyengine#16773 ## Solution bevyengine#15969 introduces a regression that causes image tearing when `ImageFilterMode::Nearest` is used as the sampler. Rounding the origin fixes the issue. Credits to @sophrosyne97 for bisecting and finding the commit that broke it. ## Testing You can test it with this repository: https://github.com/musjj/nearest_filter_bug ```bash git clone https://github.com/musjj/nearest_filter_bug cd nearest_filter_bug echo '[patch.crates-io]\nbevy = { git = "https://github.com/musjj/bevy.git", branch = "rounding-bug" }' >>Cargo.toml sed -i -e 's/0.15.0/0.15.0-dev/' Cargo.toml cargo update && cargo run ``` Gradually resize the window to various sizes, while paying attention to the sprite and font. No tearing should occur on any window resolution, even on odd numbers. Tested on Linux with Gnome. Tests on other platforms would be appreciated. --- ## Showcase Before:  After: 
mrchantey
pushed a commit
to mrchantey/bevy
that referenced
this pull request
Feb 4, 2025
# Objective Fixes bevyengine#16773 ## Solution bevyengine#15969 introduces a regression that causes image tearing when `ImageFilterMode::Nearest` is used as the sampler. Rounding the origin fixes the issue. Credits to @sophrosyne97 for bisecting and finding the commit that broke it. ## Testing You can test it with this repository: https://github.com/musjj/nearest_filter_bug ```bash git clone https://github.com/musjj/nearest_filter_bug cd nearest_filter_bug echo '[patch.crates-io]\nbevy = { git = "https://github.com/musjj/bevy.git", branch = "rounding-bug" }' >>Cargo.toml sed -i -e 's/0.15.0/0.15.0-dev/' Cargo.toml cargo update && cargo run ``` Gradually resize the window to various sizes, while paying attention to the sprite and font. No tearing should occur on any window resolution, even on odd numbers. Tested on Linux with Gnome. Tests on other platforms would be appreciated. --- ## Showcase Before:  After: 
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Fixes #15791.
As raised in #11022, scaling orthographic cameras is confusing! In Bevy 0.14, there were multiple completely redundant ways to do this, and no clear guidance on which to use.
As a result, #15075 removed the
scalefield fromOrthographicProjectioncompletely, solving the redundancy issue.However, this resulted in an unintuitive API and a painful migration, as discussed in #15791. Users simply want to change a single parameter to zoom, rather than deal with the irrelevant details of how the camera is being scaled.
Solution
This PR reverts #15075, and takes an alternate, more nuanced approach to the redundancy problem.
ScalingMode::WindowSizewas by far the biggest offender. This was the default variant, and stored a float that was fully redundant to settingscale.All of the other variants contained meaningful semantic information and had an intuitive scale. I could have made these unitless, storing an aspect ratio, but this would have been a worse API and resulted in a pointlessly painful migration.
In the course of this work I've also:
scaleto zoom camerasScalingModefor more clarity about the parameter meaningsprojection_zoomexampleMulandDivimpls forScalingMode, especially since these no longer have the intended effect onScalingMode::WindowSize.Testing
I've tested these changes as part of my work in the
projection_zoomexample, and things seem to work fine.Migration Guide
ScalingModehas been refactored for clarity, especially on how to zoom orthographic cameras and their projections:ScalingMode::WindowSizeno longer stores a float, and acts as if its value was 1. Divide your camera's scale by any previous value to achieve identical results.ScalingMode::FixedVerticalandFixedHorizontalnow use named fields.