Camera with with multiple layers of RenderLayers causes flickering when not on main window
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
See [this video](https://youtu.be/jMjdNtuUAkA) for a quick example of the issue.
## Bevy version
v0.15.3
## Relevant system information
Rust version: 1.86.0
Arch linux.
```
bevy_render::renderer::AdapterInfo {
name: "AMD Radeon RX 6600",
vendor: 4098,
device: 29695,
device_type: DiscreteGpu,
driver: "AMD open-source driver",
driver_info: "2025.Q1.3 (LLPC)",
backend: Vulkan,
}
```
## What you did
I am rendering a couple of my entities onto a second camera that uses an image as the render target. However, sometimes some entities are flickering in and out, disappearing and reappering. This depends on the position of the camera relative to the entity.
The second camera uses RenderLayer(2), while the main camera uses RenderLayer(0). This issue goes away if I include layer 0, the entities never flicker. This isn't an issue with z ordering ()
I also inspected the `VisibleEntities` to see if they are maybe fluctuating but that wasn't the case. The number of entities in the Vec was consistent.
You can see this in the below video. The top right image is the second camera. Only the player and the enemies are on the second RenderLayer, so that works correctly, however you can see the fallen enemy flickering based on the camera position.
## Additional information
See [this video with flickering](https://youtu.be/gxiBod0ocnc) for the render layer issue, compare directly with [this video without flicker](https://youtu.be/7kHy326Kt6I) , where the same enemy is not flickering anymore. In the first one the RenderLayer::layer(2) is just 2, in the second video it's 0 and 2.
Code of spawning both cameras
Second camera.
```rust
let projection = OrthographicProjection {
scaling_mode: ScalingMode::FixedVertical {
viewport_height: GAME_CAMERA_PROJECTION_SCALE,
},
far: PROJECTION_FAR,
near: -PROJECTION_FAR,
..OrthographicProjection::default_2d()
};
commands.spawn((
projection,
ShojiCamera,
Camera2d::default(),
Camera {
target: image_handle.clone().into(),
clear_color: CLEAR_COLOR.into(),
order: -1,
..default()
},
RenderLayers::layer(2),
));
```
Main camera.
```rust
let projection = OrthographicProjection {
scaling_mode: ScalingMode::FixedVertical {
viewport_height: GAME_CAMERA_PROJECTION_SCALE,
},
far: PROJECTION_FAR,
near: -PROJECTION_FAR,
..OrthographicProjection::default_2d()
};
commands.spawn((
projection,
MainCamera,
Camera2d,
RenderLayers::layer(0),
IsDefaultUiCamera,
SpatialAudioReceiver,
Msaa::Off,
PostProcessSettings::default(),
));
```
Contributor guide
Research direction
Start by reproducing the behavior described in the linked flickering videos with the two camera setups and RenderLayers::layer(2) versus layers 0 and 2. Inspect the render-layer and camera rendering paths related to visibility and the image render target. Done means entities on the second camera no longer flicker as that camera moves, while the separate layer behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100