bevyengine / bevyengine/bevy

Second camera ToneMapping and/or RenderLayers impacts first camera

Open
#17,530 3 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug D-Shaders D-Straightforward S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
4d 8m
Merged PRs (30d)
147

Description

## Bevy version
```
[[package]]
name = "bevy"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2a21c9f3306676077a88700bb8f354be779cf9caba9c21e94da9e696751af4"
dependencies = [
"bevy_dylib",
"bevy_internal",
]

```

## \[Optional\] Relevant system information

If you cannot get Bevy to build or run on your machine, please include:

* Rust version:
* ` cargo 1.83.0 (5ffbef321 2024-10-29)`
* and ` cargo 1.85.0-nightly (769f622e1 2024-12-14)`

* OS: Debian Trixie,
```bash
uname -a
Linux nevermore 6.11.9-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.11.9-1 (2024-11-17) x86_64 GNU/Linux
```

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

```
2025-01-24T23:44:49.673613Z INFO bevy_render::renderer: AdapterInfo { name: "Intel(R) Graphics (MTL)", vendor: 32902, device: 32069, device_type: IntegratedGpu, driver: "Intel open-source Mesa driver", driver_info: "Mesa 24.2.8-1", backend: Vulkan }
```

## What you did

1. Paste the code from [the 2d Bloom example](https://bevyengine.org/examples/2d-rendering/bloom-2d/) and run it. It works.
2. Add a second camera by copy-pasting the first camera.
3. Add two separate Marker components to make sure the system expecting a single camera will not make problems. Use the marker there for the query.
4. Set the first Camera to ` order: 1` and the second Camera to ` order: 2` , so the second camera should be drawn over the first camera. Add ` clear_color: ClearColorConfig::None` to the second Camera.
5. At this point, everything is still working.
6. Specify for the second camera: `RenderLayers::from_layers(&[1,])` to make the overlay camera render different entities. There are none of those, of course, but that does not matter.
7. Run it and observe that the image looks muted.

Here is what I changed:
```diff
commit 6bbbc56c72a7cbab1b411c4cef7aa814ba1f3789
Author: LucidBrot
Date: Sat Jan 25 00:44:10 2025 +0100

This is muted

diff --git a/src/main.rs b/src/main.rs
index 13f687f..d890632 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,12 @@ use bevy::{
},
prelude::*,
};
+use bevy::render::view::visibility::RenderLayers;
+
+#[derive(Component)]
+struct CameraMarker1{}
+#[derive(Component)]
+struct CameraMarker2{}

fn main() {
App::new()
@@ -25,12 +31,29 @@ fn setup(
) {
commands.spawn((
Camera2d,
+ CameraMarker1{},
+ Camera {
+ hdr: true, // 1. HDR is required for bloom
+ order: 1,
+ ..default()
+ },
+ Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended
+ Bloom::default(), // 3. Enable bloom for the camera
+ RenderLayers::from_layers(&[0,]),
+ ));
+
+ commands.spawn((
+ Camera2d,
+ CameraMarker2{},
Camera {
hdr: true, // 1. HDR is required for bloom
+ order: 2,
+ clear_color: ClearColorConfig::None,
..default()
},
Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended
Bloom::default(), // 3. Enable bloom for the camera
+ RenderLayers::from_layers(&[1,]),
));

// Sprite
@@ -72,7 +95,7 @@ fn setup(
// ------------------------------------------------------------------------------------------------

fn update_bloom_settings(
- camera: Single<(Entity, Option<&mut Bloom>), With>,
+ camera: Single<(Entity, Option<&mut Bloom>), With>,
mut text: Single<&mut Text>,
mut commands: Commands,
keycode: Res>,

```

Interestingly, the issue is dependent on both
* having the Tonemapping present in the second camera
* using RenderLayers 1, instead of the default 0

## What went wrong

Expected:

![Image](https://github.com/user-attachments/assets/04696c3c-9c69-4e8d-80c4-ba2d5df67d3f)

Actual:

![Image](https://github.com/user-attachments/assets/f543e033-c468-4983-8094-86165899cb0d)

I am not certain whether this might be intended behavior somehow, but it is certainly not what I expected. My use-case will be to show a Menu overlaid over the Game Entities. Both cameras are supposed to apply the same effects. Muting the background could be nice, but I'd want to explicitly do that, not have it as a side effect of having an unused camera.

## Additional information

Issues I've found that may or may not have anything to do with this at all:
* https://github.com/bevyengine/bevy/pull/14287
* https://github.com/bevyengine/bevy/issues/14389
> * what were you expecting?
> Tonemapping to look the same on each camera
> * what actually happened?
> The tonemapping looks more intense on other cameras, appears like it's multiplying the effect due to it not being constrained to the camera's viewport.
* https://github.com/bevyengine/bevy/issues/14197
> I believe this is caused by the effect writing outside the camera's viewport causing a multiplying effect with the camera's layered on top of each other.
* https://github.com/bevyengine/bevy/issues/12121 (Also is using Bloom, but otherwise seems different to me)

[bloom1.zip](https://github.com/user-attachments/files/18544138/bloom1.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.