Skip to content

Custom Material with AlphaMode::Blend cause flicker #8612

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

Closed
stringslength opened this issue May 14, 2023 · 2 comments
Closed

Custom Material with AlphaMode::Blend cause flicker #8612

stringslength opened this issue May 14, 2023 · 2 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Duplicate This issue or PR already exists

Comments

@stringslength
Copy link

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

@stringslength stringslength added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 14, 2023
@stringslength
Copy link
Author

I suppose that this issue is related to transparent rendering limitation: #2223

@nicopap
Copy link
Contributor

nicopap commented May 21, 2023

You can use AlphaMode::Mask to avoid the flickering. It also handles shadows properly. Blend is really only good when the material is generally semi-transparent, not a "all opaque/not opaque" style sprite.

I'll close this issue as duplicate, since it can't be fixed without fixing #2223 (and fixing 2223 would fix this)

@nicopap nicopap closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2023
@nicopap nicopap added S-Duplicate This issue or PR already exists A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels May 21, 2023
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-Duplicate This issue or PR already exists
Projects
None yet
Development

No branches or pull requests

2 participants