OrthographicProjection: place origin at integer pixel with WindowSize scaling mode (#4085)
# Objective 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. ## Solution Avoid this issue by rounding the half width and height values.
This commit is contained in:
parent
d353fbc6ea
commit
5256561b7a
@ -104,12 +104,14 @@ impl CameraProjection for OrthographicProjection {
|
|||||||
fn update(&mut self, width: f32, height: f32) {
|
fn update(&mut self, width: f32, height: f32) {
|
||||||
match (&self.scaling_mode, &self.window_origin) {
|
match (&self.scaling_mode, &self.window_origin) {
|
||||||
(ScalingMode::WindowSize, WindowOrigin::Center) => {
|
(ScalingMode::WindowSize, WindowOrigin::Center) => {
|
||||||
let half_width = width / 2.0;
|
let half_width = (width / 2.0).round();
|
||||||
let half_height = height / 2.0;
|
let half_height = (height / 2.0).round();
|
||||||
self.left = -half_width;
|
// Assign left and bottom such that (right-left)==width and (top-bottom)==height
|
||||||
|
// still hold with with rounded half_width and half_height
|
||||||
|
self.left = half_width - width;
|
||||||
self.right = half_width;
|
self.right = half_width;
|
||||||
self.top = half_height;
|
self.top = half_height;
|
||||||
self.bottom = -half_height;
|
self.bottom = half_height - height;
|
||||||
}
|
}
|
||||||
(ScalingMode::WindowSize, WindowOrigin::BottomLeft) => {
|
(ScalingMode::WindowSize, WindowOrigin::BottomLeft) => {
|
||||||
self.left = 0.0;
|
self.left = 0.0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user