diff --git a/Cargo.toml b/Cargo.toml index c7beaa1..ba8131e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 \ No newline at end of file +opt-level = 3 diff --git a/README.md b/README.md index 64204da..f6b57f2 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/examples/basic.rs b/examples/basic.rs index b0816af..1e0b10a 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -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::*; @@ -39,7 +40,7 @@ return smud::sd_circle(p_2 - vec2(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. @@ -52,7 +53,7 @@ return smud::sd_circle(p_2 - vec2(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() diff --git a/examples/bench.rs b/examples/bench.rs index 5ce0654..27b4496 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -1,4 +1,5 @@ use bevy::{ + color::palettes::css, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, }; @@ -9,14 +10,6 @@ use rand::prelude::*; fn main() { App::new() - .add_state::() - // 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(), @@ -25,6 +18,15 @@ fn main() { PanCamPlugin, bevy_lospec::PalettePlugin, )) + .init_state::() + // 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::(), + ) .add_systems(OnEnter(GameState::Running), setup) // .add_system_set(SystemSet::on_update(GameState::Running).with_system(update)) .run(); @@ -43,6 +45,7 @@ struct AssetHandles { palette: Handle, } +#[allow(dead_code)] #[derive(Component)] struct Index(usize); @@ -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 { diff --git a/examples/bevy.rs b/examples/bevy.rs index 5ed4315..d1c4c2a 100644 --- a/examples/bevy.rs +++ b/examples/bevy.rs @@ -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(); @@ -18,7 +18,7 @@ fn setup(mut commands: Commands, asset_server: Res) { 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() diff --git a/examples/bloom.rs b/examples/bloom.rs index 4a2da01..5f918e4 100644 --- a/examples/bloom.rs +++ b/examples/bloom.rs @@ -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::*; @@ -27,7 +28,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut>) { 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. diff --git a/examples/custom_fill.rs b/examples/custom_fill.rs index 67204d1..200d262 100644 --- a/examples/custom_fill.rs +++ b/examples/custom_fill.rs @@ -1,3 +1,4 @@ +use bevy::color::palettes::css; use bevy::prelude::*; use bevy_pancam::*; use bevy_smud::{prelude::*, SIMPLE_FILL_HANDLE}; @@ -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.), @@ -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.), @@ -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" diff --git a/examples/gallery.rs b/examples/gallery.rs index 76591b0..748ce20 100644 --- a/examples/gallery.rs +++ b/examples/gallery.rs @@ -1,3 +1,4 @@ +use bevy::color::palettes::css; use bevy::prelude::*; use bevy_asset_loader::prelude::*; use bevy_pancam::*; @@ -6,14 +7,8 @@ use rand::prelude::*; fn main() { App::new() - .add_state::() // 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, @@ -22,6 +17,13 @@ fn main() { PanCamPlugin, bevy_lospec::PalettePlugin, )) + .init_state::() + .insert_resource(Msaa::Off) + .add_loading_state( + LoadingState::new(GameState::Loading) + .continue_to_state(GameState::Running) + .load_collection::(), + ) .add_systems(OnEnter(GameState::Running), setup) .run(); } @@ -39,6 +41,7 @@ struct AssetHandles { palette: Handle, } +#[allow(dead_code)] #[derive(Component)] struct Index(usize); @@ -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"), @@ -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; diff --git a/examples/oscilloscope.rs b/examples/oscilloscope.rs new file mode 100644 index 0000000..93c46ac --- /dev/null +++ b/examples/oscilloscope.rs @@ -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, + mut shaders: ResMut>, +) { + // 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(col, color.a); +// This is a darker effect. +// return vec4(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) -> vec3 { + var v = max(v_, vec3(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())); +} diff --git a/examples/sorting.rs b/examples/sorting.rs index 69b306d..429cdce 100644 --- a/examples/sorting.rs +++ b/examples/sorting.rs @@ -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(); @@ -18,7 +18,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut>) { 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() @@ -30,7 +30,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut>) { 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() @@ -42,7 +42,7 @@ fn setup(mut commands: Commands, mut shaders: ResMut>) { 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() diff --git a/examples/time.rs b/examples/time.rs index 117e0e4..d9713d4 100644 --- a/examples/time.rs +++ b/examples/time.rs @@ -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(); @@ -18,7 +18,7 @@ fn setup(mut commands: Commands, asset_server: Res) { 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() diff --git a/examples/transforms.rs b/examples/transforms.rs index 9f4186b..3f7d30f 100644 --- a/examples/transforms.rs +++ b/examples/transforms.rs @@ -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(); @@ -25,7 +25,7 @@ fn setup(mut commands: Commands, asset_server: Res) { }; 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() diff --git a/src/components.rs b/src/components.rs index be95ec3..7f1a6cf 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,3 +1,4 @@ +use bevy::color::palettes::css; use bevy::prelude::*; use crate::DEFAULT_FILL_HANDLE; @@ -23,7 +24,7 @@ pub struct SmudShape { impl Default for SmudShape { fn default() -> Self { Self { - color: Color::PINK, + color: css::PINK.into(), sdf: default(), frame: default(), fill: DEFAULT_FILL_HANDLE, diff --git a/src/lib.rs b/src/lib.rs index 68d8797..920be69 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,38 +7,39 @@ use std::ops::Range; use bevy::{ core_pipeline::core_2d::Transparent2d, ecs::{ + entity::EntityHashMap, query::ROQueryItem, system::{ lifetimeless::{Read, SRes}, SystemParamItem, }, }, - math::Vec3Swizzles, + math::{FloatOrd, Vec3Swizzles}, prelude::*, render::{ globals::{GlobalsBuffer, GlobalsUniform}, render_phase::{ - AddRenderCommand, DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, - RenderPhase, SetItemPipeline, TrackedRenderPass, + AddRenderCommand, DrawFunctions, PhaseItem, PhaseItemExtraIndex, RenderCommand, + RenderCommandResult, SetItemPipeline, TrackedRenderPass, ViewSortedRenderPhases, }, render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingType, BlendState, BufferBindingType, BufferUsages, - BufferVec, CachedRenderPipelineId, ColorTargetState, ColorWrites, Face, FragmentState, - FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState, - PrimitiveTopology, RenderPipelineDescriptor, ShaderImport, ShaderStages, ShaderType, - SpecializedRenderPipeline, SpecializedRenderPipelines, TextureFormat, VertexAttribute, - VertexBufferLayout, VertexFormat, VertexState, VertexStepMode, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, + BlendState, BufferBindingType, BufferUsages, CachedRenderPipelineId, ColorTargetState, + ColorWrites, Face, FragmentState, FrontFace, MultisampleState, PipelineCache, + PolygonMode, PrimitiveState, PrimitiveTopology, RawBufferVec, RenderPipelineDescriptor, + ShaderImport, ShaderStages, ShaderType, SpecializedRenderPipeline, + SpecializedRenderPipelines, TextureFormat, VertexAttribute, VertexBufferLayout, + VertexFormat, VertexState, VertexStepMode, }, renderer::{RenderDevice, RenderQueue}, texture::BevyDefault, view::{ - ExtractedView, ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms, - VisibleEntities, + check_visibility, ExtractedView, ViewTarget, ViewUniform, ViewUniformOffset, + ViewUniforms, VisibilitySystems, VisibleEntities, WithMesh, }, Extract, MainWorld, Render, RenderApp, RenderSet, }, - utils::{EntityHashMap, FloatOrd, HashMap}, + utils::HashMap, }; use bytemuck::{Pod, Zeroable}; use fixedbitset::FixedBitSet; @@ -84,32 +85,31 @@ pub struct SmudPlugin; impl Plugin for SmudPlugin { fn build(&self, app: &mut App) { // All the messy boiler-plate for loading a bunch of shaders - app.add_plugins(ShaderLoadingPlugin); + app.add_plugins(ShaderLoadingPlugin).add_systems( + PostUpdate, + check_visibility::>.in_set(VisibilitySystems::CheckVisibility), + ); // app.add_plugins(UiShapePlugin); - if let Ok(render_app) = app.get_sub_app_mut(RenderApp) { - render_app - .add_render_command::() - .init_resource::() - .init_resource::() - .init_resource::>() - .add_systems(ExtractSchedule, (extract_shapes, extract_sdf_shaders)) - .add_systems( - Render, - ( - queue_shapes.in_set(RenderSet::Queue), - prepare_shapes.in_set(RenderSet::PrepareBindGroups), - ), - ); - } - app.register_type::(); } fn finish(&self, app: &mut App) { - app.get_sub_app_mut(RenderApp) - .unwrap() - .init_resource::(); + let render_app = app.sub_app_mut(RenderApp); + render_app + .add_render_command::() + .init_resource::() + .init_resource::() + .init_resource::>() + .init_resource::() + .add_systems(ExtractSchedule, (extract_shapes, extract_sdf_shaders)) + .add_systems( + Render, + ( + queue_shapes.in_set(RenderSet::Queue), + prepare_shapes.in_set(RenderSet::PrepareBindGroups), + ), + ); } } @@ -118,13 +118,13 @@ type DrawSmudShape = (SetItemPipeline, SetShapeViewBindGroup<0>, DrawShapeBatch) struct SetShapeViewBindGroup; impl RenderCommand

for SetShapeViewBindGroup { type Param = SRes; - type ViewWorldQuery = Read; - type ItemWorldQuery = (); + type ViewQuery = Read; + type ItemQuery = (); fn render<'w>( _item: &P, - view_uniform: ROQueryItem<'w, Self::ViewWorldQuery>, - _view: (), + view_uniform: ROQueryItem<'w, Self::ViewQuery>, + _entity: Option>, shape_meta: SystemParamItem<'w, '_, Self::Param>, pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { @@ -140,19 +140,21 @@ impl RenderCommand

for SetShapeViewBindGroup struct DrawShapeBatch; impl RenderCommand

for DrawShapeBatch { type Param = SRes; - type ViewWorldQuery = (); - type ItemWorldQuery = Read; + type ViewQuery = (); + type ItemQuery = Read; fn render<'w>( _item: &P, _view: (), - batch: &'_ ShapeBatch, + batch: Option>, shape_meta: SystemParamItem<'w, '_, Self::Param>, pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { let shape_meta = shape_meta.into_inner(); pass.set_vertex_buffer(0, shape_meta.vertices.buffer().unwrap().slice(..)); - pass.draw(0..4, batch.range.clone()); + if let Some(batch) = batch { + pass.draw(0..4, batch.range.clone()); + } RenderCommandResult::Success } } @@ -167,8 +169,9 @@ impl FromWorld for SmudPipeline { fn from_world(world: &mut World) -> Self { let render_device = world.get_resource::().unwrap(); - let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ + let view_layout = render_device.create_bind_group_layout( + Some("shape_view_layout"), + &[ BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::VERTEX_FRAGMENT, @@ -190,8 +193,7 @@ impl FromWorld for SmudPipeline { count: None, }, ], - label: Some("shape_view_layout"), - }); + ); Self { view_layout, @@ -397,7 +399,7 @@ struct ExtractedShape { #[derive(Resource, Default, Debug)] struct ExtractedShapes { - shapes: EntityHashMap, + shapes: EntityHashMap, } fn extract_shapes( @@ -482,8 +484,10 @@ fn queue_shapes( pipeline_cache: ResMut, msaa: Res, extracted_shapes: ResMut, + mut transparent_render_phases: ResMut>, mut views: Query<( - &mut RenderPhase, + Entity, + // &mut RenderPhase, &VisibleEntities, &ExtractedView, )>, @@ -492,15 +496,24 @@ fn queue_shapes( let draw_smud_shape_function = draw_functions.read().get_id::().unwrap(); // Iterate over each view (a camera is a view) - for (mut transparent_phase, visible_entities, view) in &mut views { + for (view_entity, visible_entities, view) in &mut views { // todo: bevy_sprite does some hdr stuff, should we? // let mut view_key = SpritePipelineKey::from_hdr(view.hdr) | msaa_key; + // + // + let Some(transparent_phase) = transparent_render_phases.get_mut(&view_entity) else { + continue; + }; let mesh_key = PipelineKey::from_msaa_samples(msaa.samples()) | PipelineKey::from_primitive_topology(PrimitiveTopology::TriangleStrip); view_entities.clear(); - view_entities.extend(visible_entities.entities.iter().map(|e| e.index() as usize)); + view_entities.extend( + visible_entities + .iter::() + .map(|e| e.index() as usize), + ); transparent_phase .items @@ -540,7 +553,7 @@ fn queue_shapes( sort_key, // batch_range and dynamic_offset will be calculated in prepare_shapes batch_range: 0..0, - dynamic_offset: None, + extra_index: PhaseItemExtraIndex::NONE, }); } } @@ -555,7 +568,8 @@ fn prepare_shapes( view_uniforms: Res, smud_pipeline: Res, extracted_shapes: Res, - mut phases: Query<&mut RenderPhase>, + mut phases: ResMut>, + // mut phases: Query<&mut RenderPhase>, globals_buffer: Res, ) { let globals = globals_buffer.buffer.binding().unwrap(); // todo if-let @@ -575,7 +589,7 @@ fn prepare_shapes( // Vertex buffer index let mut index = 0; - for mut transparent_phase in &mut phases { + for (_entity, transparent_phase) in phases.iter_mut() { let mut batch_item_index = 0; // let mut batch_image_size = Vec2::ZERO; // let mut batch_image_handle = AssetId::invalid(); @@ -601,7 +615,8 @@ fn prepare_shapes( let batch_shader_changed = batch_shader_handles != shader_handles; - let color = extracted_shape.color.as_linear_rgba_f32(); + let lrgba: LinearRgba = extracted_shape.color.into(); + let color = lrgba.to_f32_array(); let position = extracted_shape.transform.translation(); let position = position.into(); @@ -666,14 +681,14 @@ struct ShapeVertex { #[derive(Resource)] pub(crate) struct ShapeMeta { - vertices: BufferVec, + vertices: RawBufferVec, view_bind_group: Option, } impl Default for ShapeMeta { fn default() -> Self { Self { - vertices: BufferVec::new(BufferUsages::VERTEX), + vertices: RawBufferVec::new(BufferUsages::VERTEX), view_bind_group: None, } } diff --git a/src/util.rs b/src/util.rs index c81992a..361283b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,4 @@ -use bevy::utils::Uuid; +use uuid::Uuid; pub fn generate_shader_id() -> String { Uuid::new_v4().to_string().replace('-', "_")