Skip to content

Commit

Permalink
WIP: Bevy 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
jgayfer committed May 29, 2024
1 parent 7901e49 commit 2a7b1e3
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ readme = "README.md"
exclude = ["assets/*", "static/*"]

[dependencies]
bevy = { version = "0.13", default-features = false, features = [
bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", default-features = false, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
"bevy_sprite",
"bevy_pbr",
"png",
"x11"
] }
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
App::new()
.add_plugins((DefaultPlugins, Light2dPlugin))
.add_systems(Startup, setup)
.run()
.run();
}

fn setup(mut commands: Commands) {
Expand Down
10 changes: 5 additions & 5 deletions examples/dungeon.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -71,7 +71,7 @@ fn spawn_candles(mut commands: Commands, spritesheet: Res<CandleSpritesheet>) {
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,
},
Expand Down Expand Up @@ -185,7 +185,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,
Expand All @@ -200,7 +200,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,
Expand Down
6 changes: 3 additions & 3 deletions examples/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
App::new()
.add_plugins((DefaultPlugins, Light2dPlugin))
.add_systems(Startup, setup)
.run()
.run();
}

fn setup(mut commands: Commands) {
Expand All @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions src/light.rs
Original file line number Diff line number Diff line change
@@ -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},
};

Expand Down
13 changes: 9 additions & 4 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bevy::{
render::{
extract_component::UniformComponentPlugin,
render_graph::{RenderGraphApp, ViewNodeRunner},
view::{check_visibility, VisibilitySystems},
Render, RenderApp, RenderSet,
},
};
Expand Down Expand Up @@ -34,9 +35,13 @@ impl Plugin for Light2dPlugin {

app.add_plugins(UniformComponentPlugin::<ExtractedAmbientLight2d>::default())
.register_type::<AmbientLight2d>()
.register_type::<PointLight2d>();
.register_type::<PointLight2d>()
.add_systems(
PostUpdate,
check_visibility::<With<PointLight2d>>.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;
};

Expand All @@ -47,11 +52,11 @@ impl Plugin for Light2dPlugin {
)
.add_systems(Render, (prepare_point_lights).in_set(RenderSet::Prepare))
.add_render_graph_node::<ViewNodeRunner<LightingNode>>(Core2d, LightingPass)
.add_render_graph_edge(Core2d, Node2d::MainPass, LightingPass);
.add_render_graph_edge(Core2d, Node2d::MainTransparentPass, 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;
};

Expand Down
12 changes: 6 additions & 6 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bevy::{
color::{Color, LinearRgba},
core_pipeline::core_2d::Camera2d,
ecs::{
component::Component,
entity::Entity,
query::{With, Without},
system::{Commands, Query},
},
math::Vec4,
render::{render_resource::ShaderType, view::ViewVisibility, Extract},
transform::components::GlobalTransform,
};
Expand All @@ -17,14 +17,14 @@ use crate::light::{AmbientLight2d, PointLight2d};
pub struct ExtractedPointLight2d {
pub transform: GlobalTransform,
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(
Expand All @@ -36,7 +36,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.linear(),
transform: *global_transform,
radius: point_light.radius,
intensity: point_light.intensity,
Expand All @@ -54,7 +54,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.linear() * ambient_light.brightness,
});
}

Expand All @@ -64,7 +64,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(),
});
}
}
2 changes: 1 addition & 1 deletion src/render/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct GpuPointLights {
pub struct GpuPointLight2d {
pub center: Vec2,
pub radius: f32,
pub color: Vec4,
pub color: LinearRgba,
pub intensity: f32,
pub falloff: f32,
}
Expand Down
2 changes: 1 addition & 1 deletion src/render/lighting/lighting.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct PointLight2d {
}

struct AmbientLight2d {
color: vec3<f32>
color: vec4<f32>
}

fn world_to_ndc(world_position: vec2<f32>, view_projection: mat4x4<f32>) -> vec2<f32> {
Expand Down

0 comments on commit 2a7b1e3

Please sign in to comment.