Skip to content

Commit

Permalink
Update to Bevy 0.14 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frizi authored Jul 5, 2024
1 parent 94b8fa2 commit fd3d2dc
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 73 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -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",
Expand All @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
8 changes: 4 additions & 4 deletions examples/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,30 @@ 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()
});

// 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()
});

// 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()
});
Expand Down
49 changes: 25 additions & 24 deletions examples/gradient.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_atmosphere::prelude::*;
use bevy_spectator::{Spectator, SpectatorPlugin};
Expand Down Expand Up @@ -27,58 +28,58 @@ fn change_gradient(mut commands: Commands, keys: Res<ButtonInput<KeyCode>>) {
} 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");
Expand Down
4 changes: 2 additions & 2 deletions examples/splitscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});

Expand Down
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ proc-macro = true

[dependencies]
proc-macro-crate = "3.1"
bevy_macro_utils = "0.13"
bevy_macro_utils = "0.14"

syn = "2.0"
proc-macro2 = "1.0"
Expand Down
16 changes: 8 additions & 8 deletions macros/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {
ShaderPathType::None => panic!("Expected `external` or `internal` attribute"),
ShaderPathType::External(s) => quote! {
{
let asset_server = app.world.resource::<AssetServer>();
let asset_server = app.world().resource::<AssetServer>();

asset_server.load(#s)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {

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 {
Expand Down Expand Up @@ -295,7 +295,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {

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 {
Expand Down Expand Up @@ -417,7 +417,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {
&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,)*];
Expand Down Expand Up @@ -450,12 +450,12 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {
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")),
Expand All @@ -477,7 +477,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {
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();

Expand Down
18 changes: 9 additions & 9 deletions src/collection/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)`).
/// <div style="background-color:rgb(29%, 41%, 50%); width: 10px; padding: 10px; border: 1px solid;"></div>
///
///
/// 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)`).
/// <div style="background-color:rgb(48%, 62%, 69%); width: 10px; padding: 10px; border: 1px solid;"></div>
///
///
/// 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)`).
/// <div style="background-color:rgb(71%, 69%, 57%); width: 10px; padding: 10px; border: 1px solid;"></div>
///
///
/// 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(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//! }
//!
//! fn write_gradient(mut atmosphere: AtmosphereMut<Gradient>) {
//! atmosphere.horizon = Color::RED;
//! atmosphere.horizon = LinearRgba::RED;
//! }
//!
//! fn check_model(atmosphere: Res<AtmosphereModel>) {
Expand Down
4 changes: 2 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use bevy::{
render_asset::RenderAssets,
render_resource::{BindGroup, BindGroupLayout, CachedComputePipelineId},
renderer::RenderDevice,
texture::FallbackImage,
texture::{FallbackImage, GpuImage},
},
};

Expand All @@ -55,7 +55,7 @@ pub trait Atmospheric: Send + Sync + Reflect + Any + 'static {
&self,
layout: &BindGroupLayout,
render_device: &RenderDevice,
images: &RenderAssets<Image>,
images: &RenderAssets<GpuImage>,
fallback_image: &FallbackImage,
) -> BindGroup;

Expand Down
20 changes: 9 additions & 11 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use std::ops::Deref;

use bevy::{
ecs::event::event_update_system,
prelude::*,
render::{
extract_resource::{ExtractResource, ExtractResourcePlugin},
Expand All @@ -19,7 +18,7 @@ use bevy::{
TextureFormat, TextureUsages, TextureView, TextureViewDescriptor, TextureViewDimension,
},
renderer::RenderDevice,
texture::FallbackImage,
texture::{FallbackImage, GpuImage},
Extract, Render, RenderApp, RenderSet,
},
};
Expand Down Expand Up @@ -93,12 +92,12 @@ pub struct AtmospherePipelinePlugin;

impl Plugin for AtmospherePipelinePlugin {
fn build(&self, app: &mut App) {
let settings = match app.world.get_resource::<AtmosphereSettings>() {
let settings = match app.world().get_resource::<AtmosphereSettings>() {
Some(s) => *s,
None => default(),
};

let atmosphere = match app.world.get_resource::<AtmosphereModel>() {
let atmosphere = match app.world().get_resource::<AtmosphereModel>() {
Some(a) => a.clone(),
None => default(),
};
Expand All @@ -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::<Assets<Image>>();
let mut image_assets = app.world_mut().resource_mut::<Assets<Image>>();
let handle = image_assets.add(image);

app.insert_resource(AtmosphereImage {
Expand All @@ -131,26 +130,25 @@ impl Plugin for AtmospherePipelinePlugin {

app.add_systems(Update, atmosphere_settings_changed);

let type_registry = app.world.resource::<AppTypeRegistry>().clone();
let type_registry = app.world().resource::<AppTypeRegistry>().clone();

let render_app = app.sub_app_mut(RenderApp);
render_app
.insert_resource(atmosphere)
.insert_resource(settings)
.insert_resource(AtmosphereTypeRegistry(type_registry))
.init_resource::<CachedAtmosphereModelMetadata>()
.init_resource::<Events<AtmosphereUpdateEvent>>()
.add_event::<AtmosphereUpdateEvent>()
.add_systems(ExtractSchedule, extract_atmosphere_resources)
.add_systems(
Render,
(
event_update_system::<AtmosphereUpdateEvent>.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::<RenderGraph>();
let mut render_graph = render_app.world_mut().resource_mut::<RenderGraph>();
render_graph.add_node(BevyAtmosphereLabel, AtmosphereNode::default());
render_graph.add_node_edge(BevyAtmosphereLabel, CameraDriverLabel);
}
Expand Down Expand Up @@ -326,7 +324,7 @@ pub const ATMOSPHERE_IMAGE_TEXTURE_DESCRIPTOR: fn(u32) -> TextureDescriptor<'sta
fn prepare_atmosphere_resources(
mut update_events: ResMut<Events<AtmosphereUpdateEvent>>,
mut atmosphere_image: ResMut<AtmosphereImage>,
gpu_images: Res<RenderAssets<Image>>,
gpu_images: Res<RenderAssets<GpuImage>>,
atmosphere: Res<AtmosphereModel>,
) {
let mut update = || update_events.send(AtmosphereUpdateEvent);
Expand Down Expand Up @@ -359,7 +357,7 @@ fn prepare_atmosphere_resources(
fn prepare_atmosphere_bind_group(
mut commands: Commands,
mut cached_metadata: ResMut<CachedAtmosphereModelMetadata>,
gpu_images: Res<RenderAssets<Image>>,
gpu_images: Res<RenderAssets<GpuImage>>,
atmosphere_image: Res<AtmosphereImage>,
render_device: Res<RenderDevice>,
fallback_image: Res<FallbackImage>,
Expand Down
Loading

0 comments on commit fd3d2dc

Please sign in to comment.