@@ -21,11 +21,11 @@ use bevy_render::{
21
21
renderer:: RenderAdapter ,
22
22
sync_world:: RenderEntity ,
23
23
view:: { RenderVisibilityRanges , RetainedViewEntity , VISIBILITY_RANGES_STORAGE_BUFFER_COUNT } ,
24
- ExtractSchedule , Render , RenderApp , RenderDebugFlags , RenderSystems ,
24
+ ExtractSchedule , Render , RenderApp , RenderDebugFlags , RenderStartup , RenderSystems ,
25
25
} ;
26
26
pub use prepass_bindings:: * ;
27
27
28
- use bevy_asset:: { embedded_asset, load_embedded_asset, Handle } ;
28
+ use bevy_asset:: { embedded_asset, load_embedded_asset, AssetServer , Handle } ;
29
29
use bevy_core_pipeline:: {
30
30
core_3d:: CORE_3D_DEPTH_FORMAT , deferred:: * , prelude:: Camera3d , prepass:: * ,
31
31
} ;
@@ -87,22 +87,16 @@ impl Plugin for PrepassPipelinePlugin {
87
87
} ;
88
88
89
89
render_app
90
+ . add_systems (
91
+ RenderStartup ,
92
+ ( init_prepass_pipeline, init_prepass_view_bind_group) . chain ( ) ,
93
+ )
90
94
. add_systems (
91
95
Render ,
92
96
prepare_prepass_view_bind_group. in_set ( RenderSystems :: PrepareBindGroups ) ,
93
97
)
94
98
. init_resource :: < SpecializedMeshPipelines < PrepassPipelineSpecializer > > ( ) ;
95
99
}
96
-
97
- fn finish ( & self , app : & mut App ) {
98
- let Some ( render_app) = app. get_sub_app_mut ( RenderApp ) else {
99
- return ;
100
- } ;
101
-
102
- render_app
103
- . init_resource :: < PrepassPipeline > ( )
104
- . init_resource :: < PrepassViewBindGroup > ( ) ;
105
- }
106
100
}
107
101
108
102
/// Sets up the prepasses for a material.
@@ -273,78 +267,79 @@ pub struct PrepassPipeline {
273
267
pub material_pipeline : MaterialPipeline ,
274
268
}
275
269
276
- impl FromWorld for PrepassPipeline {
277
- fn from_world ( world : & mut World ) -> Self {
278
- let render_device = world. resource :: < RenderDevice > ( ) ;
279
- let render_adapter = world. resource :: < RenderAdapter > ( ) ;
280
- let visibility_ranges_buffer_binding_type = render_device
281
- . get_supported_read_only_binding_type ( VISIBILITY_RANGES_STORAGE_BUFFER_COUNT ) ;
282
-
283
- let view_layout_motion_vectors = render_device. create_bind_group_layout (
284
- "prepass_view_layout_motion_vectors" ,
285
- & BindGroupLayoutEntries :: with_indices (
286
- ShaderStages :: VERTEX_FRAGMENT ,
270
+ pub fn init_prepass_pipeline (
271
+ mut commands : Commands ,
272
+ render_device : Res < RenderDevice > ,
273
+ render_adapter : Res < RenderAdapter > ,
274
+ mesh_pipeline : Res < MeshPipeline > ,
275
+ material_pipeline : Res < MaterialPipeline > ,
276
+ asset_server : Res < AssetServer > ,
277
+ ) {
278
+ let visibility_ranges_buffer_binding_type =
279
+ render_device. get_supported_read_only_binding_type ( VISIBILITY_RANGES_STORAGE_BUFFER_COUNT ) ;
280
+
281
+ let view_layout_motion_vectors = render_device. create_bind_group_layout (
282
+ "prepass_view_layout_motion_vectors" ,
283
+ & BindGroupLayoutEntries :: with_indices (
284
+ ShaderStages :: VERTEX_FRAGMENT ,
285
+ (
286
+ // View
287
+ ( 0 , uniform_buffer :: < ViewUniform > ( true ) ) ,
288
+ // Globals
289
+ ( 1 , uniform_buffer :: < GlobalsUniform > ( false ) ) ,
290
+ // PreviousViewUniforms
291
+ ( 2 , uniform_buffer :: < PreviousViewData > ( true ) ) ,
292
+ // VisibilityRanges
287
293
(
288
- // View
289
- ( 0 , uniform_buffer :: < ViewUniform > ( true ) ) ,
290
- // Globals
291
- ( 1 , uniform_buffer :: < GlobalsUniform > ( false ) ) ,
292
- // PreviousViewUniforms
293
- ( 2 , uniform_buffer :: < PreviousViewData > ( true ) ) ,
294
- // VisibilityRanges
295
- (
296
- 14 ,
297
- buffer_layout (
298
- visibility_ranges_buffer_binding_type,
299
- false ,
300
- Some ( Vec4 :: min_size ( ) ) ,
301
- )
302
- . visibility ( ShaderStages :: VERTEX ) ,
303
- ) ,
294
+ 14 ,
295
+ buffer_layout (
296
+ visibility_ranges_buffer_binding_type,
297
+ false ,
298
+ Some ( Vec4 :: min_size ( ) ) ,
299
+ )
300
+ . visibility ( ShaderStages :: VERTEX ) ,
304
301
) ,
305
302
) ,
306
- ) ;
303
+ ) ,
304
+ ) ;
307
305
308
- let view_layout_no_motion_vectors = render_device. create_bind_group_layout (
309
- "prepass_view_layout_no_motion_vectors" ,
310
- & BindGroupLayoutEntries :: with_indices (
311
- ShaderStages :: VERTEX_FRAGMENT ,
306
+ let view_layout_no_motion_vectors = render_device. create_bind_group_layout (
307
+ "prepass_view_layout_no_motion_vectors" ,
308
+ & BindGroupLayoutEntries :: with_indices (
309
+ ShaderStages :: VERTEX_FRAGMENT ,
310
+ (
311
+ // View
312
+ ( 0 , uniform_buffer :: < ViewUniform > ( true ) ) ,
313
+ // Globals
314
+ ( 1 , uniform_buffer :: < GlobalsUniform > ( false ) ) ,
315
+ // VisibilityRanges
312
316
(
313
- // View
314
- ( 0 , uniform_buffer :: < ViewUniform > ( true ) ) ,
315
- // Globals
316
- ( 1 , uniform_buffer :: < GlobalsUniform > ( false ) ) ,
317
- // VisibilityRanges
318
- (
319
- 14 ,
320
- buffer_layout (
321
- visibility_ranges_buffer_binding_type,
322
- false ,
323
- Some ( Vec4 :: min_size ( ) ) ,
324
- )
325
- . visibility ( ShaderStages :: VERTEX ) ,
326
- ) ,
317
+ 14 ,
318
+ buffer_layout (
319
+ visibility_ranges_buffer_binding_type,
320
+ false ,
321
+ Some ( Vec4 :: min_size ( ) ) ,
322
+ )
323
+ . visibility ( ShaderStages :: VERTEX ) ,
327
324
) ,
328
325
) ,
329
- ) ;
326
+ ) ,
327
+ ) ;
330
328
331
- let mesh_pipeline = world. resource :: < MeshPipeline > ( ) ;
332
-
333
- let depth_clip_control_supported = render_device
334
- . features ( )
335
- . contains ( WgpuFeatures :: DEPTH_CLIP_CONTROL ) ;
336
- PrepassPipeline {
337
- view_layout_motion_vectors,
338
- view_layout_no_motion_vectors,
339
- mesh_layouts : mesh_pipeline. mesh_layouts . clone ( ) ,
340
- default_prepass_shader : load_embedded_asset ! ( world, "prepass.wgsl" ) ,
341
- skins_use_uniform_buffers : skin:: skins_use_uniform_buffers ( render_device) ,
342
- depth_clip_control_supported,
343
- binding_arrays_are_usable : binding_arrays_are_usable ( render_device, render_adapter) ,
344
- empty_layout : render_device. create_bind_group_layout ( "prepass_empty_layout" , & [ ] ) ,
345
- material_pipeline : world. resource :: < MaterialPipeline > ( ) . clone ( ) ,
346
- }
347
- }
329
+ let depth_clip_control_supported = render_device
330
+ . features ( )
331
+ . contains ( WgpuFeatures :: DEPTH_CLIP_CONTROL ) ;
332
+ commands. insert_resource ( PrepassPipeline {
333
+ view_layout_motion_vectors,
334
+ view_layout_no_motion_vectors,
335
+ mesh_layouts : mesh_pipeline. mesh_layouts . clone ( ) ,
336
+ default_prepass_shader : load_embedded_asset ! ( asset_server. as_ref( ) , "prepass.wgsl" ) ,
337
+ skins_use_uniform_buffers : skin:: skins_use_uniform_buffers ( & render_device) ,
338
+ depth_clip_control_supported,
339
+ binding_arrays_are_usable : binding_arrays_are_usable ( & render_device, & render_adapter) ,
340
+ empty_layout : render_device. create_bind_group_layout ( "prepass_empty_layout" , & [ ] ) ,
341
+ material_pipeline : material_pipeline. clone ( ) ,
342
+ } ) ;
348
343
}
349
344
350
345
pub struct PrepassPipelineSpecializer {
@@ -702,22 +697,21 @@ pub struct PrepassViewBindGroup {
702
697
pub empty_bind_group : BindGroup ,
703
698
}
704
699
705
- impl FromWorld for PrepassViewBindGroup {
706
- fn from_world ( world : & mut World ) -> Self {
707
- let pipeline = world. resource :: < PrepassPipeline > ( ) ;
708
-
709
- let render_device = world. resource :: < RenderDevice > ( ) ;
710
- let empty_bind_group = render_device. create_bind_group (
711
- "prepass_view_empty_bind_group" ,
712
- & pipeline. empty_layout ,
713
- & [ ] ,
714
- ) ;
715
- PrepassViewBindGroup {
716
- motion_vectors : None ,
717
- no_motion_vectors : None ,
718
- empty_bind_group,
719
- }
720
- }
700
+ pub fn init_prepass_view_bind_group (
701
+ mut commands : Commands ,
702
+ render_device : Res < RenderDevice > ,
703
+ pipeline : Res < PrepassPipeline > ,
704
+ ) {
705
+ let empty_bind_group = render_device. create_bind_group (
706
+ "prepass_view_empty_bind_group" ,
707
+ & pipeline. empty_layout ,
708
+ & [ ] ,
709
+ ) ;
710
+ commands. insert_resource ( PrepassViewBindGroup {
711
+ motion_vectors : None ,
712
+ no_motion_vectors : None ,
713
+ empty_bind_group,
714
+ } ) ;
721
715
}
722
716
723
717
pub fn prepare_prepass_view_bind_group (
0 commit comments