@@ -179,6 +179,19 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized {
179
179
false
180
180
}
181
181
182
+ /// Controls if the prepass is enabled for the Material.
183
+ /// For more information about what a prepass is, see the [`bevy_core_pipeline::prepass`] docs.
184
+ #[ inline]
185
+ fn enable_prepass ( ) -> bool {
186
+ true
187
+ }
188
+
189
+ /// Controls if shadows are enabled for the Material.
190
+ #[ inline]
191
+ fn enable_shadows ( ) -> bool {
192
+ true
193
+ }
194
+
182
195
/// Returns this material's prepass vertex shader. If [`ShaderRef::Default`] is returned, the default prepass vertex shader
183
196
/// will be used.
184
197
///
@@ -324,14 +337,6 @@ impl Plugin for MaterialsPlugin {
324
337
/// Adds the necessary ECS resources and render logic to enable rendering entities using the given [`Material`]
325
338
/// asset type.
326
339
pub struct MaterialPlugin < M : Material > {
327
- /// Controls if the prepass is enabled for the Material.
328
- /// For more information about what a prepass is, see the [`bevy_core_pipeline::prepass`] docs.
329
- ///
330
- /// When it is enabled, it will automatically add the [`PrepassPlugin`]
331
- /// required to make the prepass work on this Material.
332
- pub prepass_enabled : bool ,
333
- /// Controls if shadows are enabled for the Material.
334
- pub shadows_enabled : bool ,
335
340
/// Debugging flags that can optionally be set when constructing the renderer.
336
341
pub debug_flags : RenderDebugFlags ,
337
342
pub _marker : PhantomData < M > ,
@@ -340,8 +345,6 @@ pub struct MaterialPlugin<M: Material> {
340
345
impl < M : Material > Default for MaterialPlugin < M > {
341
346
fn default ( ) -> Self {
342
347
Self {
343
- prepass_enabled : true ,
344
- shadows_enabled : true ,
345
348
debug_flags : RenderDebugFlags :: default ( ) ,
346
349
_marker : Default :: default ( ) ,
347
350
}
@@ -366,7 +369,7 @@ where
366
369
. after ( mark_3d_meshes_as_changed_if_their_assets_changed) ,
367
370
) ;
368
371
369
- if self . shadows_enabled {
372
+ if M :: enable_shadows ( ) {
370
373
app. add_systems (
371
374
PostUpdate ,
372
375
check_light_entities_needing_specialization :: < M >
@@ -375,13 +378,6 @@ where
375
378
}
376
379
377
380
if let Some ( render_app) = app. get_sub_app_mut ( RenderApp ) {
378
- if self . prepass_enabled {
379
- render_app. init_resource :: < PrepassEnabled < M > > ( ) ;
380
- }
381
- if self . shadows_enabled {
382
- render_app. init_resource :: < ShadowsEnabled < M > > ( ) ;
383
- }
384
-
385
381
render_app
386
382
. add_systems ( RenderStartup , add_material_bind_group_allocator :: < M > )
387
383
. add_systems (
@@ -1511,11 +1507,7 @@ where
1511
1507
SRes < DrawFunctions < AlphaMask3dDeferred > > ,
1512
1508
SRes < DrawFunctions < Shadow > > ,
1513
1509
SRes < AssetServer > ,
1514
- (
1515
- Option < SRes < ShadowsEnabled < M > > > ,
1516
- Option < SRes < PrepassEnabled < M > > > ,
1517
- M :: Param ,
1518
- ) ,
1510
+ M :: Param ,
1519
1511
) ;
1520
1512
1521
1513
fn prepare_asset (
@@ -1536,13 +1528,13 @@ where
1536
1528
alpha_mask_deferred_draw_functions,
1537
1529
shadow_draw_functions,
1538
1530
asset_server,
1539
- ( shadows_enabled , prepass_enabled , material_param) ,
1531
+ material_param,
1540
1532
) : & mut SystemParamItem < Self :: Param > ,
1541
1533
) -> Result < Self :: ErasedAsset , PrepareAssetError < Self :: SourceAsset > > {
1542
1534
let material_layout = M :: bind_group_layout ( render_device) ;
1543
1535
1544
- let shadows_enabled = shadows_enabled . is_some ( ) ;
1545
- let prepass_enabled = prepass_enabled . is_some ( ) ;
1536
+ let shadows_enabled = M :: enable_shadows ( ) ;
1537
+ let prepass_enabled = M :: enable_prepass ( ) ;
1546
1538
1547
1539
let draw_opaque_pbr = opaque_draw_functions. read ( ) . id :: < DrawMaterial > ( ) ;
1548
1540
let draw_alpha_mask_pbr = alpha_mask_draw_functions. read ( ) . id :: < DrawMaterial > ( ) ;
@@ -1811,13 +1803,3 @@ pub fn write_material_bind_group_buffers(
1811
1803
allocator. write_buffers ( & render_device, & render_queue) ;
1812
1804
}
1813
1805
}
1814
-
1815
- /// Marker resource for whether shadows are enabled for this material type
1816
- #[ derive( Resource , Debug ) ]
1817
- pub struct ShadowsEnabled < M : Material > ( PhantomData < M > ) ;
1818
-
1819
- impl < M : Material > Default for ShadowsEnabled < M > {
1820
- fn default ( ) -> Self {
1821
- Self ( PhantomData )
1822
- }
1823
- }
0 commit comments