Skip to content

Commit

Permalink
update for bevy 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
sphw committed Nov 6, 2023
1 parent 5c69170 commit e469e29
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]
Expand Down
15 changes: 5 additions & 10 deletions macros/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {
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<Shader> = #asset_path::Handle::weak_from_u128(#id as u128);

let internal_handle = handle.clone();
#asset_path::load_internal_asset!(
Expand All @@ -153,7 +153,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {
Shader::from_wgsl
);

handle.typed()
handle
}
},
};
Expand Down Expand Up @@ -423,14 +423,9 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result<TokenStream> {
) -> #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
}

Expand Down
31 changes: 14 additions & 17 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -142,8 +142,8 @@ impl Plugin for AtmospherePipelinePlugin {
.add_systems(
Render,
(
Events::<AtmosphereUpdateEvent>::update_system.in_set(RenderSet::Prepare),
prepare_atmosphere_assets.in_set(PrepareAssetSet::PostAssetPrepare),
//Events::<AtmosphereUpdateEvent>::update_system.in_set(RenderSet::Prepare),
prepare_atmosphere_assets.in_set(RenderSet::PrepareAssets),
queue_atmosphere_bind_group.in_set(RenderSet::Queue),
),
);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn atmosphere_remove(
atmosphere_skyboxes: Query<Entity, With<AtmosphereSkyBox>>,
mut atmosphere_cameras: RemovedComponents<AtmosphereCamera>,
) {
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/gradient.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ struct Gradient {
}

fn render_gradient(r: vec3<f32>, g: Gradient) -> vec3<f32> {
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);
Expand Down
6 changes: 3 additions & 3 deletions src/shaders/nishita.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ fn rsi(rd: vec3<f32>, r0: vec3<f32>, sr: f32) -> vec2<f32> {
}
}

fn render_nishita(r: vec3<f32>, r0: vec3<f32>, p_sun: vec3<f32>, i_sun: f32, r_planet: f32, r_atmos: f32, k_rlh: vec3<f32>, k_mie: f32, sh_rlh: f32, sh_mie: f32, g: f32) -> vec3<f32> {
fn render_nishita(r_full: vec3<f32>, r0: vec3<f32>, p_sun_full: vec3<f32>, i_sun: f32, r_planet: f32, r_atmos: f32, k_rlh: vec3<f32>, k_mie: f32, sh_rlh: f32, sh_mie: f32, g: f32) -> vec3<f32> {
// 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);
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/skybox.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn dither(frag_coord: vec2<f32>) -> vec3<f32> {
}
#endif

#import bevy_pbr::mesh_vertex_output MeshVertexOutput
#import bevy_pbr::forward_io::VertexOutput

@group(1) @binding(0)
var sky_texture: texture_cube<f32>;
Expand All @@ -19,7 +19,7 @@ var sky_sampler: sampler;

@fragment
fn fragment(
in: MeshVertexOutput
in: VertexOutput
) -> @location(0) vec4<f32> {
let color = textureSample(sky_texture, sky_sampler, in.world_normal).xyz;
#ifdef DITHER
Expand Down
8 changes: 4 additions & 4 deletions src/skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use bevy::{
pub struct AtmosphereSkyBoxMaterial(pub Handle<SkyBoxMaterial>);

/// 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<Shader> =
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 {
Expand All @@ -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(
Expand Down

0 comments on commit e469e29

Please sign in to comment.