From e469e29848d624dd54fee4c6ecc860fa1171033a Mon Sep 17 00:00:00 2001 From: Sascha Wise Date: Mon, 6 Nov 2023 13:50:58 -0800 Subject: [PATCH] update for bevy 0.12 --- Cargo.toml | 4 ++-- macros/src/model.rs | 15 +++++---------- src/pipeline.rs | 31 ++++++++++++++----------------- src/plugin.rs | 2 +- src/shaders/gradient.wgsl | 4 ++-- src/shaders/nishita.wgsl | 6 +++--- src/shaders/skybox.wgsl | 4 ++-- src/skybox.rs | 8 ++++---- 8 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7fb571..a8b041f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/JonahPlusPlus/bevy_atmosphere" exclude = ["/assets/", "/examples/", "/.github/"] [dependencies] -bevy = { version = "0.11", default-features = false, features = [ +bevy = { version = "0.12", default-features = false, features = [ "bevy_asset", "bevy_render", "bevy_pbr", @@ -21,7 +21,7 @@ cfg-if = "1.0" [dev-dependencies] bevy_spectator = "0.3" -bevy = { version = "0.11", features = ["bevy_core_pipeline", "x11"] } +bevy = { version = "0.12", features = ["bevy_core_pipeline", "x11"] } [features] default = ["basic", "all_models"] diff --git a/macros/src/model.rs b/macros/src/model.rs index 5a2eb82..2f6a46f 100644 --- a/macros/src/model.rs +++ b/macros/src/model.rs @@ -143,7 +143,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { ShaderPathType::Internal(s) => quote! { { use bevy::reflect::TypeUuid; - let handle = #asset_path::HandleUntyped::weak_from_u64(#render_path::render_resource::Shader::TYPE_UUID, #id); + let handle: #asset_path::Handle = #asset_path::Handle::weak_from_u128(#id as u128); let internal_handle = handle.clone(); #asset_path::load_internal_asset!( @@ -153,7 +153,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { Shader::from_wgsl ); - handle.typed() + handle } }, }; @@ -423,14 +423,9 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { ) -> #render_path::render_resource::BindGroup { let bindings = vec![#(#binding_impls,)*]; - let bind_group = { - let descriptor = #render_path::render_resource::BindGroupDescriptor { - entries: &[#(#bind_group_entries,)*], - label: None, - layout: &layout, - }; - render_device.create_bind_group(&descriptor) - }; + let bind_group = + render_device.create_bind_group( + None, &layout, &[#(#bind_group_entries,)*]); bind_group } diff --git a/src/pipeline.rs b/src/pipeline.rs index fd204f4..f223051 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -8,14 +8,14 @@ use bevy::{ prelude::*, render::{ extract_resource::{ExtractResource, ExtractResourcePlugin}, - render_asset::{PrepareAssetSet, RenderAssets}, + render_asset::RenderAssets, render_graph::{self, RenderGraph}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, - BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, - CachedPipelineState, ComputePassDescriptor, Extent3d, PipelineCache, ShaderStages, - StorageTextureAccess, TextureAspect, TextureDescriptor, TextureDimension, - TextureFormat, TextureUsages, TextureView, TextureViewDescriptor, TextureViewDimension, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroupLayoutEntry, BindingResource, BindingType, CachedPipelineState, + ComputePassDescriptor, Extent3d, PipelineCache, ShaderStages, StorageTextureAccess, + TextureAspect, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, + TextureView, TextureViewDescriptor, TextureViewDimension, }, renderer::RenderDevice, texture::FallbackImage, @@ -142,8 +142,8 @@ impl Plugin for AtmospherePipelinePlugin { .add_systems( Render, ( - Events::::update_system.in_set(RenderSet::Prepare), - prepare_atmosphere_assets.in_set(PrepareAssetSet::PostAssetPrepare), + //Events::::update_system.in_set(RenderSet::Prepare), + prepare_atmosphere_assets.in_set(RenderSet::PrepareAssets), queue_atmosphere_bind_group.in_set(RenderSet::Queue), ), ); @@ -336,7 +336,7 @@ fn prepare_atmosphere_assets( name = "bevy_atmosphere::pipeline::prepare_atmosphere_assets" ) .entered(); - let texture = &gpu_images[&atmosphere_image.handle].texture; + let texture = &gpu_images.get(&atmosphere_image.handle).unwrap().texture; let view = texture.create_view(&ATMOSPHERE_ARRAY_TEXTURE_VIEW_DESCRIPTOR); atmosphere_image.array_view = Some(view); update(); @@ -394,14 +394,11 @@ fn queue_atmosphere_bind_group( &fallback_image, ); - let image_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: Some("bevy_atmosphere_image_bind_group"), - layout: &image_bind_group_layout.0, - entries: &[BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(view), - }], - }); + let image_bind_group = render_device.create_bind_group( + "bevy_atmosphere_image_bind_group", + &image_bind_group_layout.0, + &BindGroupEntries::sequential((BindingResource::TextureView(view),)), + ); commands.insert_resource(AtmosphereBindGroups( atmosphere_bind_group, diff --git a/src/plugin.rs b/src/plugin.rs index 3c62ac1..ce2ff72 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -143,7 +143,7 @@ fn atmosphere_remove( atmosphere_skyboxes: Query>, mut atmosphere_cameras: RemovedComponents, ) { - for camera in &mut atmosphere_cameras { + for camera in &mut atmosphere_cameras.read() { #[cfg(feature = "bevy/trace")] trace!("Removing skybox from camera entity (ID:{:?})", camera); let Ok(children) = parents.get(camera) else { diff --git a/src/shaders/gradient.wgsl b/src/shaders/gradient.wgsl index 32208ac..a7e6dbf 100644 --- a/src/shaders/gradient.wgsl +++ b/src/shaders/gradient.wgsl @@ -6,8 +6,8 @@ struct Gradient { } fn render_gradient(r: vec3, g: Gradient) -> vec3 { - let r = normalize(r); - let y = r.y; + let r_norm = normalize(r); + let y = r_norm.y; let p_sky = max(y, 0f); let p_horizon = 1f-abs(y); diff --git a/src/shaders/nishita.wgsl b/src/shaders/nishita.wgsl index 216668a..86b8494 100644 --- a/src/shaders/nishita.wgsl +++ b/src/shaders/nishita.wgsl @@ -35,10 +35,10 @@ fn rsi(rd: vec3, r0: vec3, sr: f32) -> vec2 { } } -fn render_nishita(r: vec3, r0: vec3, p_sun: vec3, i_sun: f32, r_planet: f32, r_atmos: f32, k_rlh: vec3, k_mie: f32, sh_rlh: f32, sh_mie: f32, g: f32) -> vec3 { +fn render_nishita(r_full: vec3, r0: vec3, p_sun_full: vec3, i_sun: f32, r_planet: f32, r_atmos: f32, k_rlh: vec3, k_mie: f32, sh_rlh: f32, sh_mie: f32, g: f32) -> vec3 { // Normalize the ray direction and sun position. - let r = normalize(r); - let p_sun = normalize(p_sun); + let r = normalize(r_full); + let p_sun = normalize(p_sun_full); // Calculate the step size of the primary ray. var p = rsi(r, r0, r_atmos); diff --git a/src/shaders/skybox.wgsl b/src/shaders/skybox.wgsl index 458a5a3..28c689a 100644 --- a/src/shaders/skybox.wgsl +++ b/src/shaders/skybox.wgsl @@ -10,7 +10,7 @@ fn dither(frag_coord: vec2) -> vec3 { } #endif -#import bevy_pbr::mesh_vertex_output MeshVertexOutput +#import bevy_pbr::forward_io::VertexOutput @group(1) @binding(0) var sky_texture: texture_cube; @@ -19,7 +19,7 @@ var sky_sampler: sampler; @fragment fn fragment( - in: MeshVertexOutput + in: VertexOutput ) -> @location(0) vec4 { let color = textureSample(sky_texture, sky_sampler, in.world_normal).xyz; #ifdef DITHER diff --git a/src/skybox.rs b/src/skybox.rs index 179d00c..bd7e503 100644 --- a/src/skybox.rs +++ b/src/skybox.rs @@ -15,11 +15,11 @@ use bevy::{ pub struct AtmosphereSkyBoxMaterial(pub Handle); /// The `Handle` for the shader for the [`SkyBoxMaterial`]. -pub const ATMOSPHERE_SKYBOX_SHADER_HANDLE: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 4511926918914205353); +pub const ATMOSPHERE_SKYBOX_SHADER_HANDLE: Handle = + Handle::weak_from_u128(4511926918914205353); /// The `Material` that renders skyboxes. -#[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone)] +#[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone, Asset)] #[uuid = "b460ff90-0ee4-42df-875f-0a62ecd1301c"] #[bind_group_data(SkyBoxMaterialKey)] pub struct SkyBoxMaterial { @@ -40,7 +40,7 @@ pub struct SkyBoxMaterialKey { impl Material for SkyBoxMaterial { fn fragment_shader() -> ShaderRef { - ATMOSPHERE_SKYBOX_SHADER_HANDLE.typed().into() + ATMOSPHERE_SKYBOX_SHADER_HANDLE.into() } fn specialize(