linebender / bevy_vello

An integration to render with Vello in Bevy game engine.
https://linebender.org/bevy_vello/
Apache License 2.0
98 stars 10 forks source link

`VelloScene` doesn't respect Bevy `RenderLayers` #58

Open dannymcgee opened 1 month ago

dannymcgee commented 1 month ago

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 commented 1 month ago

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 commented 1 week ago

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