Use PluginGroup for SolariPlugins (#20044)

This commit is contained in:
JMS55 2025-07-09 11:31:39 -07:00 committed by GitHub
parent d45ae74286
commit 1a3b26d433
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 22 deletions

View File

@ -2,7 +2,7 @@
//! Provides raytraced lighting.
//!
//! See [`SolariPlugin`] for more info.
//! See [`SolariPlugins`] for more info.
//!
//! ![`bevy_solari` logo](https://raw.githubusercontent.com/bevyengine/bevy/assets/branding/bevy_solari.svg)
pub mod pathtracer;
@ -13,33 +13,35 @@ pub mod scene;
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
pub use super::SolariPlugin;
pub use super::SolariPlugins;
pub use crate::realtime::SolariLighting;
pub use crate::scene::RaytracingMesh3d;
}
use crate::realtime::SolariLightingPlugin;
use crate::scene::RaytracingScenePlugin;
use bevy_app::{App, Plugin};
use bevy_app::{PluginGroup, PluginGroupBuilder};
use bevy_render::settings::WgpuFeatures;
/// An experimental plugin for raytraced lighting.
/// An experimental set of plugins for raytraced lighting.
///
/// This plugin provides:
/// This plugin group provides:
/// * [`SolariLightingPlugin`] - Raytraced direct and indirect lighting (indirect lighting not yet implemented).
/// * [`RaytracingScenePlugin`] - BLAS building, resource and lighting binding.
/// * [`pathtracer::PathtracingPlugin`] - A non-realtime pathtracer for validation purposes.
/// * [`pathtracer::PathtracingPlugin`] - A non-realtime pathtracer for validation purposes (not added by default).
///
/// To get started, add `RaytracingMesh3d` and `MeshMaterial3d::<StandardMaterial>` to your entities.
pub struct SolariPlugin;
pub struct SolariPlugins;
impl Plugin for SolariPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((RaytracingScenePlugin, SolariLightingPlugin));
impl PluginGroup for SolariPlugins {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
.add(RaytracingScenePlugin)
.add(SolariLightingPlugin)
}
}
impl SolariPlugin {
impl SolariPlugins {
/// [`WgpuFeatures`] required for this plugin to function.
pub fn required_wgpu_features() -> WgpuFeatures {
WgpuFeatures::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE

View File

@ -2,7 +2,7 @@ mod extract;
mod node;
mod prepare;
use crate::SolariPlugin;
use crate::SolariPlugins;
use bevy_app::{App, Plugin};
use bevy_asset::embedded_asset;
use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d};
@ -37,10 +37,10 @@ impl Plugin for PathtracingPlugin {
let render_device = render_app.world().resource::<RenderDevice>();
let features = render_device.features();
if !features.contains(SolariPlugin::required_wgpu_features()) {
if !features.contains(SolariPlugins::required_wgpu_features()) {
warn!(
"PathtracingPlugin not loaded. GPU lacks support for required features: {:?}.",
SolariPlugin::required_wgpu_features().difference(features)
SolariPlugins::required_wgpu_features().difference(features)
);
return;
}

View File

@ -2,7 +2,7 @@ mod extract;
mod node;
mod prepare;
use crate::SolariPlugin;
use crate::SolariPlugins;
use bevy_app::{App, Plugin};
use bevy_asset::embedded_asset;
use bevy_core_pipeline::{
@ -38,10 +38,10 @@ impl Plugin for SolariLightingPlugin {
let render_device = render_app.world().resource::<RenderDevice>();
let features = render_device.features();
if !features.contains(SolariPlugin::required_wgpu_features()) {
if !features.contains(SolariPlugins::required_wgpu_features()) {
warn!(
"SolariLightingPlugin not loaded. GPU lacks support for required features: {:?}.",
SolariPlugin::required_wgpu_features().difference(features)
SolariPlugins::required_wgpu_features().difference(features)
);
return;
}

View File

@ -6,7 +6,7 @@ mod types;
pub use binder::RaytracingSceneBindings;
pub use types::RaytracingMesh3d;
use crate::SolariPlugin;
use crate::SolariPlugins;
use bevy_app::{App, Plugin};
use bevy_ecs::schedule::IntoScheduleConfigs;
use bevy_render::{
@ -41,10 +41,10 @@ impl Plugin for RaytracingScenePlugin {
let render_app = app.sub_app_mut(RenderApp);
let render_device = render_app.world().resource::<RenderDevice>();
let features = render_device.features();
if !features.contains(SolariPlugin::required_wgpu_features()) {
if !features.contains(SolariPlugins::required_wgpu_features()) {
warn!(
"RaytracingScenePlugin not loaded. GPU lacks support for required features: {:?}.",
SolariPlugin::required_wgpu_features().difference(features)
SolariPlugins::required_wgpu_features().difference(features)
);
return;
}

View File

@ -10,7 +10,7 @@ use bevy::{
scene::SceneInstanceReady,
solari::{
pathtracer::{Pathtracer, PathtracingPlugin},
prelude::{RaytracingMesh3d, SolariLighting, SolariPlugin},
prelude::{RaytracingMesh3d, SolariLighting, SolariPlugins},
},
};
use camera_controller::{CameraController, CameraControllerPlugin};
@ -28,7 +28,7 @@ fn main() {
let args: Args = argh::from_env();
let mut app = App::new();
app.add_plugins((DefaultPlugins, SolariPlugin, CameraControllerPlugin))
app.add_plugins((DefaultPlugins, SolariPlugins, CameraControllerPlugin))
.insert_resource(args)
.add_systems(Startup, setup);