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

UI components not respecting RenderLayers #6069

Open
paulkre opened this issue Sep 22, 2022 · 5 comments
Open

UI components not respecting RenderLayers #6069

paulkre opened this issue Sep 22, 2022 · 5 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@paulkre
Copy link

paulkre commented Sep 22, 2022

The visibility of UI entities like text is not affected by the RenderLayers component. This is a problem when trying to prerender a scene with RenderTarget::Image to use it as a mesh texture (the game UI will also be visible on the texture).

Is there a way to make UI components respect RenderLayers?

@paulkre paulkre added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Sep 22, 2022
@Nilirad Nilirad added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Sep 23, 2022
@paulkre
Copy link
Author

paulkre commented Sep 26, 2022

I modified the render_to_texture example to demonstrate the bug:
https://github.com/paulkre/bevy/blob/ui-renderlayers-demo/examples/3d/render_to_texture.rs

bevy-ui-renderlayers-demo.mp4

@paulkre
Copy link
Author

paulkre commented Sep 26, 2022

I just found an acceptable workaround. You can add the UiCameraConfig { show_ui: false } component to your RenderTarget::Image-camera which hides all UI elements for that camera. This helps most of the time but sometimes you might want to render different UI elements in both cameras. In these situations it would be great if RenderLayers worked for UI.

@jdm
Copy link
Contributor

jdm commented Apr 8, 2023

Updated example change that demonstrates the issue:

diff --git a/examples/3d/render_to_texture.rs b/examples/3d/render_to_texture.rs
index 81c687e5a..e4473bcae 100644
--- a/examples/3d/render_to_texture.rs
+++ b/examples/3d/render_to_texture.rs
@@ -35,6 +35,7 @@ fn setup(
     mut meshes: ResMut<Assets<Mesh>>,
     mut materials: ResMut<Assets<StandardMaterial>>,
     mut images: ResMut<Assets<Image>>,
+    asset_server: Res<AssetServer>,
 ) {
     let size = Extent3d {
         width: 512,
@@ -141,6 +142,17 @@ fn setup(
         transform: Transform::from_xyz(0.0, 0.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y),
         ..default()
     });
+
+    commands.spawn((
+        TextBundle::from_section(
+            "hello\nbevy!",
+            TextStyle {
+                font: asset_server.load("fonts/FiraSans-Bold.ttf"),
+                font_size: 200.0,
+                color: Color::RED,
+            },
+        ),
+    ));
 }

 /// Rotates the inner cube (first pass)

@musjj
Copy link
Contributor

musjj commented Nov 27, 2023

Hmmm, when I added UiCameraConfig { show_ui: false } to the camera looking at the rendered image, the UI simply does not get rendered.

Adding it to the camera rendering to the image using RenderTarget simply does nothing. Did anything change in 0.12?

@Aunmag
Copy link

Aunmag commented Feb 25, 2024

Same problem. I use two cameras: one for classic game rendering, and second for rendering onto tile map (decals like blood texures, etc..). But when I spawn a TextBundle it renders to screen (which is ok) and to all my tiles (which is bad).

Here's how I spawn text:

world.spawn(
    TextBundle::from_sections([
        TextSection::new("FPS: ", style.clone()),
        TextSection::from_style(style.clone()),
        TextSection::new("\nEntities: ", style.clone()),
        TextSection::from_style(style.clone()),
        TextSection::new("\nAudio sources: ", style.clone()),
        TextSection::from_style(style.clone()),
        TextSection::new(
            "\n\
            \nSpawn weapon: [G]\
            \nSpawn human : [H] group: [+SHIFT]\
            \nSpawn zombie: [J] group: [+SHIFT]\
            ",
            style,
        ),
    ])
);

Here's how I spawn second camera (for tile map blending):

commands
    .spawn(Camera2dBundle {
        camera: Camera {
            target: RenderTarget::Image(target),
            output_mode: CameraOutputMode::Write {
                blend_state: Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING),
                color_attachment_load_op: LoadOp::Load,
            },
            ..Default::default()
        },
        camera_2d: Camera2d {
            clear_color: ClearColorConfig::None,
        },
        transform,
        ..Default::default()
    })
    .insert(RenderLayers::layer(1)); // NOTE: used different render layer

Screenshot 2024-02-25 125411

But thanks to @paulkre workaround with UiCameraConfig helped!

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants