77//! implementation using Bevy's low level rendering API.
88//! It's generally recommended to try the built-in instancing before going with this approach.
99
10+ use bevy:: asset:: { load_internal_asset, weak_handle} ;
1011use bevy:: {
1112 core_pipeline:: core_3d:: Transparent3d ,
1213 ecs:: {
@@ -36,9 +37,6 @@ use bevy::{
3637} ;
3738use bytemuck:: { Pod , Zeroable } ;
3839
39- /// Path to the WGSL shader asset used for custom instancing rendering.
40- const SHADER_ASSET_PATH : & str = "shaders/instancing.wgsl" ;
41-
4240/// Component holding per-instance data for custom rendering.
4341#[ derive( Component ) ]
4442pub struct InstanceMaterialData {
@@ -61,6 +59,7 @@ impl ExtractComponent for InstanceMaterialData {
6159/// Plugin that sets up the custom voxel material pipeline.
6260pub struct VoxelMaterialPlugin ;
6361
62+ pub const SHADER_HANDLE : Handle < Shader > = weak_handle ! ( "123e4567-e89b-12d3-a456-426614174000" ) ;
6463impl Plugin for VoxelMaterialPlugin {
6564 fn build ( & self , app : & mut App ) {
6665 app. add_plugins ( ExtractComponentPlugin :: < InstanceMaterialData > :: default ( ) ) ;
@@ -74,6 +73,12 @@ impl Plugin for VoxelMaterialPlugin {
7473 prepare_instance_buffers. in_set ( RenderSet :: PrepareResources ) ,
7574 ) ,
7675 ) ;
76+ load_internal_asset ! (
77+ app,
78+ SHADER_HANDLE ,
79+ "../assets/shaders/instancing.wgsl" ,
80+ Shader :: from_wgsl
81+ ) ;
7782 }
7883
7984 fn finish ( & self , app : & mut App ) {
@@ -206,11 +211,11 @@ struct CustomPipeline {
206211
207212impl FromWorld for CustomPipeline {
208213 fn from_world ( world : & mut World ) -> Self {
209- let mesh_pipeline = world. resource :: < MeshPipeline > ( ) ;
214+ let mesh_pipeline = world. resource :: < MeshPipeline > ( ) . clone ( ) ;
210215
211216 CustomPipeline {
212- shader : world . load_asset ( SHADER_ASSET_PATH ) ,
213- mesh_pipeline : mesh_pipeline . clone ( ) ,
217+ shader : SHADER_HANDLE . clone ( ) ,
218+ mesh_pipeline,
214219 }
215220 }
216221}
0 commit comments