Skip to content
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

Second camera ToneMapping and/or RenderLayers impacts first camera #17530

Open
lucidBrot opened this issue Jan 25, 2025 · 0 comments
Open

Second camera ToneMapping and/or RenderLayers impacts first camera #17530

lucidBrot opened this issue Jan 25, 2025 · 0 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Shaders This code uses GPU shader languages D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@lucidBrot
Copy link

lucidBrot commented Jan 25, 2025

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,

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 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:

commit 6bbbc56c72a7cbab1b411c4cef7aa814ba1f3789
Author: LucidBrot <eric@mink.li>
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>>,
+    camera: Single<(Entity, Option<&mut Bloom>), With<CameraMarker1>>,
     mut text: Single<&mut Text>,
     mut commands: Commands,
     keycode: Res<ButtonInput<KeyCode>>,

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

Actual:

Image

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:

bloom1.zip

@lucidBrot lucidBrot added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 25, 2025
@BenjaminBrienen BenjaminBrienen added A-Rendering Drawing game state to the screen S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! D-Straightforward Simple bug fixes and API improvements, docs, test and examples D-Shaders This code uses GPU shader languages and removed S-Needs-Triage This issue needs to be labelled labels Jan 25, 2025
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 D-Shaders This code uses GPU shader languages D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

No branches or pull requests

2 participants