7
7
//! implementation using Bevy's low level rendering API.
8
8
//! It's generally recommended to try the built-in instancing before going with this approach.
9
9
10
+ use bevy:: asset:: { load_internal_asset, weak_handle} ;
10
11
use bevy:: {
11
12
core_pipeline:: core_3d:: Transparent3d ,
12
13
ecs:: {
@@ -36,9 +37,6 @@ use bevy::{
36
37
} ;
37
38
use bytemuck:: { Pod , Zeroable } ;
38
39
39
- /// Path to the WGSL shader asset used for custom instancing rendering.
40
- const SHADER_ASSET_PATH : & str = "shaders/instancing.wgsl" ;
41
-
42
40
/// Component holding per-instance data for custom rendering.
43
41
#[ derive( Component ) ]
44
42
pub struct InstanceMaterialData {
@@ -61,6 +59,7 @@ impl ExtractComponent for InstanceMaterialData {
61
59
/// Plugin that sets up the custom voxel material pipeline.
62
60
pub struct VoxelMaterialPlugin ;
63
61
62
+ pub const SHADER_HANDLE : Handle < Shader > = weak_handle ! ( "123e4567-e89b-12d3-a456-426614174000" ) ;
64
63
impl Plugin for VoxelMaterialPlugin {
65
64
fn build ( & self , app : & mut App ) {
66
65
app. add_plugins ( ExtractComponentPlugin :: < InstanceMaterialData > :: default ( ) ) ;
@@ -74,6 +73,12 @@ impl Plugin for VoxelMaterialPlugin {
74
73
prepare_instance_buffers. in_set ( RenderSet :: PrepareResources ) ,
75
74
) ,
76
75
) ;
76
+ load_internal_asset ! (
77
+ app,
78
+ SHADER_HANDLE ,
79
+ "../assets/shaders/instancing.wgsl" ,
80
+ Shader :: from_wgsl
81
+ ) ;
77
82
}
78
83
79
84
fn finish ( & self , app : & mut App ) {
@@ -206,11 +211,11 @@ struct CustomPipeline {
206
211
207
212
impl FromWorld for CustomPipeline {
208
213
fn from_world ( world : & mut World ) -> Self {
209
- let mesh_pipeline = world. resource :: < MeshPipeline > ( ) ;
214
+ let mesh_pipeline = world. resource :: < MeshPipeline > ( ) . clone ( ) ;
210
215
211
216
CustomPipeline {
212
- shader : world . load_asset ( SHADER_ASSET_PATH ) ,
213
- mesh_pipeline : mesh_pipeline . clone ( ) ,
217
+ shader : SHADER_HANDLE . clone ( ) ,
218
+ mesh_pipeline,
214
219
}
215
220
}
216
221
}
0 commit comments