Skip to content

Visual tearing with ImageFilterMode::Nearest #16773

@musjj

Description

@musjj

Bevy version

0.15.0

What you did

When ImageFilterMode::Nearest is set as the default sampler, tearing occurs to text, sprites, etc. when the window resolution is an odd number (101x303, etc.). You can test by spawning a sprite and then resizing the window:

use bevy::prelude::*;

fn main() -> AppExit {
    App::new()
        .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
        .add_systems(Startup, setup)
        .run()
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2d);

    commands.spawn(Sprite::from_image(asset_server.load("grid_480x270.png")));
}

The notable exception is that it doesn't happen to sprites with dimensions that is the power of two (512x256, etc.).

You can test a more elaborate, interactive reproduction here: https://github.com/musjj/nearest_filter_bug. Slowly and gradually resize the window and you should be able to see the artifacts popping in and out.

What went wrong

Visual tearing occurs.

Additional information

An example of no tearing:

Image

An example of tearing:

Image

A closeup of the tearing (the lines are supposed to be perfectly straight):

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions