diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 654533f..338329c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,6 @@ jobs: - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - name: Cache uses: Swatinem/rust-cache@v2 @@ -34,8 +32,6 @@ jobs: - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - name: Cache uses: Swatinem/rust-cache@v2 diff --git a/Cargo.toml b/Cargo.toml index 8439dd1..336003f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,22 +7,22 @@ keywords = ["gamedev", "bevy", "noise", "pcg", "simplex_noise"] license = "MIT" name = "noisy_bevy" repository = "https://github.com/johanhelsing/noisy_bevy" -version = "0.4.0" +version = "0.5.0" [dependencies] -bevy = { version = "0.11", features = ["bevy_asset", "bevy_render"], default-features = false } +bevy = { version = "0.12", default-features = false, features = [ + "bevy_asset", + "bevy_render" + ] } [dev-dependencies] -bevy = { version = "0.11", default-features = false, features = [ - "bevy_render", +bevy = { version = "0.12", default-features = false, features = [ "bevy_sprite", - "bevy_asset", "bevy_winit", - "filesystem_watcher", "x11", # github actions runners don't have libxkbcommon installed, so can't use wayland ] } rand = "0.8" -bevy_egui = {version = "0.21.0", default-features = false, features = ["default_fonts"]} +bevy_egui = { version = "0.23", default-features = false, features = ["default_fonts"] } # bevy-inspector-egui = {version = "0.19.1", default-features = false} -bevy_pancam = {version = "0.9", features = ["bevy_egui"] } +bevy_pancam = { version = "0.10", features = ["bevy_egui"] } insta = "1.21" \ No newline at end of file diff --git a/README.md b/README.md index dcb2397..7191cde 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,8 @@ The `main` branch targets the latest bevy release. |bevy|noisy_bevy| |----|----------| -|0.11| 0.4, main| +|0.12| 0.5, main| +|0.11| 0.4 | |0.10| 0.3 | |0.9 | 0.2 | |0.8 | 0.1 | diff --git a/assets/examples/asteroid_background.wgsl b/assets/examples/asteroid_background.wgsl index 0767559..7ce6fb4 100644 --- a/assets/examples/asteroid_background.wgsl +++ b/assets/examples/asteroid_background.wgsl @@ -1,20 +1,41 @@ -#import noisy_bevy fbm_simplex_2d_seeded -#import bevy_sprite::mesh2d_bindings mesh -#import bevy_sprite::mesh2d_vertex_output MeshVertexOutput +#import noisy_bevy::fbm_simplex_2d_seeded +#import bevy_sprite::mesh2d_functions::{ + get_model_matrix, + mesh2d_position_local_to_clip, +} struct AsteroidMaterial { params: vec4 } -@group(1) @binding(0) -var material: AsteroidMaterial; +@group(1) @binding(0) var material: AsteroidMaterial; + +struct Vertex { + @builtin(instance_index) instance_index: u32, + @location(0) position: vec3, + @location(1) blend_color: vec4, +}; + +struct VertexOutput { + @builtin(position) clip_position: vec4, + @location(0) object_position: vec2, +}; + +@vertex +fn vertex(vertex: Vertex) -> VertexOutput { + var out: VertexOutput; + // Project the world position of the mesh into screen position + let model = get_model_matrix(vertex.instance_index); + out.clip_position = mesh2d_position_local_to_clip(model, vec4(vertex.position, 1.0)); + out.object_position = vertex.position.xy; + return out; +} @fragment fn fragment( - vertex_output: MeshVertexOutput, + vertex_output: VertexOutput, ) -> @location(0) vec4 { - // perf: better to do in vertex shader! - var p = vertex_output.world_position.xy - vec2(mesh.model[3].x, mesh.model[3].y); // ignoring rotation + var p = vertex_output.object_position; let params = material.params; let freq_scale = params.x; let amp_scale = params.y; diff --git a/examples/asteroids.rs b/examples/asteroids.rs index 6a2a308..f298891 100644 --- a/examples/asteroids.rs +++ b/examples/asteroids.rs @@ -1,10 +1,6 @@ -use std::time::Duration; - use bevy::{ - asset::ChangeWatcher, math::{vec2, vec4}, prelude::*, - reflect::{TypePath, TypeUuid}, render::{camera::ScalingMode, render_resource::AsBindGroup}, sprite::{Material2d, Material2dPlugin, MaterialMesh2dBundle}, }; @@ -17,10 +13,7 @@ fn main() { .register_type::() .insert_resource(ClearColor(Color::BLACK)) .add_plugins(( - DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), - ..default() - }), + DefaultPlugins, NoisyShaderPlugin, PanCamPlugin::default(), Material2dPlugin::::default(), @@ -40,14 +33,16 @@ fn setup(mut commands: Commands) { commands.spawn(AsteroidBundle::default()); } -#[derive(AsBindGroup, TypeUuid, Clone, TypePath)] -#[uuid = "1e449d2e-6901-4bff-95fa-d7407ad62b58"] +#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)] struct AsteroidBackgroundMaterial { #[uniform(0)] params: Vec4, } impl Material2d for AsteroidBackgroundMaterial { + fn vertex_shader() -> bevy::render::render_resource::ShaderRef { + "examples/asteroid_background.wgsl".into() + } fn fragment_shader() -> bevy::render::render_resource::ShaderRef { "examples/asteroid_background.wgsl".into() } @@ -79,7 +74,8 @@ struct AsteroidBundle { transform: Transform, global_transform: GlobalTransform, visibility: Visibility, - computed_visibility: ComputedVisibility, + view_visibility: ViewVisibility, + inherited_visibility: InheritedVisibility, params: AsteroidParams, } @@ -90,8 +86,9 @@ impl Default for AsteroidBundle { transform: default(), global_transform: default(), visibility: default(), - computed_visibility: default(), params: default(), + view_visibility: default(), + inherited_visibility: default(), } } } diff --git a/src/lib.rs b/src/lib.rs index aa0d250..6907b4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ #![doc = include_str!("../README.md")] use bevy::{ - asset::HandleId, + asset::load_internal_asset, math::{vec2, vec3, vec4, Vec2Swizzles, Vec3Swizzles, Vec4Swizzles}, prelude::*, }; @@ -18,18 +18,18 @@ pub struct NoisyShaderPlugin; impl Plugin for NoisyShaderPlugin { fn build(&self, app: &mut App) { - app.add_systems(Startup, load_shaders); + // workaround: embedded_asset is broken in bevy 0.12.0 + load_internal_asset!( + app, + NOISY_SHADER_HANDLE, + "../assets/noisy_bevy.wgsl", + Shader::from_wgsl + ); } } -fn load_shaders(mut shaders: ResMut>) { - let shader = Shader::from_wgsl( - include_str!("../assets/noisy_bevy.wgsl",), - "noisy_bevy.wgsl", - ); - let handle_id = HandleId::random::(); - shaders.set_untracked(handle_id, shader); -} +const NOISY_SHADER_HANDLE: Handle = + Handle::weak_from_u128(224136012015454690045205738992444526155); fn permute_3(x: Vec3) -> Vec3 { (((x * 34.) + 1.) * x) % Vec3::splat(289.)