//! A shader that uses the WESL shading language. use bevy::{ asset::{load_internal_asset, weak_handle}, pbr::{MaterialPipeline, MaterialPipelineKey}, prelude::*, reflect::TypePath, render::{ mesh::MeshVertexBufferLayoutRef, render_resource::{ AsBindGroup, RenderPipelineDescriptor, ShaderDefVal, ShaderRef, SpecializedMeshPipelineError, }, }, }; /// This example uses shader source files from the assets subdirectory const FRAGMENT_SHADER_ASSET_PATH: &str = "shaders/custom_material.wesl"; /// An example utility shader that is used by the custom material pub const UTIL_SHADER_HANDLE: Handle = weak_handle!("748706a1-969e-43d4-be36-74559bd31d23"); fn main() { App::new() .add_plugins(( DefaultPlugins, MaterialPlugin::::default(), CustomMaterialPlugin, )) .add_systems(Startup, setup) .add_systems(Update, update) .run(); } /// A plugin that loads the custom material shader pub struct CustomMaterialPlugin; impl Plugin for CustomMaterialPlugin { fn build(&self, app: &mut App) { load_internal_asset!( app, UTIL_SHADER_HANDLE, "../../assets/shaders/util.wesl", Shader::from_wesl ); } } /// set up a simple 3D scene fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // cube commands.spawn(( Mesh3d(meshes.add(Cuboid::default())), MeshMaterial3d(materials.add(CustomMaterial { time: 0.0, party_mode: false, })), Transform::from_xyz(0.0, 0.5, 0.0), )); // camera commands.spawn(( Camera3d::default(), Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), )); } fn update( time: Res