bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.71k stars 3.61k forks source link

Render-to-texture does not work with UI images #7873

Closed alice-i-cecile closed 9 months ago

alice-i-cecile commented 1 year ago

Bevy version

0.9.1 and https://github.com/bevyengine/bevy/commit/9153bd0e786df602e8f86f3c564c131f9d738242

[Optional] Relevant system information

2023-03-02T19:57:12.148916Z INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 970", vendor: 4318, device: 5058, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "525.85.05", backend: Vulkan }

2023-03-02T19:57:12.798355Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 22.04 Pop!_OS", kernel: "6.1.11-76060111-generic", cpu: "AMD Ryzen 5 5600G with Radeon Graphics", core_count: "6", memory: "15.4 GiB" }

What you did

Attempt to render to texture, then use the returned handle in an ImageNode.

This can be reproduced by adding the following code to the render_to_texture example (and fixing the minor compilation issues).

    // The ImageBundle UI node that demonstrates the problem
    commands.spawn(ImageBundle {
        image: UiImage {
            texture: image_handle,
            ..default()
        },
        ..default()
    });

A full reproduction for Bevy 0.9.1 can be found here.

What went wrong

Some very interesting symptoms here!

  1. The existing render-to-texture on the rotating cube stops working.
  2. Nothing shows up in the ImageNode.
  3. On one of my PopOS boxes, but not the other, this worked about 25% of the time, and behaved exactly as expected. The rest of the time, nothing rendered.
ramirezmike commented 1 year ago

I started implementing a screen with render-to-texture on UI Images and it wasn't working right and I found this issue. At some point, I realized what I was doing wrong and got it working for my use case so I tried to see if I could reproduce the issues you wrote here on 0.11, but it seems to be working for me.

When I first tried it, all I saw was white I think because of the size of the window I had it running in, so I setup the image to take up less space so I could see it:

    commands.spawn(ImageBundle {
        style: Style {
            width: Val::Percent(25.),
            height: Val::Percent(50.),
            ..default()
        },
        image: UiImage {
            texture: image_handle,
            ..default()
        },
        ..default()
    });

https://github.com/bevyengine/bevy/assets/1421719/8a355f38-4092-4a54-9ca4-ff7d5c6c0799

At this point I needed to add the UiCameraConfig to make the camera ignore the image node

   UiCameraConfig {
       show_ui: false,
    }

https://github.com/bevyengine/bevy/assets/1421719/a7c44352-e070-4cb9-89f3-644f5f27bc4a

And this has been working consistently for me. I'm curious if this issue has potentially been resolved or if I'm just incredibly lucky 🤔

alice-i-cecile commented 9 months ago

I'm going to close this as fixed for now. If people encounter further errors, please re-open this!