Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to bevy 0.14 #32

Merged
merged 12 commits into from
Aug 9, 2024
29 changes: 16 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,35 @@ keywords = ["gamedev", "bevy", "sdf"]
license = "MIT OR Apache-2.0"
name = "bevy_smud"
repository = "https://github.com/johanhelsing/bevy_smud"
version = "0.7.0"
version = "0.9.0"

[dependencies]
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset", # needed for handle ids
]}
bytemuck = { version = "1.7", features = ["derive"] }
"bevy_asset", # needed for handle ids
"multi_threaded",
] }
bytemuck = { version = "1.15.0", features = ["derive"] }
copyless = "0.1"
bitflags = "2.4"
fixedbitset = "0.4"
bitflags = "2.5"
fixedbitset = "0.5"
uuid = "1.10.0"

[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
"bevy_state",
"bevy_winit",
"x11", # github actions runners don't have libxkbcommon installed, so can't use wayland
"x11", # github actions runners don't have libxkbcommon installed, so can't use wayland
"file_watcher",
] }
bevy_asset_loader = "0.18"
bevy_lospec = "0.6"
bevy_pancam = "0.10"
bevy_asset_loader = "0.21"
bevy_lospec = "0.8"
bevy_pancam = "0.12"
rand = "0.8"

[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 3
opt-level = 3
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ The `main` branch targets the latest bevy release.

|bevy|bevy_smud|
|----|---------|
|0.12|0.7, main|
|0.14|0.9, main|
|0.12|0.7 |
|0.11|0.6 |
|0.10|0.5 |
|0.9 |0.4 |
Expand Down
5 changes: 3 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes::css;
use bevy::prelude::*;
// The prelude contains the basic things needed to create shapes
use bevy_smud::prelude::*;
Expand Down Expand Up @@ -39,7 +40,7 @@ return smud::sd_circle(p_2 - vec2<f32>(20., 0.), 40.);

commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::TOMATO,
color: css::TOMATO.into(),
sdf: circle,
// The frame needs to be bigger than the shape we're drawing
// Since the circle has radius 70, we make the half-size of the quad 80.
Expand All @@ -52,7 +53,7 @@ return smud::sd_circle(p_2 - vec2<f32>(20., 0.), 40.);
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::X * 200.),
shape: SmudShape {
color: Color::rgb(0.7, 0.6, 0.4),
color: Color::srgb(0.7, 0.6, 0.4),
sdf: peanut,
frame: Frame::Quad(80.),
..default()
Expand Down
21 changes: 12 additions & 9 deletions examples/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy::{
color::palettes::css,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
};
Expand All @@ -9,14 +10,6 @@ use rand::prelude::*;

fn main() {
App::new()
.add_state::<GameState>()
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.add_loading_state(
LoadingState::new(GameState::Loading).continue_to_state(GameState::Running),
)
.add_collection_to_loading_state::<_, AssetHandles>(GameState::Loading)
.add_plugins((
DefaultPlugins,
LogDiagnosticsPlugin::default(),
Expand All @@ -25,6 +18,15 @@ fn main() {
PanCamPlugin,
bevy_lospec::PalettePlugin,
))
.init_state::<GameState>()
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.add_loading_state(
LoadingState::new(GameState::Loading)
.continue_to_state(GameState::Running)
.load_collection::<AssetHandles>(),
)
.add_systems(OnEnter(GameState::Running), setup)
// .add_system_set(SystemSet::on_update(GameState::Running).with_system(update))
.run();
Expand All @@ -43,6 +45,7 @@ struct AssetHandles {
palette: Handle<bevy_lospec::Palette>,
}

#[allow(dead_code)]
#[derive(Component)]
struct Index(usize);

Expand Down Expand Up @@ -73,7 +76,7 @@ fn setup(
.filter(|c| *c != &clear_color)
.choose(&mut rng)
.copied()
.unwrap_or(Color::PINK);
.unwrap_or(css::PINK.into());

commands.spawn((
ShapeBundle {
Expand Down
4 changes: 2 additions & 2 deletions examples/bevy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.insert_resource(ClearColor(Color::srgb(0.7, 0.8, 0.7)))
.add_plugins((DefaultPlugins, SmudPlugin, PanCamPlugin))
.add_systems(Startup, setup)
.run();
Expand All @@ -18,7 +18,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::rgb(0.36, 0.41, 0.45),
color: Color::srgb(0.36, 0.41, 0.45),
sdf: bevy_shape_shader,
frame: Frame::Quad(400.),
..default()
Expand Down
3 changes: 2 additions & 1 deletion examples/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Note that you could probably achieve cheaper and higher quality bloom-like
//! effects by creating a custom fill.

use bevy::color::palettes::css;
use bevy::{core_pipeline::bloom::BloomSettings, prelude::*};
// The prelude contains the basic things needed to create shapes
use bevy_smud::prelude::*;
Expand All @@ -27,7 +28,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {

commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::TOMATO,
color: css::TOMATO.into(),
sdf: circle,
// The frame needs to be bigger than the shape we're drawing
// Since the circle has radius 70, we make the half-size of the quad 80.
Expand Down
7 changes: 4 additions & 3 deletions examples/custom_fill.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes::css;
use bevy::prelude::*;
use bevy_pancam::*;
use bevy_smud::{prelude::*, SIMPLE_FILL_HANDLE};
Expand All @@ -23,7 +24,7 @@ fn setup(

commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::TEAL,
color: css::TEAL.into(),
sdf: asset_server.load("bevy.wgsl"),
fill: sin_fill,
frame: Frame::Quad(295.),
Expand All @@ -34,7 +35,7 @@ fn setup(
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::X * 600.),
shape: SmudShape {
color: Color::BLUE,
color: css::BLUE.into(),
sdf: asset_server.load("bevy.wgsl"),
fill: SIMPLE_FILL_HANDLE,
frame: Frame::Quad(295.),
Expand All @@ -45,7 +46,7 @@ fn setup(
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::X * -600.),
shape: SmudShape {
color: Color::ORANGE,
color: css::ORANGE.into(),
sdf: asset_server.load("bevy.wgsl"),
fill: shaders.add_fill_body(
r"
Expand Down
19 changes: 11 additions & 8 deletions examples/gallery.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes::css;
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;
use bevy_pancam::*;
Expand All @@ -6,14 +7,8 @@ use rand::prelude::*;

fn main() {
App::new()
.add_state::<GameState>()
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.add_loading_state(
LoadingState::new(GameState::Loading).continue_to_state(GameState::Running),
)
.add_collection_to_loading_state::<_, AssetHandles>(GameState::Loading)
.add_plugins((
DefaultPlugins,
SmudPlugin,
Expand All @@ -22,6 +17,13 @@ fn main() {
PanCamPlugin,
bevy_lospec::PalettePlugin,
))
.init_state::<GameState>()
.insert_resource(Msaa::Off)
.add_loading_state(
LoadingState::new(GameState::Loading)
.continue_to_state(GameState::Running)
.load_collection::<AssetHandles>(),
)
.add_systems(OnEnter(GameState::Running), setup)
.run();
}
Expand All @@ -39,6 +41,7 @@ struct AssetHandles {
palette: Handle<bevy_lospec::Palette>,
}

#[allow(dead_code)]
#[derive(Component)]
struct Index(usize);

Expand Down Expand Up @@ -85,7 +88,7 @@ fn setup(
asset_server.load("gallery/donut.wgsl"),
];

let fills = vec![
let fills = [
// asset_server.load("fills/simple.wgsl"),
asset_server.load("fills/cubic_falloff.wgsl"),
asset_server.load("fills/outline.wgsl"),
Expand All @@ -98,7 +101,7 @@ fn setup(
.filter(|c| *c != &clear_color)
.choose(&mut rng)
.copied()
.unwrap_or(Color::PINK);
.unwrap_or(css::PINK.into());

let index = i + j * w;

Expand Down
60 changes: 60 additions & 0 deletions examples/oscilloscope.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use bevy::color::palettes::css;
use bevy::prelude::*;
use bevy_pancam::*;
use bevy_smud::{prelude::*, SIMPLE_FILL_HANDLE};

fn main() {
App::new()
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::BLACK))
.add_plugins((DefaultPlugins, SmudPlugin, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut shaders: ResMut<Assets<Shader>>,
) {
// The fill takes a distance and a color and returns another color
commands.spawn(ShapeBundle {
shape: SmudShape {
// color: css::GREEN.into(),
color: css::ORANGE.into(),
sdf: asset_server.load("bevy.wgsl"),
fill: shaders.add_fill_body(
r"
var col = color.rgb / sqrt(abs(d));
// col *= smoothstep(1.5, 0.5, length(p)); // We don't have p. This would give a vignette.

// This is a brighter effect.
return vec4<f32>(col, color.a);
// This is a darker effect.
// return vec4<f32>(aces_approx(col), color.a);
}

// HACK: We're gonna cheat on this template and add an auxiliary function.

// License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/
fn aces_approx(v_: vec3<f32>) -> vec3<f32> {
var v = max(v_, vec3<f32>(0.0));
v *= 0.6;
let a: f32 = 2.51;
let b: f32 = 0.03;
let c: f32 = 2.43;
let d: f32 = 0.59;
let e: f32 = 0.14;
return saturate((v * (a * v + b)) / (v * (c * v + d) + e));
",
),

frame: Frame::Quad(295.),
},
..default()
});

commands.spawn((Camera2dBundle::default(), PanCam::default()));
}
8 changes: 4 additions & 4 deletions examples/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.insert_resource(ClearColor(Color::srgb(0.7, 0.8, 0.7)))
.add_plugins((DefaultPlugins, SmudPlugin, PanCamPlugin))
.add_systems(Startup, setup)
.run();
Expand All @@ -18,7 +18,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::Z * 3.),
shape: SmudShape {
color: Color::rgb(0.0, 0.0, 0.0),
color: Color::srgb(0.0, 0.0, 0.0),
sdf: shaders.add_sdf_body("return smud::sd_circle(p, 70.);"),
frame: Frame::Quad(80.),
..default()
Expand All @@ -30,7 +30,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::Z * 2.),
shape: SmudShape {
color: Color::rgb(0.46, 0.42, 0.80),
color: Color::srgb(0.46, 0.42, 0.80),
sdf: shaders.add_sdf_body("return smud::sd_circle(p, 150.);"),
frame: Frame::Quad(200.),
..default()
Expand All @@ -42,7 +42,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut<Assets<Shader>>) {
commands.spawn(ShapeBundle {
transform: Transform::from_translation(Vec3::Z * 1.),
shape: SmudShape {
color: Color::rgb(0.83, 0.82, 0.80),
color: Color::srgb(0.83, 0.82, 0.80),
sdf: shaders.add_sdf_body("return smud::sd_vesica(p.yx, 400., 150.);"),
frame: Frame::Quad(400.),
..default()
Expand Down
4 changes: 2 additions & 2 deletions examples/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.insert_resource(ClearColor(Color::srgb(0.7, 0.8, 0.7)))
.add_plugins((DefaultPlugins, SmudPlugin, PanCamPlugin))
.add_systems(Startup, setup)
.run();
Expand All @@ -18,7 +18,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

commands.spawn(ShapeBundle {
shape: SmudShape {
color: Color::rgb(0.36, 0.41, 0.45),
color: Color::srgb(0.36, 0.41, 0.45),
sdf: bevy_shape_shader,
frame: Frame::Quad(400.),
..default()
Expand Down
4 changes: 2 additions & 2 deletions examples/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::rgb(0.7, 0.8, 0.7)))
.insert_resource(ClearColor(Color::srgb(0.7, 0.8, 0.7)))
.add_plugins((DefaultPlugins, SmudPlugin, PanCamPlugin))
.add_systems(Startup, setup)
.run();
Expand All @@ -25,7 +25,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
};

let shape = SmudShape {
color: Color::rgb(0.36, 0.41, 0.45),
color: Color::srgb(0.36, 0.41, 0.45),
sdf: bevy_shape_shader,
frame: Frame::Quad(295.),
..default()
Expand Down
Loading
Loading