Skip to content

Commit

Permalink
OrthographicProjection: place origin at integer pixel with WindowSize…
Browse files Browse the repository at this point in the history
… scaling mode

One way to avoid texture atlas bleeding is to ensure that every vertex is
placed at an integer pixel coordinate. This is a particularly appealing
solution for regular structures like tile maps.

Doing so is currently harder than necessary when the WindowSize scaling
mode and Center origin are used: For odd window width or height, the
origin of the coordinate system is placed in the middle of a pixel at
some .5 offset.

Avoid this issue by rounding the half width and height values.
  • Loading branch information
neocturne committed Mar 2, 2022
1 parent b6a647c commit d5d901c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_render/src/camera/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ impl CameraProjection for OrthographicProjection {
fn update(&mut self, width: f32, height: f32) {
match (&self.scaling_mode, &self.window_origin) {
(ScalingMode::WindowSize, WindowOrigin::Center) => {
let half_width = width / 2.0;
let half_height = height / 2.0;
self.left = -half_width;
let half_width = (width / 2.0).round();
let half_height = (height / 2.0).round();
self.left = half_width - width;
self.right = half_width;
self.top = half_height;
self.bottom = -half_height;
self.bottom = half_height - height;
}
(ScalingMode::WindowSize, WindowOrigin::BottomLeft) => {
self.left = 0.0;
Expand Down

0 comments on commit d5d901c

Please sign in to comment.