bevyengine / bevyengine/bevy

Sprite is blurry under macOS

Open
#5,311 3 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.7.0

## \[Optional\] Relevant system information

macOS 12.4
``2022-07-13T19:52:42.356701Z INFO bevy_render::renderer: AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: DiscreteGpu, backend: Metal }``

## What you did

Minimal sprite rendering with the following code:
```rust
use bevy::prelude::*;
use bevy::math::{const_vec3, const_vec2};
use bevy::render::render_resource::FilterMode;

#[derive(Component)]
struct Player {}

fn main() {
App::new()
.insert_resource(Msaa { samples: 1 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(set_texture_filters_to_nearest)
.run();
}

fn setup(mut commands: Commands, asset_server: Res) {
let ship = asset_server.load("ship.png");

commands
.spawn_bundle(OrthographicCameraBundle::new_2d());
commands
.spawn()
.insert_bundle(SpriteBundle {
transform: Transform {
translation: const_vec3!([0.0, 0.0, 1.0]),
..default()
},
texture: ship,
..default()
})
.insert(Player {});

}

fn set_texture_filters_to_nearest(
mut texture_events: EventReader>,
mut textures: ResMut>,
) {
for event in texture_events.iter() {
if let AssetEvent::Created { handle } = event {
if let Some(mut texture) = textures.get_mut(handle) {
println!("Change texture filter!");

texture.sampler_descriptor.min_filter = FilterMode::Nearest;
texture.sampler_descriptor.mag_filter = FilterMode::Nearest;
texture.sampler_descriptor.mipmap_filter = FilterMode::Nearest;
}
}
}
}
```

## What went wrong

The sprite is not properly interpolated and looks really odd.
![image](https://user-images.githubusercontent.com/6075580/178821580-3a0dcec5-2329-4a77-9e73-af862aa233dc.png)

## Additional information

I've attached the original sprite file:
![image](https://user-images.githubusercontent.com/6075580/178821799-8280ae87-fe31-4bbd-90ee-6ae7f34e67cf.png)

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal reproduction from the issue on macOS 12.4 with the listed Apple M1 Max/Metal setup. Inspect the setup and set_texture_filters_to_nearest entry points and compare the rendered sprite with the attached images; done means the sprite renders with the expected interpolation rather than appearing blurry or distorted.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.