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

VelloScene doesn't respect Bevy RenderLayers #58

Closed
dannymcgee opened this issue May 31, 2024 · 6 comments
Closed

VelloScene doesn't respect Bevy RenderLayers #58

dannymcgee opened this issue May 31, 2024 · 6 comments

Comments

@dannymcgee
Copy link
Contributor

dannymcgee commented May 31, 2024

I'm experimenting with Vello in a Bevy 3D project, where I have my cameras set up like this:

fn spawn_cameras(mut cmd: Commands) {
    cmd.spawn((
        Name::new("Main Camera"),
        MainCamera,
        Camera3dBundle::default(),
    ));
    cmd.spawn((
        Name::new("UI Camera"),
        UiCamera,
        Camera2dBundle {
            camera: Camera {
                clear_color: ClearColorConfig::None,
                order: 1,
                ..default()
            },
            ..default()
        },
        RenderLayers::layer(1),
    ));
}

With the intention being that anything that needs to be rendered in 2D-world-space as an overlay on top of the 3D scene should get RenderLayers::layer(1), so that it only gets rendered by the 2D camera.

However, when I tried to spawn a VelloSceneBundle with a RenderLayers::layer(1) component, it didn't render at all. After some debugging, I discovered that after changing the camera's render layers to RenderLayers::layer(0).with(1), the VelloScene started rendering as expected, indicating that bevy_vello's rendering systems are ignoring the RenderLayers component.

This is problematic for me, because allowing my 2D camera to render layer 0 causes it to render some other things that it shouldn't (e.g., 3D-world-space Gizmos with an always-in-front depth bias).

Edit: I just read over the discussion in #49, so it looks like you're already aware of the issue. 🙂 Let me know if there's anything I can do to help!

@dannymcgee
Copy link
Contributor Author

dannymcgee commented Jun 1, 2024

So it looks like Bevy UI also ignores RenderLayers. 😂 Upon further inspection, there's actually a TargetCamera component in Bevy UI that serves this purpose. That doesn't fix my issue with non-UI stuff rendering to the UI camera, but I guess I'll have to come up with another solution for that. Closing this since it matches Bevy's behavior.

EDIT: Just kidding, Bevy does respect the render layers.

@simbleau
Copy link
Member

simbleau commented Jul 5, 2024

This is definitely something I'd love to accept in a PR, or get to as time permits.

@simbleau
Copy link
Member

simbleau commented Jul 25, 2024

Up to this point, RenderLayer was something I've never worked with. Currently bevy_vello ignores RenderLayers entirely, so at first it was unclear why adding a RenderLayer::layer(1) component to a VelloSceneBundle would make it not render.

I understand this a little better now and I'm committed to pushing this across the finish line.

Here's what I understand, for others:

  • Changing the camera order will change the ordering of rendering cameras. This is a possible way to make bevy_vello render on top or on bottom of your 3d space. (camera order 1 or -1 respectively should do the trick).
    image
  • Render layers are used to tell a camera what it can and can't see. An entity on Render Layer 0 is never seen by a camera on Render Layer 1.

Re: The situation where a camera has a RenderLayer: I believe having multiple cameras with different RenderLayers would mean internally we would need a new framebuffer for every camera. Then we would need a check to ensure each camera is only rendering the items in its render layer.

@simbleau
Copy link
Member

simbleau commented Jul 25, 2024

@dannymcgee Let me know if I'm offbase from your needs.

Likewise, I'm adding @musjj and @nixon-voxell because they had a similar issue on voxell-tech/bevy_motiongfx#40. Please feel free to give thoughts.

@ChristopherBiscardi
Copy link
Contributor

I'll add the reason I was looking into this as well:

I have a Camera2d where I want to render all ui from a bevy_vello powered ui crate, and a Camera3d where I want to render "everything else" (gltf scenes, gizmos, effects, etc. game stuff).

If the Camera2d doesn't have a RenderLayers specified, then it will render a bunch of "extra" stuff, such as gizmos I'm using in the 3d camera. So ideally I would be able to order +1 on Camera2d, which places it over the 3d camera, and use RenderLayers to target all vello content to the Camera2d. I believe this still fits the "one pass" model of vello as it is only one layer.

@simbleau
Copy link
Member

Fixed via #68 - Please re-open a new issue if there are further render layer issues.

There is also a new example for render layers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants