Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifact in sprite rendering #16918

Open
sofia-m-a opened this issue Dec 20, 2024 · 5 comments
Open

Artifact in sprite rendering #16918

sofia-m-a opened this issue Dec 20, 2024 · 5 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong

Comments

@sofia-m-a
Copy link

Bevy version

0.15.0

[Optional] Relevant system information

`AdapterInfo { name: "AMD Radeon Graphics (RADV RENOIR)", vendor: 4098, device: 5686, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 24.2.6", backend: Vulkan }`

What you did

Example code, using this CC0 tilemap texture Image

use bevy::prelude::*;
use std::collections::HashMap;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
        .add_systems(Startup, startup)
        .run();
}

fn startup(
    mut commands: Commands,
    assets: ResMut<AssetServer>,
    mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
) {
    let texture_handle = assets.load_with_settings(
        "kenney_tiny-dungeon/Tilemap/tilemap_packed.png",
        |settings: &mut bevy::image::ImageLoaderSettings| {
            // Use `nearest` image sampling to preserve the pixel art style.
            settings.sampler = bevy::image::ImageSampler::nearest();
        },
    );
    let texture_atlas_layout =
        TextureAtlasLayout::from_grid(UVec2::new(16, 16), 12, 11, None, None);
    let texture_atlas_layout = texture_atlas_layouts.add(texture_atlas_layout);
    commands.spawn(Camera2d);

    let mut out = HashMap::new();

    { // generation, not super important, it just is easier to see the bug with some variety
        for x in -2..=2 {
            for y in -2..=2 {
                out.insert(IVec2::new(x, y), 48);
            }
        }

        for y in -2..=2 {
            out.insert(IVec2::new(-3, y), 13);
            out.insert(IVec2::new(3, y), 15);
        }

        for x in -2..=2 {
            out.insert(IVec2::new(x, -3), 26);
            out.insert(IVec2::new(x, 3), 2);
        }

        out.insert(IVec2::new(-3, -3), 25);
        out.insert(IVec2::new(3, -3), 27);
        out.insert(IVec2::new(-3, 3), 1);
        out.insert(IVec2::new(3, 3), 3);
    }

    for (place, kind) in out {
        let mut s = Sprite::from_atlas_image(texture_handle.clone(), TextureAtlas {
            layout: texture_atlas_layout.clone(),
            index: kind,
        });
        s.custom_size = Some(Vec2::new(1.0, 1.0));

        let scale = 6.0;
        commands.spawn((
            s,
            Transform::from_scale(Vec2::splat(16.0 * scale).extend(1.0))
                * Transform::from_translation(place.as_vec2().extend(0.0)),
        ));
    }
}

What went wrong

There is misalignment Image
It seems the bottom-left triangle of each quad has incorrect texturing, seemingly the wrong UVs, leading to it not matching the neighbouring triangle, and also bleeding over the edge of the atlas by 1 pixel

Additional information

Maybe its something to do with rounding?!

@sofia-m-a sofia-m-a added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Dec 20, 2024
@sofia-m-a sofia-m-a changed the title Arifact in sprite rendering Artifact in sprite rendering Dec 20, 2024
@sofia-m-a
Copy link
Author

Additional note: those tiles that don't have a visible 1-pixel line underneath them happen to lie next to the tile below them on the tilemap
So they do have the same problem, it just happens to work out due to how the tilemap is arranged

@shanecelis
Copy link
Contributor

Unfortunately I cannot replicate this on my machine with either v0.15.0 or the 'main' branch. I will try on my x86 machine later tonight.

AdapterInfo { name: "Apple M2", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

@alexniver
Copy link

bleeding over the edge of the atlas by 1 pixel , I got the same issue in bevy 0.14

@Elabajaba
Copy link
Contributor

The fix/workaround for this is to disable MSAA on your camera by inserting the Msaa::Off component on it.

@sofia-m-a
Copy link
Author

@Elabajaba thanks, disabling MSAA does fix the borders on the bottom of the tiles. The triangular artifacts still remain

Image

@BenjaminBrienen BenjaminBrienen added A-Rendering Drawing game state to the screen S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

No branches or pull requests

5 participants