diff --git a/examples/shader/shader_material.rs b/examples/shader/shader_material.rs index a54f2ac049d44..2a71fcd585e1c 100644 --- a/examples/shader/shader_material.rs +++ b/examples/shader/shader_material.rs @@ -7,7 +7,9 @@ use bevy::{ render_asset::{PrepareAssetError, RenderAsset}, render_resource::{ std140::{AsStd140, Std140}, - *, + BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, + BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, Buffer, + BufferBindingType, BufferInitDescriptor, BufferSize, BufferUsages, ShaderStages, }, renderer::RenderDevice, }, @@ -44,6 +46,7 @@ fn setup( }); } +// This is the struct that will be passed to your shader #[derive(Debug, Clone, TypeUuid)] #[uuid = "4ee9c363-1124-4113-890e-199d81b00281"] pub struct CustomMaterial { @@ -56,6 +59,7 @@ pub struct GpuCustomMaterial { bind_group: BindGroup, } +// The implementation of [`Material`] needs this impl to work properly. impl RenderAsset for CustomMaterial { type ExtractedAsset = CustomMaterial; type PreparedAsset = GpuCustomMaterial; @@ -91,6 +95,16 @@ impl RenderAsset for CustomMaterial { } impl Material for CustomMaterial { + // When creating a custom material, you need to define either a vertex shader, a fragment shader or both. + // If you don't define one of them it will use the default mesh shader which can be found at + // + + // For this example we don't need a vertex shader + // fn vertex_shader(asset_server: &AssetServer) -> Option> { + // // Use the same path as the fragment shader since wgsl let's you define both shader in the same file + // Some(asset_server.load("shaders/custom_material.wgsl")) + // } + fn fragment_shader(asset_server: &AssetServer) -> Option> { Some(asset_server.load("shaders/custom_material.wgsl")) }