Z-fighting is not stable and causes flickering
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.11.3
## Relevant system information
```ignore
AdapterInfo { name: "Apple M1 Pro", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
```
## What you did
Add three planes of different colors at exactly the same location.
```rust
use bevy::app::App;
use bevy::app::Startup;
use bevy::prelude::shape::Plane;
use bevy::prelude::*;
fn setup(
mut commands: Commands,
mut materials: ResMut>,
mut meshes: ResMut>,
) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3.0, 3.0, 3.0).looking_at(Vec3::new(0., 0., 0.), Vec3::Y),
..default()
});
let red = materials.add(Color::RED.into());
let green = materials.add(Color::GREEN.into());
let blue = materials.add(Color::BLUE.into());
for color in [red, green, blue] {
// Intentionally spawn 3 planes in the same place.
commands.spawn(PbrBundle {
mesh: meshes.add(Plane::from_size(2.0).into()),
material: color,
..default()
});
}
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
```
Compiled with `-O1`.
## What went wrong
Rectangle is constantly changing color.
I suspect that's because order of rendering is not deterministic.
If it not always easy to make sure that triangles never occupy the same place, so it would be convenient if Bevy rendered these meshes in some deterministic order, regardless of what's that order is. At least if entities did not change.
Attaching screen recording.
https://github.com/bevyengine/bevy/assets/28969/49df65ac-7c67-46c2-a01c-dc6f67d8f1d9
Contributor guide
Assessment
This issue has not been assessed yet.