From b7e7ce89105c9dbc9ac259972db54b0219f0d7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Grabarz?= Date: Fri, 5 Jul 2024 02:08:47 +0200 Subject: [PATCH] Update to Bevy 0.14 --- Cargo.toml | 8 +++---- README.md | 1 + examples/cycle.rs | 8 +++---- examples/gradient.rs | 49 +++++++++++++++++++------------------- examples/splitscreen.rs | 4 ++-- macros/src/model.rs | 16 ++++++------- src/collection/gradient.rs | 18 +++++++------- src/model.rs | 4 ++-- src/pipeline.rs | 20 +++++++--------- src/plugin.rs | 10 ++++---- src/skybox.rs | 4 ++-- 11 files changed, 71 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 59a2db3..565a1c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_atmosphere" description = "A procedural sky plugin for bevy" -version = "0.9.1" +version = "0.10.0" edition = "2021" authors = ["JonahPlusPlus <33059163+JonahPlusPlus@users.noreply.github.com>"] license = "MIT OR Apache-2.0" @@ -11,7 +11,7 @@ repository = "https://github.com/JonahPlusPlus/bevy_atmosphere" exclude = ["/assets/", "/examples/", "/.github/"] [dependencies] -bevy = { version = "0.13", default-features = false, features = [ +bevy = { version = "0.14", default-features = false, features = [ "bevy_asset", "bevy_render", "bevy_pbr", @@ -20,8 +20,8 @@ bevy_atmosphere_macros = { path = "macros", version = "0.5" } cfg-if = "1.0" [dev-dependencies] -bevy_spectator = "0.5" -bevy = { version = "0.13", features = ["bevy_core_pipeline", "x11"] } +bevy_spectator = "0.6" +bevy = { version = "0.14", features = ["bevy_core_pipeline", "x11"] } [features] default = ["basic", "all_models"] diff --git a/README.md b/README.md index 6273e19..a8d4215 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ For more information on the technicalities, you can check out the [technical doc | bevy | bevy_atmosphere | |------|-----------------| +| 0.14 | 0.10 | | 0.13 | 0.9 | | 0.12 | 0.8 | | 0.11 | 0.7 | diff --git a/examples/cycle.rs b/examples/cycle.rs index ea9cbe4..c93449f 100644 --- a/examples/cycle.rs +++ b/examples/cycle.rs @@ -65,14 +65,14 @@ fn setup_environment( // Simple transform shape just for reference commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::default()), - material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.8, 0.8))), + material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.8, 0.8))), ..Default::default() }); // X axis commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::new(0.5, 0.5, 0.5)), - material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.0, 0.0))), + material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.0, 0.0))), transform: Transform::from_xyz(1., 0., 0.), ..Default::default() }); @@ -80,7 +80,7 @@ fn setup_environment( // Y axis commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::new(0.5, 0.5, 0.5)), - material: materials.add(StandardMaterial::from(Color::rgb(0.0, 0.8, 0.0))), + material: materials.add(StandardMaterial::from(Color::srgb(0.0, 0.8, 0.0))), transform: Transform::from_xyz(0., 1., 0.), ..Default::default() }); @@ -88,7 +88,7 @@ fn setup_environment( // Z axis commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::new(0.5, 0.5, 0.5)), - material: materials.add(StandardMaterial::from(Color::rgb(0.0, 0.0, 0.8))), + material: materials.add(StandardMaterial::from(Color::srgb(0.0, 0.0, 0.8))), transform: Transform::from_xyz(0., 0., 1.), ..Default::default() }); diff --git a/examples/gradient.rs b/examples/gradient.rs index 736c897..6b6ba34 100644 --- a/examples/gradient.rs +++ b/examples/gradient.rs @@ -1,3 +1,4 @@ +use bevy::color::palettes; use bevy::prelude::*; use bevy_atmosphere::prelude::*; use bevy_spectator::{Spectator, SpectatorPlugin}; @@ -27,58 +28,58 @@ fn change_gradient(mut commands: Commands, keys: Res>) { } else if keys.just_pressed(KeyCode::Digit2) { info!("Changed to Atmosphere Preset 2 (Cotton Candy)"); commands.insert_resource(AtmosphereModel::new(Gradient { - ground: Color::rgb(1.0, 0.5, 0.75), - horizon: Color::WHITE, - sky: Color::rgb(0.5, 0.75, 1.0), + ground: Color::srgb(1.0, 0.5, 0.75).into(), + horizon: LinearRgba::WHITE, + sky: Color::srgb(0.5, 0.75, 1.0).into(), })); } else if keys.just_pressed(KeyCode::Digit3) { info!("Changed to Atmosphere Preset 3 (80's Sunset)"); commands.insert_resource(AtmosphereModel::new(Gradient { - sky: Color::PURPLE, - horizon: Color::PINK, - ground: Color::ORANGE, + sky: palettes::css::PURPLE.into(), + horizon: palettes::css::PINK.into(), + ground: palettes::css::ORANGE.into(), })); } else if keys.just_pressed(KeyCode::Digit4) { info!("Changed to Atmosphere Preset 4 (Winter)"); commands.insert_resource(AtmosphereModel::new(Gradient { - ground: Color::rgb(0.0, 0.1, 0.2), - horizon: Color::rgb(0.3, 0.4, 0.5), - sky: Color::rgb(0.7, 0.8, 0.9), + ground: Color::srgb(0.0, 0.1, 0.2).into(), + horizon: Color::srgb(0.3, 0.4, 0.5).into(), + sky: Color::srgb(0.7, 0.8, 0.9).into(), })); } else if keys.just_pressed(KeyCode::Digit5) { info!("Changed to Atmosphere Preset 5 (Nether)"); commands.insert_resource(AtmosphereModel::new(Gradient { - ground: Color::BLACK, - horizon: Color::rgb(0.2, 0.0, 0.0), - sky: Color::rgb(0.5, 0.1, 0.0), + ground: LinearRgba::BLACK, + horizon: Color::srgb(0.2, 0.0, 0.0).into(), + sky: Color::srgb(0.5, 0.1, 0.0).into(), })); } else if keys.just_pressed(KeyCode::Digit6) { info!("Changed to Atmosphere Preset 6 (Golden)"); commands.insert_resource(AtmosphereModel::new(Gradient { - ground: Color::ORANGE_RED, - horizon: Color::ORANGE, - sky: Color::GOLD, + ground: palettes::css::ORANGE_RED.into(), + horizon: palettes::css::ORANGE.into(), + sky: palettes::css::GOLD.into(), })); } else if keys.just_pressed(KeyCode::Digit7) { info!("Changed to Atmosphere Preset 7 (Noir)"); commands.insert_resource(AtmosphereModel::new(Gradient { - ground: Color::BLACK, - horizon: Color::BLACK, - sky: Color::WHITE, + ground: LinearRgba::BLACK, + horizon: LinearRgba::BLACK, + sky: LinearRgba::WHITE, })); } else if keys.just_pressed(KeyCode::Digit8) { info!("Changed to Atmosphere Preset 8 (Midnight)"); commands.insert_resource(AtmosphereModel::new(Gradient { - ground: Color::BLACK, - horizon: Color::BLACK, - sky: Color::MIDNIGHT_BLUE, + ground: LinearRgba::BLACK, + horizon: LinearRgba::BLACK, + sky: palettes::css::MIDNIGHT_BLUE.into(), })); } else if keys.just_pressed(KeyCode::Digit9) { info!("Changed to Atmosphere Preset 9 (Greenery)"); commands.insert_resource(AtmosphereModel::new(Gradient { - ground: Color::rgb(0.1, 0.2, 0.0), - horizon: Color::rgb(0.3, 0.4, 0.1), - sky: Color::rgb(0.6, 0.8, 0.2), + ground: Color::srgb(0.1, 0.2, 0.0).into(), + horizon: Color::srgb(0.3, 0.4, 0.1).into(), + sky: Color::srgb(0.6, 0.8, 0.2).into(), })); } else if keys.just_pressed(KeyCode::Digit0) { info!("Reset Atmosphere to Default"); diff --git a/examples/splitscreen.rs b/examples/splitscreen.rs index 19065e7..052c412 100644 --- a/examples/splitscreen.rs +++ b/examples/splitscreen.rs @@ -37,8 +37,8 @@ fn setup( ) { // Plane commands.spawn(PbrBundle { - mesh: meshes.add(Plane3d::new(Vec3::Y).mesh().size(100.0, 100.0)), - material: materials.add(Color::rgb(0.3, 0.5, 0.3)), + mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)), + material: materials.add(Color::srgb(0.3, 0.5, 0.3)), ..default() }); diff --git a/macros/src/model.rs b/macros/src/model.rs index 737080d..c95ffac 100644 --- a/macros/src/model.rs +++ b/macros/src/model.rs @@ -135,7 +135,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { ShaderPathType::None => panic!("Expected `external` or `internal` attribute"), ShaderPathType::External(s) => quote! { { - let asset_server = app.world.resource::(); + let asset_server = app.world().resource::(); asset_server.load(#s) } @@ -262,7 +262,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { binding_impls.push(quote! { #render_path::render_resource::OwnedBindingResource::TextureView({ - let handle: Option<&#asset_path::Handle<#render_path::texture::Image>> = (&self.#field_name).into(); + let handle: Option<&#asset_path::Handle<#render_path::texture::GpuImage>> = (&self.#field_name).into(); if let Some(handle) = handle { images.get(handle).ok_or_else(|| #render_path::render_resource::AsBindGroupError::RetryNextUpdate)?.texture_view.clone() } else { @@ -295,7 +295,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { binding_impls.push(quote! { #render_path::render_resource::OwnedBindingResource::Sampler({ - let handle: Option<&#asset_path::Handle<#render_path::texture::Image>> = (&self.#field_name).into(); + let handle: Option<&#asset_path::Handle<#render_path::texture::GpuImage>> = (&self.#field_name).into(); if let Some(handle) = handle { images.get(handle).ok_or_else(|| #render_path::render_resource::AsBindGroupError::RetryNextUpdate)?.sampler.clone() } else { @@ -417,7 +417,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { &self, layout: &#render_path::render_resource::BindGroupLayout, render_device: &#render_path::renderer::RenderDevice, - images: &#render_path::render_asset::RenderAssets<#render_path::texture::Image>, + images: &#render_path::render_asset::RenderAssets<#render_path::texture::GpuImage>, fallback_image: &#render_path::texture::FallbackImage, ) -> #render_path::render_resource::BindGroup { let bindings = vec![#(#binding_impls,)*]; @@ -450,12 +450,12 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { let handle = #shader_path_impl; let render_app = app.sub_app_mut(#render_path::RenderApp); - let render_device = render_app.world.resource::<#render_path::renderer::RenderDevice>(); - let #atmosphere_path::pipeline::AtmosphereImageBindGroupLayout(image_bind_group_layout) = render_app.world.resource::<#atmosphere_path::pipeline::AtmosphereImageBindGroupLayout>().clone(); + let render_device = render_app.world().resource::<#render_path::renderer::RenderDevice>(); + let #atmosphere_path::pipeline::AtmosphereImageBindGroupLayout(image_bind_group_layout) = render_app.world().resource::<#atmosphere_path::pipeline::AtmosphereImageBindGroupLayout>().clone(); let bind_group_layout = Self::bind_group_layout(render_device); - let mut pipeline_cache = render_app.world.resource_mut::<#render_path::render_resource::PipelineCache>(); + let mut pipeline_cache = render_app.world_mut().resource_mut::<#render_path::render_resource::PipelineCache>(); let pipeline = pipeline_cache.queue_compute_pipeline(#render_path::render_resource::ComputePipelineDescriptor { label: Some(Cow::from("bevy_atmosphere_compute_pipeline")), @@ -477,7 +477,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { pipeline, }; - let type_registry = app.world.resource_mut::<#ecs_path::reflect::AppTypeRegistry>(); + let type_registry = app.world_mut().resource_mut::<#ecs_path::reflect::AppTypeRegistry>(); { let mut type_registry = type_registry.write(); diff --git a/src/collection/gradient.rs b/src/collection/gradient.rs index 214d3f1..bd886d4 100644 --- a/src/collection/gradient.rs +++ b/src/collection/gradient.rs @@ -8,32 +8,32 @@ use bevy::{prelude::*, render::render_resource::ShaderType}; #[uniform(0, Gradient)] #[internal("shaders/gradient.wgsl")] pub struct Gradient { - /// Sky Color (Default: `Color::rgb(0.29, 0.41, 0.50)`). + /// Sky Color (Default: `Color::srgb(0.29, 0.41, 0.50)`). ///
/// /// /// The color of the top. - pub sky: Color, - /// Horizon Color (Default: `Color::rgb(0.48, 0.62, 0.69)`). + pub sky: LinearRgba, + /// Horizon Color (Default: `Color::srgb(0.48, 0.62, 0.69)`). ///
/// /// /// The color of the sides. - pub horizon: Color, - /// Ground Color (Default: `Color::rgb(0.71, 0.69, 0.57)`). + pub horizon: LinearRgba, + /// Ground Color (Default: `Color::srgb(0.71, 0.69, 0.57)`). ///
/// /// /// The color of the bottom. - pub ground: Color, + pub ground: LinearRgba, } impl Default for Gradient { fn default() -> Self { Self { - sky: Color::rgb(0.29, 0.41, 0.50), - horizon: Color::rgb(0.48, 0.62, 0.69), - ground: Color::rgb(0.71, 0.69, 0.57), + sky: Color::srgb(0.29, 0.41, 0.50).into(), + horizon: Color::srgb(0.48, 0.62, 0.69).into(), + ground: Color::srgb(0.71, 0.69, 0.57).into(), } } } diff --git a/src/model.rs b/src/model.rs index 58a4b56..758d036 100644 --- a/src/model.rs +++ b/src/model.rs @@ -38,7 +38,7 @@ use bevy::{ render_asset::RenderAssets, render_resource::{BindGroup, BindGroupLayout, CachedComputePipelineId}, renderer::RenderDevice, - texture::FallbackImage, + texture::{FallbackImage, GpuImage}, }, }; @@ -55,7 +55,7 @@ pub trait Atmospheric: Send + Sync + Reflect + Any + 'static { &self, layout: &BindGroupLayout, render_device: &RenderDevice, - images: &RenderAssets, + images: &RenderAssets, fallback_image: &FallbackImage, ) -> BindGroup; diff --git a/src/pipeline.rs b/src/pipeline.rs index 417abe8..84cfad5 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -5,7 +5,6 @@ use std::ops::Deref; use bevy::{ - ecs::event::event_update_system, prelude::*, render::{ extract_resource::{ExtractResource, ExtractResourcePlugin}, @@ -19,7 +18,7 @@ use bevy::{ TextureFormat, TextureUsages, TextureView, TextureViewDescriptor, TextureViewDimension, }, renderer::RenderDevice, - texture::FallbackImage, + texture::{FallbackImage, GpuImage}, Extract, Render, RenderApp, RenderSet, }, }; @@ -93,12 +92,12 @@ pub struct AtmospherePipelinePlugin; impl Plugin for AtmospherePipelinePlugin { fn build(&self, app: &mut App) { - let settings = match app.world.get_resource::() { + let settings = match app.world().get_resource::() { Some(s) => *s, None => default(), }; - let atmosphere = match app.world.get_resource::() { + let atmosphere = match app.world().get_resource::() { Some(a) => a.clone(), None => default(), }; @@ -119,7 +118,7 @@ impl Plugin for AtmospherePipelinePlugin { image.texture_descriptor = ATMOSPHERE_IMAGE_TEXTURE_DESCRIPTOR(settings.resolution); - let mut image_assets = app.world.resource_mut::>(); + let mut image_assets = app.world_mut().resource_mut::>(); let handle = image_assets.add(image); app.insert_resource(AtmosphereImage { @@ -131,7 +130,7 @@ impl Plugin for AtmospherePipelinePlugin { app.add_systems(Update, atmosphere_settings_changed); - let type_registry = app.world.resource::().clone(); + let type_registry = app.world().resource::().clone(); let render_app = app.sub_app_mut(RenderApp); render_app @@ -139,18 +138,17 @@ impl Plugin for AtmospherePipelinePlugin { .insert_resource(settings) .insert_resource(AtmosphereTypeRegistry(type_registry)) .init_resource::() - .init_resource::>() + .add_event::() .add_systems(ExtractSchedule, extract_atmosphere_resources) .add_systems( Render, ( - event_update_system::.in_set(RenderSet::Prepare), prepare_atmosphere_resources.in_set(RenderSet::PrepareResources), prepare_atmosphere_bind_group.in_set(RenderSet::PrepareBindGroups), ), ); - let mut render_graph = render_app.world.resource_mut::(); + let mut render_graph = render_app.world_mut().resource_mut::(); render_graph.add_node(BevyAtmosphereLabel, AtmosphereNode::default()); render_graph.add_node_edge(BevyAtmosphereLabel, CameraDriverLabel); } @@ -326,7 +324,7 @@ pub const ATMOSPHERE_IMAGE_TEXTURE_DESCRIPTOR: fn(u32) -> TextureDescriptor<'sta fn prepare_atmosphere_resources( mut update_events: ResMut>, mut atmosphere_image: ResMut, - gpu_images: Res>, + gpu_images: Res>, atmosphere: Res, ) { let mut update = || update_events.send(AtmosphereUpdateEvent); @@ -359,7 +357,7 @@ fn prepare_atmosphere_resources( fn prepare_atmosphere_bind_group( mut commands: Commands, mut cached_metadata: ResMut, - gpu_images: Res>, + gpu_images: Res>, atmosphere_image: Res, render_device: Res, fallback_image: Res, diff --git a/src/plugin.rs b/src/plugin.rs index ce2ff72..0e07260 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -37,18 +37,18 @@ impl Plugin for AtmospherePlugin { { let image_handle = { - let image = app.world.get_resource::().expect("`AtmosphereImage` missing! If the `procedural` feature is disabled, add the resource before `AtmospherePlugin`"); + let image = app.world().get_resource::().expect("`AtmosphereImage` missing! If the `procedural` feature is disabled, add the resource before `AtmospherePlugin`"); image.handle.clone() }; let settings = { let settings = app - .world + .world() .get_resource::(); settings.copied().unwrap_or_default() }; - let mut material_assets = app.world.resource_mut::>(); + let mut material_assets = app.world_mut().resource_mut::>(); let material = material_assets.add(SkyBoxMaterial { sky_texture: image_handle, #[cfg(feature = "dithering")] @@ -84,7 +84,7 @@ impl Plugin for AtmospherePlugin { /// When added, a skybox will be created as a child. /// When removed, that skybox will also be removed. /// This behaviour can be disabled by turning off the "detection" feature. -#[derive(Component, Default, Debug, Clone, Copy)] +#[derive(Component, Default, Debug, Clone)] pub struct AtmosphereCamera { /// Controls whether or not the skybox will be seen only on certain render layers. pub render_layers: Option, @@ -129,7 +129,7 @@ fn atmosphere_insert( render_layers: Some(render_layers), } = atmosphere_camera { - child.insert(*render_layers); + child.insert(render_layers.clone()); } }); } diff --git a/src/skybox.rs b/src/skybox.rs index ce67dee..a7a5d6f 100644 --- a/src/skybox.rs +++ b/src/skybox.rs @@ -5,7 +5,7 @@ use bevy::{ prelude::*, reflect::TypePath, render::{ - mesh::{Indices, Mesh, MeshVertexBufferLayout, PrimitiveTopology}, + mesh::{Indices, Mesh, MeshVertexBufferLayoutRef, PrimitiveTopology}, render_resource::{AsBindGroup, RenderPipelineDescriptor, ShaderDefVal, ShaderRef}, }, }; @@ -45,7 +45,7 @@ impl Material for SkyBoxMaterial { fn specialize( _pipeline: &MaterialPipeline, descriptor: &mut RenderPipelineDescriptor, - _layout: &MeshVertexBufferLayout, + _layout: &MeshVertexBufferLayoutRef, key: MaterialPipelineKey, ) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> { #[cfg(feature = "dithering")]