Skip to content

Custom Material with AlphaMode::Blend cause flicker #8612

Closed as not planned
Closed as not planned
@stringslength

Description

@stringslength

Bevy version

bevy = "0.10.1"

[Optional] Relevant system information

the Rust version you're using (you can get this by running cargo --version)

cargo 1.68.2 (6feb7c9cf 2023-03-26)

the operating system or browser used, including its version

Windows 10, Desktop App

If your bug is rendering-related, copy the adapter info that appears when you run Bevy.

AdapterInfo { name: "NVIDIA GeForce GTX 1070", vendor: 4318, device: 7041, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "516.94", backend: Vulkan }

What you did

I build example https://bevyengine.org/examples/shader/shader-material/.
Then I add the green-colored outer-cube to example, like this (ADD START - ADD END) :

/// set up a simple 3D scene
fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<CustomMaterial>>,
    asset_server: Res<AssetServer>,
) {
    // cube
    commands.spawn(MaterialMeshBundle {
        mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
        transform: Transform::from_xyz(0.0, 0.5, 0.0),
        material: materials.add(CustomMaterial {
            color: Color::BLUE,
            color_texture: Some(asset_server.load("branding/icon.png")),
            alpha_mode: AlphaMode::Blend,
        }),
        ..default()
    });

    // ADD START
    commands.spawn(MaterialMeshBundle {
        mesh: meshes.add(Mesh::from(shape::Cube { size: 3.0 })),
        transform: Transform::from_xyz(0.0, 0.5, 0.0),
        material: materials.add(CustomMaterial {
            color: Color::GREEN,
            color_texture: Some(asset_server.load("branding/icon.png")),
            alpha_mode: AlphaMode::Blend,
        }),
        ..default()
    });
    // ADD END

    // camera
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}

What went wrong

My expect : show green-cube because blue-cube is hided from it.
Result : blue-cube is displayed flickering. I attach a movie.

BevyApp_CustomMaterial_Blend_Flicker.mp4

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorS-DuplicateThis issue or PR already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions