diff --git a/examples/shader/animate_shader.rs b/examples/shader/animate_shader.rs index dd46d6293d985..6226395da707a 100644 --- a/examples/shader/animate_shader.rs +++ b/examples/shader/animate_shader.rs @@ -56,20 +56,9 @@ pub struct CustomMaterialPlugin; impl Plugin for CustomMaterialPlugin { fn build(&self, app: &mut App) { - let render_device = app.world.resource::(); - let buffer = render_device.create_buffer(&BufferDescriptor { - label: Some("time uniform buffer"), - size: std::mem::size_of::() as u64, - usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST, - mapped_at_creation: false, - }); - app.sub_app_mut(RenderApp) .add_render_command::() - .insert_resource(TimeMeta { - buffer, - bind_group: None, - }) + .init_resource::() .init_resource::() .init_resource::>() .add_system_to_stage(RenderStage::Extract, extract_time) @@ -133,34 +122,35 @@ fn queue_custom( } } -#[derive(Default)] -struct ExtractedTime { +#[derive(Default, Clone, ShaderType)] +struct TimeUniform { + // on WebGL, uniforms need to be at least 16 bytes wide + #[align(16)] seconds_since_startup: f32, } // extract the passed time into a resource in the render world fn extract_time(mut commands: Commands, time: Res