Add setting to enable/disable shadows to MaterialPlugin (#12538)

# Objective

- Not all materials need shadow, but a queue_shadows system is always
added to the `Render` schedule and executed

## Solution

- Make a setting for shadows, it defaults to true

## Changelog

- Added `shadows_enabled` setting to `MaterialPlugin`

## Migration Guide

- `MaterialPlugin` now has a `shadows_enabled` setting, if you didn't
spawn the plugin using `::default()` or `..default()`, you'll need to
set it. `shadows_enabled: true` is the same behavior as the previous
version, and also the default value.
This commit is contained in:
NiseVoid 2024-03-18 18:54:41 +01:00 committed by GitHub
parent 70da903cec
commit ce75dec3b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -193,6 +193,8 @@ pub struct MaterialPlugin<M: Material> {
/// When it is enabled, it will automatically add the [`PrepassPlugin`] /// When it is enabled, it will automatically add the [`PrepassPlugin`]
/// required to make the prepass work on this Material. /// required to make the prepass work on this Material.
pub prepass_enabled: bool, pub prepass_enabled: bool,
/// Controls if shadows are enabled for the Material.
pub shadows_enabled: bool,
pub _marker: PhantomData<M>, pub _marker: PhantomData<M>,
} }
@ -200,6 +202,7 @@ impl<M: Material> Default for MaterialPlugin<M> {
fn default() -> Self { fn default() -> Self {
Self { Self {
prepass_enabled: true, prepass_enabled: true,
shadows_enabled: true,
_marker: Default::default(), _marker: Default::default(),
} }
} }
@ -231,18 +234,26 @@ where
prepare_materials::<M> prepare_materials::<M>
.in_set(RenderSet::PrepareAssets) .in_set(RenderSet::PrepareAssets)
.after(prepare_assets::<Image>), .after(prepare_assets::<Image>),
queue_shadows::<M>
.in_set(RenderSet::QueueMeshes)
.after(prepare_materials::<M>),
queue_material_meshes::<M> queue_material_meshes::<M>
.in_set(RenderSet::QueueMeshes) .in_set(RenderSet::QueueMeshes)
.after(prepare_materials::<M>), .after(prepare_materials::<M>),
), ),
); );
if self.shadows_enabled {
render_app.add_systems(
Render,
(queue_shadows::<M>
.in_set(RenderSet::QueueMeshes)
.after(prepare_materials::<M>),),
);
}
} }
// PrepassPipelinePlugin is required for shadow mapping and the optional PrepassPlugin if self.shadows_enabled || self.prepass_enabled {
app.add_plugins(PrepassPipelinePlugin::<M>::default()); // PrepassPipelinePlugin is required for shadow mapping and the optional PrepassPlugin
app.add_plugins(PrepassPipelinePlugin::<M>::default());
}
if self.prepass_enabled { if self.prepass_enabled {
app.add_plugins(PrepassPlugin::<M>::default()); app.add_plugins(PrepassPlugin::<M>::default());