bevy/crates
Marius Metzger fcce3fb344 (fix) SSRPlugin: Don't reference default deferred lighting pass if it doesn't exist (#16932)
Fixes a crash when using deferred rendering but disabling the default
deferred lighting plugin.

# The Issue
The `ScreenSpaceReflectionsPlugin` references
`NodePbr::DeferredLightingPass`, which hasn't been added when
`PbrPlugin::add_default_deferred_lighting_plugin` is `false`.

This yields the following crash:
```
thread 'main' panicked at /Users/marius/Documents/dev/bevy/crates/bevy_render/src/render_graph/graph.rs:155:26:
InvalidNode(DeferredLightingPass)
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: bevy_render::render_graph::graph::RenderGraph::add_node_edges
             at /Users/marius/Documents/dev/bevy/crates/bevy_render/src/render_graph/graph.rs:155:26
   3: <bevy_app::sub_app::SubApp as bevy_render::render_graph::app::RenderGraphApp>::add_render_graph_edges
             at /Users/marius/Documents/dev/bevy/crates/bevy_render/src/render_graph/app.rs:66:13
   4: <bevy_pbr::ssr::ScreenSpaceReflectionsPlugin as bevy_app::plugin::Plugin>::finish
             at /Users/marius/Documents/dev/bevy/crates/bevy_pbr/src/ssr/mod.rs:234:9
   5: bevy_app::app::App::finish
             at /Users/marius/Documents/dev/bevy/crates/bevy_app/src/app.rs:255:13
   6: bevy_winit::state::winit_runner
             at /Users/marius/Documents/dev/bevy/crates/bevy_winit/src/state.rs:859:9
   7: core::ops::function::FnOnce::call_once
             at /Users/marius/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /Users/marius/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
   9: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /Users/marius/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:2454:9
  10: bevy_app::app::App::run
             at /Users/marius/Documents/dev/bevy/crates/bevy_app/src/app.rs:184:9
  11: bevy_deferred_test::main
             at ./src/main.rs:9:5
  12: core::ops::function::FnOnce::call_once
             at /Users/marius/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
```


### Minimal reproduction example:
```rust
use bevy::core_pipeline::prepass::{DeferredPrepass, DepthPrepass};
use bevy::pbr::{DefaultOpaqueRendererMethod, PbrPlugin, ScreenSpaceReflections};
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(PbrPlugin {
            add_default_deferred_lighting_plugin: false,
            ..default()
        }))
        .add_systems(Startup, setup)
        .insert_resource(DefaultOpaqueRendererMethod::deferred())
        .run();
}

/// set up a camera
fn setup(
    mut commands: Commands
) {
    // camera
    commands.spawn((
        Camera3d::default(),
        Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
        DepthPrepass,
        DeferredPrepass,
        ScreenSpaceReflections::default(),
    ));
}
```

# The Fix
When no node under the default lighting node's label exists, this label
isn't added to the SSR's graph node edges. It's good to keep the
SSRPlugin enabled, this way, users can plug in their own lighting
system, which I have successfully done on top of this PR.

# Workarounds

A current workaround for this issue is to re-use Bevy's
`NodePbr::DeferredLightingPass` as the label for your own custom
lighting pass node.
2025-01-03 19:27:41 +01:00
..
bevy_a11y Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_animation Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_app Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_asset Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_audio Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_color Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_core Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_core_pipeline Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_derive Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_dev_tools Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_diagnostic Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_dylib Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_ecs Set panic as default fallible system param behavior (#16638) 2025-01-03 19:27:37 +01:00
bevy_encase_derive Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_gilrs Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_gizmos Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_gltf Make bevy_gltf compile without bevy_animation feature (#16551) 2025-01-03 19:15:53 +01:00
bevy_hierarchy Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_image Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_input Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_internal Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_log Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_macro_utils Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_math Fix atan2 docs (#16673) 2025-01-03 19:15:53 +01:00
bevy_mesh Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_mikktspace Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_pbr (fix) SSRPlugin: Don't reference default deferred lighting pass if it doesn't exist (#16932) 2025-01-03 19:27:41 +01:00
bevy_picking picking: disable raycast backface culling for Mesh2d (#16657) 2025-01-03 19:15:53 +01:00
bevy_ptr Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_reflect Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_remote BrpQueryRow has field deserialization fix (#16613) 2025-01-03 19:15:53 +01:00
bevy_render Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_scene Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_sprite Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_state Make StateTransitionSteps public (#16612) 2025-01-03 19:15:53 +01:00
bevy_tasks Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_text Add missing registration for TextEntity (#16649) 2025-01-03 19:15:53 +01:00
bevy_time Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_transform Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_ui ScrollPosition scale factor fix (#16617) 2025-01-03 19:26:40 +01:00
bevy_utils Release 0.15.0 2024-11-29 01:50:42 +01:00
bevy_window add missing type registration for Monitor (#16685) 2025-01-03 19:15:53 +01:00
bevy_winit Release 0.15.0 2024-11-29 01:50:42 +01:00