From c06faedeb3d982e5fae5a4217ecabe25b99b3249 Mon Sep 17 00:00:00 2001 From: James Gayfer <10660608+jgayfer@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:56:51 -0700 Subject: [PATCH] Upgrade to Bevy 0.14 (#9) * Upgrade to Bevy 0.14.0-rc.2 Brings us up to date with the "first" release candidate for 0.14. The only breaking change is that our PointLight2d API is affected by the migration from `LegacyColor` to `bevy_color::Color`. https://bevyengine.org/learn/migration-guides/0-13-to-0-14/#migrate-from-legacycolor-to-bevy-color-color * Cut release candidate for 0.2.0-rc.1 Our first release candiate for 0.2.0, featuring support for Bevy 0.14. * Update CHANGELOG.md New Bevy version! * Add link to Bevy color migration guide * Update README.md versions * Add note about extraneous features * Update to bevy 0.14.0-rc.3 * Bump version to 0.2.0-rc.2 Mirrors bevy 0.14.0-rc.3 * Bump bevy to 0.14.0-rc.4 * Bump version to 0.2.0-rc.3 Release for bevy 0.14.0-rc.4 * Include x11 This is needed to build the library on Linux. * Remove invalid category Crates.io was throwing a 400 (where it previously only warned). * Upgrade to Bevy 0.14 * Bump version * Update changelog --- CHANGELOG.md | 4 ++++ Cargo.toml | 12 ++++++---- README.md | 9 ++++---- examples/basic.rs | 2 +- examples/dungeon.rs | 38 ++++++++++++++++--------------- examples/multiple.rs | 6 ++--- src/light.rs | 6 ++--- src/plugin.rs | 13 +++++++---- src/render/extract.rs | 10 ++++---- src/render/lighting/lighting.wgsl | 6 ++--- src/render/lighting/node.rs | 2 +- 11 files changed, 60 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38668cd..6c2f659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.0] - 2024-07-04 + ### Added - WebGL2 support (#7). ### Changed +- Updated Bevy version from `0.13` to `0.14` (#9). +- Updated `PointLight2d#color` to use the new [`bevy::color`](https://bevyengine.org/learn/migration-guides/0-13-to-0-14/#overhaul-color) module (#9). - Moved `bevy_sprite`, `png`, and `x11` Bevy features to `dev-dependencies` (#12). ### Fixed diff --git a/Cargo.toml b/Cargo.toml index cac501f..faa71c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "bevy_light_2d" -version = "0.1.3" +version = "0.2.0" edition = "2021" -categories = ["game-engines", "graphics", "rendering", "gamedev"] +categories = ["game-engines", "graphics", "rendering"] description = "General purpose 2d lighting for the Bevy game engine." authors = ["James Gayfer"] repository = "https://github.com/jgayfer/bevy_light_2d" @@ -11,14 +11,16 @@ readme = "README.md" exclude = ["assets/*", "static/*"] [dependencies] -bevy = { version = "0.13", default-features = false, features = [ +bevy = { version = "0.14", default-features = false, features = [ "bevy_render", "bevy_core_pipeline", - "bevy_winit" + "bevy_winit", + "x11" ] } +smallvec = "1.13" [dev-dependencies] -bevy = { version = "0.13", default-features = false, features = [ +bevy = { version = "0.14", default-features = false, features = [ "bevy_render", "bevy_core_pipeline", "bevy_winit", diff --git a/README.md b/README.md index c591b2b..204a9b0 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Designed to be simple to use, yet expressive enough to fit a variety of needs. ## Features - Component driven design -- Configurable [point lights](https://docs.rs/bevy_light_2d/0.1.0/bevy_light_2d/light/struct.PointLight2d.html) -- Camera specific [ambient light](https://docs.rs/bevy_light_2d/0.1.0/bevy_light_2d/light/struct.AmbientLight2d.html) +- Configurable [point lights](https://docs.rs/bevy_light_2d/0.2.0/bevy_light_2d/light/struct.PointLight2d.html) +- Camera specific [ambient light](https://docs.rs/bevy_light_2d/0.2.0/bevy_light_2d/light/struct.AmbientLight2d.html) - Single camera rendering ## Usage @@ -26,8 +26,8 @@ In the [`basic`](https://github.com/jgayfer/bevy_light_2d/blob/main/examples/bas ```toml # Cargo.toml [dependencies] -bevy = "0.13" -bevy_light_2d = "0.1" +bevy = "0.14" +bevy_light_2d = "0.2" ``` ```rust @@ -80,6 +80,7 @@ general application over depth of features. | bevy | bevy_light_2d | |------|---------------| +| 0.14 | 0.2 | | 0.13 | 0.1 | ## Acknowledgements diff --git a/examples/basic.rs b/examples/basic.rs index c4bfad9..1829db6 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -5,7 +5,7 @@ fn main() { App::new() .add_plugins((DefaultPlugins, Light2dPlugin)) .add_systems(Startup, setup) - .run() + .run(); } fn setup(mut commands: Commands) { diff --git a/examples/dungeon.rs b/examples/dungeon.rs index 0d92793..817b643 100644 --- a/examples/dungeon.rs +++ b/examples/dungeon.rs @@ -1,4 +1,4 @@ -use bevy::prelude::*; +use bevy::{color::palettes::css::YELLOW, prelude::*}; use bevy_light_2d::prelude::*; const TILE_INDEX: f32 = 0.0; @@ -16,7 +16,7 @@ fn main() { .add_systems(Startup, (setup_dungeon_tileset, spawn_tiles).chain()) .add_systems(Startup, (setup_candle_spritesheet, spawn_candles).chain()) .add_systems(Update, animate_candles) - .run() + .run(); } #[derive(Resource, Default)] @@ -50,7 +50,7 @@ fn setup_camera(mut commands: Commands) { } fn set_clear_color(mut clear_color: ResMut) { - clear_color.0 = Color::rgb_u8(37, 19, 26); + clear_color.0 = Color::srgb_u8(37, 19, 26); } fn animate_candles( @@ -71,7 +71,7 @@ fn spawn_candles(mut commands: Commands, spritesheet: Res) { transform: Transform::from_xyz(0.0, 4.0, ENTITY_INDEX), point_light: PointLight2d { radius: 48.0, - color: Color::YELLOW, + color: Color::Srgba(YELLOW), intensity: 25.0, falloff: 4.0, }, @@ -83,13 +83,13 @@ fn spawn_candles(mut commands: Commands, spritesheet: Res) { .spawn(( Candle, AnimationTimer(Timer::from_seconds(0.2, TimerMode::Repeating)), - SpriteSheetBundle { + SpriteBundle { transform: Transform::from_xyz(0., 2., ENTITY_INDEX), texture: spritesheet.texture.clone(), - atlas: TextureAtlas { - layout: spritesheet.layout.clone(), - ..default() - }, + ..default() + }, + TextureAtlas { + layout: spritesheet.layout.clone(), ..default() }, )) @@ -164,18 +164,20 @@ fn spawn_from_atlas( atlas_handle: Handle, texture: Handle, ) { - commands.spawn(SpriteSheetBundle { - transform: Transform { - translation, + commands.spawn(( + SpriteBundle { + transform: Transform { + translation, + ..default() + }, + texture, ..default() }, - texture, - atlas: TextureAtlas { + TextureAtlas { index: sprite_index, layout: atlas_handle, }, - ..default() - }); + )); } fn setup_dungeon_tileset( @@ -185,7 +187,7 @@ fn setup_dungeon_tileset( ) { dungeon_tileset.texture = asset_server.load("dungeon_tiles.png"); dungeon_tileset.layout = texture_atlas_layouts.add(TextureAtlasLayout::from_grid( - Vec2::new(16.0, 16.0), + UVec2::new(16, 16), 10, 10, None, @@ -200,7 +202,7 @@ fn setup_candle_spritesheet( ) { candle_spritesheet.texture = asset_server.load("candle.png"); candle_spritesheet.layout = texture_atlas_layouts.add(TextureAtlasLayout::from_grid( - Vec2::new(16.0, 16.0), + UVec2::new(16, 16), 4, 1, None, diff --git a/examples/multiple.rs b/examples/multiple.rs index d081420..1abb906 100644 --- a/examples/multiple.rs +++ b/examples/multiple.rs @@ -5,7 +5,7 @@ fn main() { App::new() .add_plugins((DefaultPlugins, Light2dPlugin)) .add_systems(Startup, setup) - .run() + .run(); } fn setup(mut commands: Commands) { @@ -28,7 +28,7 @@ fn setup(mut commands: Commands) { commands.spawn(PointLight2dBundle { point_light: PointLight2d { - color: Color::RED, + color: Color::Srgba(Srgba::RED), radius: 50., intensity: 5.0, ..default() @@ -50,7 +50,7 @@ fn setup(mut commands: Commands) { commands.spawn(PointLight2dBundle { point_light: PointLight2d { - color: Color::GREEN, + color: Color::Srgba(Srgba::GREEN), radius: 75., intensity: 5.0, ..default() diff --git a/src/light.rs b/src/light.rs index 608f241..e7b3dfd 100644 --- a/src/light.rs +++ b/src/light.rs @@ -1,12 +1,10 @@ //! A module which contains lighting components. use bevy::{ + color::Color, ecs::{bundle::Bundle, component::Component}, reflect::Reflect, - render::{ - color::Color, - view::{InheritedVisibility, ViewVisibility, Visibility}, - }, + render::view::{InheritedVisibility, ViewVisibility, Visibility}, transform::components::{GlobalTransform, Transform}, }; diff --git a/src/plugin.rs b/src/plugin.rs index f830dc5..d7fe516 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -9,6 +9,7 @@ use bevy::{ gpu_component_array_buffer::GpuComponentArrayBufferPlugin, render_graph::{RenderGraphApp, ViewNodeRunner}, render_resource::SpecializedRenderPipelines, + view::{check_visibility, VisibilitySystems}, Render, RenderApp, RenderSet, }, }; @@ -44,9 +45,13 @@ impl Plugin for Light2dPlugin { GpuComponentArrayBufferPlugin::::default(), )) .register_type::() - .register_type::(); + .register_type::() + .add_systems( + PostUpdate, + check_visibility::>.in_set(VisibilitySystems::CheckVisibility), + ); - let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; @@ -61,11 +66,11 @@ impl Plugin for Light2dPlugin { prepare_lighting_pipelines.in_set(RenderSet::Prepare), ) .add_render_graph_node::>(Core2d, LightingPass) - .add_render_graph_edge(Core2d, Node2d::MainPass, LightingPass); + .add_render_graph_edge(Core2d, Node2d::EndMainPass, LightingPass); } fn finish(&self, app: &mut App) { - let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; diff --git a/src/render/extract.rs b/src/render/extract.rs index eb79abc..86538d3 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -9,14 +9,14 @@ use crate::light::{AmbientLight2d, PointLight2d}; pub struct ExtractedPointLight2d { pub transform: Vec2, pub radius: f32, - pub color: Vec4, + pub color: LinearRgba, pub intensity: f32, pub falloff: f32, } #[derive(Component, Default, Clone, ShaderType)] pub struct ExtractedAmbientLight2d { - pub color: Vec4, + pub color: LinearRgba, } pub fn extract_point_lights( @@ -28,7 +28,7 @@ pub fn extract_point_lights( continue; } commands.get_or_spawn(entity).insert(ExtractedPointLight2d { - color: point_light.color.rgba_linear_to_vec4(), + color: point_light.color.to_linear(), transform: global_transform.translation().xy(), radius: point_light.radius, intensity: point_light.intensity, @@ -46,7 +46,7 @@ pub fn extract_ambient_lights( commands .get_or_spawn(entity) .insert(ExtractedAmbientLight2d { - color: ambient_light.color.rgba_linear_to_vec4() * ambient_light.brightness, + color: ambient_light.color.to_linear() * ambient_light.brightness, }); } @@ -56,7 +56,7 @@ pub fn extract_ambient_lights( commands .get_or_spawn(entity) .insert(ExtractedAmbientLight2d { - color: Vec4::new(1.0, 1.0, 1.0, 0.0), + color: Color::WHITE.into(), }); } } diff --git a/src/render/lighting/lighting.wgsl b/src/render/lighting/lighting.wgsl index fb76010..826a2a6 100644 --- a/src/render/lighting/lighting.wgsl +++ b/src/render/lighting/lighting.wgsl @@ -15,7 +15,7 @@ struct PointLight2d { } struct AmbientLight2d { - color: vec3 + color: vec4 } fn world_to_ndc(world_position: vec2, view_projection: mat4x4) -> vec2 { @@ -37,7 +37,7 @@ fn world_to_screen( fn scale_factor(view: View) -> f32 { let screen_size = - 2.0 * vec2f(view.inverse_projection[0][0], view.inverse_projection[1][1]); + 2.0 * vec2f(view.view_from_clip[0][0], view.view_from_clip[1][1]); return screen_size.y / view.viewport.w; } @@ -85,7 +85,7 @@ fn fragment(vo: FullscreenVertexOutput) -> @location(0) vec4 { // it to screen space in order to do things like compute distances (let // alone render it in the correct place). let point_light_screen_center = - world_to_screen(point_light.center, view.viewport.zw, view.view_proj); + world_to_screen(point_light.center, view.viewport.zw, view.clip_from_world); // Compute the distance between the current position and the light's center. // We multiply by the scale factor as otherwise our distance will always be diff --git a/src/render/lighting/node.rs b/src/render/lighting/node.rs index 35a5a3b..6a11303 100644 --- a/src/render/lighting/node.rs +++ b/src/render/lighting/node.rs @@ -8,7 +8,7 @@ use bevy::render::render_resource::{ }; use bevy::render::renderer::RenderDevice; use bevy::render::view::{ViewTarget, ViewUniformOffset, ViewUniforms}; -use bevy::utils::smallvec::{smallvec, SmallVec}; +use smallvec::{smallvec, SmallVec}; use crate::render::extract::{ExtractedAmbientLight2d, ExtractedPointLight2d};