diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index fcb0c3a..0daeab9 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,10 +1,11 @@ name: PR +permissions: read-all on: push: - branches: ["main"] + branches: [main] pull_request: - branches: ["main"] + branches: [main] env: CARGO_TERM_COLOR: always diff --git a/.trunk/.gitignore b/.trunk/.gitignore index 1e24652..15966d0 100644 --- a/.trunk/.gitignore +++ b/.trunk/.gitignore @@ -6,3 +6,4 @@ plugins user_trunk.yaml user.yaml +tmp diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 12cb477..a91ba83 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,26 +1,26 @@ version: 0.1 cli: - version: 1.17.1 + version: 1.22.3 plugins: sources: - id: trunk - ref: v1.2.6 + ref: v1.6.2 uri: https://github.com/trunk-io/plugins lint: enabled: - - checkov@3.0.22 - - trivy@0.47.0 - - trufflehog@3.62.1 - - yamllint@1.32.0 - - actionlint@1.6.26 - - oxipng@9.0.0 - - taplo@0.8.1 - - markdownlint@0.37.0 - - clippy@1.73.0 + - checkov@3.2.235 + - trivy@0.54.1 + - trufflehog@3.81.9 + - yamllint@1.35.1 + - actionlint@1.7.1 + - oxipng@9.1.2 + - taplo@0.9.3 + - markdownlint@0.41.0 + - clippy@SYSTEM + - rustfmt@SYSTEM - git-diff-check - - rustfmt@1.73.0 - - prettier@3.0.3 - - gitleaks@8.18.0 + - prettier@3.3.3 + - gitleaks@8.18.4 runtimes: enabled: @@ -40,4 +40,4 @@ actions: merge: required_statuses: - - Trunk Check + - PR / Trunk Check (pull_request) diff --git a/Cargo.toml b/Cargo.toml index 9be3824..faef052 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,28 +1,29 @@ [package] edition = "2021" name = "bevy_magic_light_2d" -version = "0.7.0" +version = "0.8.0" [features] default = ["egui"] egui = ["dep:bevy-inspector-egui"] [dependencies] -bevy = { version = "0.13", default-features = false, features = [ - "bevy_render", - "bevy_core_pipeline", - "bevy_winit", - "bevy_asset", - "bevy_sprite", - "bevy_pbr", - "embedded_watcher", +bevy = { version = "0.14.1", default-features = false, features = [ + "bevy_render", + "bevy_core_pipeline", + "bevy_winit", + "bevy_asset", + "bevy_sprite", + "bevy_pbr", + "embedded_watcher", + "multi_threaded", ] } -bevy-inspector-egui = { version = "0.23.0", optional = true } +bevy-inspector-egui = { version = "0.25.2", optional = true } log = "0.4.20" rand = "0.8.5" [dev-dependencies] -bevy = "0.13" +bevy = "0.14.1" [profile.release] codegen-units = 1 diff --git a/assets/art/atlas_floor.png b/assets/art/atlas_floor.png index 21906ae..6e0ab81 100644 Binary files a/assets/art/atlas_floor.png and b/assets/art/atlas_floor.png differ diff --git a/examples/krypta.rs b/examples/krypta.rs index a42b71e..b6c8bc3 100644 --- a/examples/krypta.rs +++ b/examples/krypta.rs @@ -1,9 +1,12 @@ +use bevy::color::palettes; use bevy::prelude::*; use bevy::render::camera::RenderTarget; use bevy::render::texture::{ImageFilterMode, ImageSamplerDescriptor}; use bevy::render::view::RenderLayers; use bevy::sprite::MaterialMesh2dBundle; use bevy::window::PrimaryWindow; +use bevy_inspector_egui::quick::ResourceInspectorPlugin; +use bevy_magic_light_2d::gi::render_layer::ALL_LAYERS; use bevy_magic_light_2d::prelude::*; use rand::prelude::*; @@ -24,7 +27,7 @@ fn main() { // Basic setup. App::new() - .insert_resource(ClearColor(Color::rgba_u8(0, 0, 0, 0))) + .insert_resource(ClearColor(Color::srgba_u8(0, 0, 0, 0))) .add_plugins(( DefaultPlugins .set(AssetPlugin { @@ -48,6 +51,7 @@ fn main() }, }), BevyMagicLight2DPlugin, + ResourceInspectorPlugin::::new(), )) .insert_resource(BevyMagicLight2DSettings { light_pass_params: LightPassParams { @@ -134,7 +138,7 @@ fn setup( // Load floor tiles. let floor_atlas_rows = 4; let floor_atlas_cols = 4; - let floor_atlas_size = Vec2::new(16.0, 16.0); + let floor_atlas_size = UVec2::new(16, 16); let floor_image = asset_server.load("art/atlas_floor.png"); let floor_atlas = texture_atlases.add(TextureAtlasLayout::from_grid( floor_atlas_size, @@ -147,7 +151,7 @@ fn setup( // Load wall tiles. let wall_atlas_rows = 5; let wall_atlas_cols = 6; - let wall_atlas_size = Vec2::new(16.0, 16.0); + let wall_atlas_size = UVec2::new(16, 16); let wall_image = asset_server.load("art/atlas_wall.png"); let wall_atlas = texture_atlases.add(TextureAtlasLayout::from_grid( wall_atlas_size, @@ -171,19 +175,21 @@ fn setup( floor_tiles.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(xy.x, xy.y, z), - scale: Vec2::splat(SPRITE_SCALE).extend(0.0), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(xy.x, xy.y, z), + scale: Vec2::splat(SPRITE_SCALE).extend(0.0), + ..default() + }, + texture: floor_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: floor_atlas.clone(), - index: id, + index: id as usize, }, - texture: floor_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_FLOOR)) .id(), ); @@ -299,19 +305,21 @@ fn setup( walls.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(xy.x, xy.y, z), - scale: Vec2::splat(SPRITE_SCALE).extend(0.0), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(xy.x, xy.y, z), + scale: Vec2::splat(SPRITE_SCALE).extend(0.0), + ..default() + }, + texture: wall_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: wall_atlas.clone(), - index: id, + index: id as usize, }, - texture: wall_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_WALLS)) .insert(occluder_data) .id(), @@ -327,31 +335,31 @@ fn setup( // Add decorations. let mut decorations = vec![]; { - let mut decorations_atlas = TextureAtlasLayout::new_empty(Vec2::new(256.0, 256.0)); + let mut decorations_atlas = TextureAtlasLayout::new_empty(UVec2::new(256, 256)); - let candle_rect_1 = decorations_atlas.add_texture(Rect { - min: Vec2::new(0.0, 0.0), - max: Vec2::new(16.0, 16.0), + let candle_rect_1 = decorations_atlas.add_texture(URect { + min: UVec2::new(0, 0), + max: UVec2::new(16, 16), }); - let candle_rect_2 = decorations_atlas.add_texture(Rect { - min: Vec2::new(16.0, 0.0), - max: Vec2::new(32.0, 16.0), + let candle_rect_2 = decorations_atlas.add_texture(URect { + min: UVec2::new(16, 0), + max: UVec2::new(32, 16), }); - let candle_rect_3 = decorations_atlas.add_texture(Rect { - min: Vec2::new(32.0, 0.0), - max: Vec2::new(48.0, 16.0), + let candle_rect_3 = decorations_atlas.add_texture(URect { + min: UVec2::new(32, 0), + max: UVec2::new(48, 16), }); - let candle_rect_4 = decorations_atlas.add_texture(Rect { - min: Vec2::new(48.0, 0.0), - max: Vec2::new(64.0, 16.0), + let candle_rect_4 = decorations_atlas.add_texture(URect { + min: UVec2::new(48, 0), + max: UVec2::new(64, 16), }); - let tomb_rect_1 = decorations_atlas.add_texture(Rect { - min: Vec2::new(32.0, 16.0), - max: Vec2::new(80.0, 48.0), + let tomb_rect_1 = decorations_atlas.add_texture(URect { + min: UVec2::new(32, 16), + max: UVec2::new(80, 48), }); - let sewerage_rect_1 = decorations_atlas.add_texture(Rect { - min: Vec2::new(0.0, 16.0), - max: Vec2::new(32.0, 48.0), + let sewerage_rect_1 = decorations_atlas.add_texture(URect { + min: UVec2::new(0, 16), + max: UVec2::new(32, 48), }); let texture_atlas_handle = texture_atlases.add(decorations_atlas); @@ -363,23 +371,25 @@ fn setup( decorations.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(x, y, get_object_z(y)), - scale: Vec2::splat(4.0).extend(0.0), - ..default() - }, - sprite: Sprite { - color: Color::rgb_u8(180, 180, 180), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(x, y, get_object_z(y)), + scale: Vec2::splat(4.0).extend(0.0), + ..default() + }, + sprite: Sprite { + color: Color::srgb_u8(180, 180, 180), + ..default() + }, + texture: decorations_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: texture_atlas_handle.clone(), index: candle_rect_1, }, - texture: decorations_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_OBJECTS)) .insert(LightOccluder2D { h_size: Vec2::splat(2.0), @@ -396,23 +406,25 @@ fn setup( decorations.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(x, y, get_object_z(y)), - scale: Vec2::splat(4.0).extend(0.0), - ..default() - }, - sprite: Sprite { - color: Color::rgb_u8(180, 180, 180), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(x, y, get_object_z(y)), + scale: Vec2::splat(4.0).extend(0.0), + ..default() + }, + sprite: Sprite { + color: Color::srgb_u8(180, 180, 180), + ..default() + }, + texture: decorations_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: texture_atlas_handle.clone(), index: candle_rect_2, }, - texture: decorations_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_OBJECTS)) .insert(LightOccluder2D { h_size: Vec2::splat(2.0), @@ -429,23 +441,25 @@ fn setup( decorations.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(x, y, get_object_z(y)), - scale: Vec2::splat(4.0).extend(0.0), - ..default() - }, - sprite: Sprite { - color: Color::rgb_u8(180, 180, 180), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(x, y, get_object_z(y)), + scale: Vec2::splat(4.0).extend(0.0), + ..default() + }, + sprite: Sprite { + color: Color::srgb_u8(180, 180, 180), + ..default() + }, + texture: decorations_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: texture_atlas_handle.clone(), index: candle_rect_3, }, - texture: decorations_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_OBJECTS)) .insert(LightOccluder2D { h_size: Vec2::splat(2.0), @@ -462,23 +476,25 @@ fn setup( decorations.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(x, y, get_object_z(y)), - scale: Vec2::splat(4.0).extend(0.0), - ..default() - }, - sprite: Sprite { - color: Color::rgb_u8(180, 180, 180), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(x, y, get_object_z(y)), + scale: Vec2::splat(4.0).extend(0.0), + ..default() + }, + sprite: Sprite { + color: Color::srgb_u8(180, 180, 180), + ..default() + }, + texture: decorations_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: texture_atlas_handle.clone(), index: candle_rect_4, }, - texture: decorations_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_OBJECTS)) .insert(LightOccluder2D { h_size: Vec2::splat(2.0), @@ -494,23 +510,25 @@ fn setup( let y = -220.0; decorations.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(x, y, get_object_z(y)), - scale: Vec2::splat(4.0).extend(0.0), - ..default() - }, - sprite: Sprite { - color: Color::rgb_u8(255, 255, 255), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(x, y, get_object_z(y)), + scale: Vec2::splat(4.0).extend(0.0), + ..default() + }, + sprite: Sprite { + color: Color::srgb_u8(255, 255, 255), + ..default() + }, + texture: decorations_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: texture_atlas_handle.clone(), index: tomb_rect_1, }, - texture: decorations_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_OBJECTS)) .insert(LightOccluder2D { h_size: Vec2::new(72.8, 31.0), @@ -526,23 +544,25 @@ fn setup( let y = -500.0; decorations.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(x, y, get_object_z(y)), - scale: Vec2::splat(4.0).extend(0.0), - ..default() - }, - sprite: Sprite { - color: Color::rgb_u8(255, 255, 255), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(x, y, get_object_z(y)), + scale: Vec2::splat(4.0).extend(0.0), + ..default() + }, + sprite: Sprite { + color: Color::srgb_u8(255, 255, 255), + ..default() + }, + texture: decorations_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: texture_atlas_handle.clone(), index: tomb_rect_1, }, - texture: decorations_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_OBJECTS)) .insert(LightOccluder2D { h_size: Vec2::new(72.8, 31.0), @@ -559,23 +579,25 @@ fn setup( decorations.push( commands - .spawn(SpriteSheetBundle { - transform: Transform { - translation: Vec3::new(x, y, get_object_z(y)), - scale: Vec2::splat(4.0).extend(0.0), - ..default() - }, - sprite: Sprite { - color: Color::rgb_u8(255, 255, 255), + .spawn(( + SpriteBundle { + transform: Transform { + translation: Vec3::new(x, y, get_object_z(y)), + scale: Vec2::splat(4.0).extend(0.0), + ..default() + }, + sprite: Sprite { + color: Color::srgb_u8(255, 255, 255), + ..default() + }, + texture: decorations_image.clone(), ..default() }, - atlas: TextureAtlas { + TextureAtlas { layout: texture_atlas_handle.clone(), index: sewerage_rect_1, }, - texture: decorations_image.clone(), - ..default() - }) + )) .insert(RenderLayers::from_layers(CAMERA_LAYER_FLOOR)) // Add to floor .insert(Name::new("sewerage_1")) .id(), @@ -604,7 +626,7 @@ fn setup( }, ..default() }) - .insert(RenderLayers::all()) + .insert(RenderLayers::from_layers(ALL_LAYERS)) .id() }; @@ -620,7 +642,7 @@ fn setup( "outdoor_krypta_torch_1", OmniLightSource2D { intensity: 4.5, - color: Color::rgb_u8(137, 79, 24), + color: Color::srgb_u8(137, 79, 24), jitter_intensity: 2.5, jitter_translation: 8.0, ..base @@ -633,7 +655,7 @@ fn setup( "outdoor_krypta_torch_2", OmniLightSource2D { intensity: 4.5, - color: Color::rgb_u8(137, 79, 24), + color: Color::srgb_u8(137, 79, 24), jitter_intensity: 2.5, jitter_translation: 8.0, ..base @@ -646,7 +668,7 @@ fn setup( "indoor_krypta_light_1", OmniLightSource2D { intensity: 10.0, - color: Color::rgb_u8(76, 57, 211), + color: Color::srgb_u8(76, 57, 211), jitter_intensity: 2.0, jitter_translation: 0.0, ..base @@ -659,7 +681,7 @@ fn setup( "indoor_krypta_light_2", OmniLightSource2D { intensity: 10.0, - color: Color::rgb_u8(76, 57, 211), + color: Color::srgb_u8(76, 57, 211), jitter_intensity: 2.0, jitter_translation: 0.0, ..base @@ -672,7 +694,7 @@ fn setup( "outdoor_krypta_torch_3", OmniLightSource2D { intensity: 4.5, - color: Color::rgb_u8(137, 79, 24), + color: Color::srgb_u8(137, 79, 24), jitter_intensity: 2.5, jitter_translation: 3.0, ..base @@ -685,7 +707,7 @@ fn setup( "outdoor_krypta_torch_4", OmniLightSource2D { intensity: 4.5, - color: Color::rgb_u8(137, 79, 24), + color: Color::srgb_u8(137, 79, 24), jitter_intensity: 2.5, jitter_translation: 3.0, ..base @@ -698,7 +720,7 @@ fn setup( "indoor_krypta_ghost_1", OmniLightSource2D { intensity: 0.8, - color: Color::rgb_u8(6, 53, 6), + color: Color::srgb_u8(6, 53, 6), jitter_intensity: 0.2, jitter_translation: 0.0, ..base @@ -711,7 +733,7 @@ fn setup( "indoor_krypta_tomb_1", OmniLightSource2D { intensity: 0.4, - color: Color::rgb_u8(252, 182, 182), + color: Color::srgb_u8(252, 182, 182), jitter_intensity: 0.05, jitter_translation: 4.7, ..base @@ -726,7 +748,7 @@ fn setup( OmniLightSource2D { intensity: 1.2, falloff: Vec3::new(50.0, 40.0, 0.03), - color: Color::rgb_u8(0, 206, 94), + color: Color::srgb_u8(0, 206, 94), jitter_intensity: 0.7, jitter_translation: 3.0, }, @@ -740,7 +762,7 @@ fn setup( OmniLightSource2D { intensity: 1.2, falloff: Vec3::new(50.0, 40.0, 0.03), - color: Color::rgb_u8(0, 206, 94), + color: Color::srgb_u8(0, 206, 94), jitter_intensity: 0.7, jitter_translation: 3.0, }, @@ -780,7 +802,7 @@ fn setup( // Add skylight light. commands.spawn(( SkylightLight2D { - color: Color::rgb_u8(93, 158, 179), + color: Color::srgb_u8(93, 158, 179), intensity: 0.025, }, Name::new("global_skylight"), @@ -790,7 +812,7 @@ fn setup( commands .spawn(MaterialMesh2dBundle { mesh: block_mesh.into(), - material: materials.add(ColorMaterial::from(Color::YELLOW)), + material: materials.add(ColorMaterial::from_color(palettes::basic::YELLOW)), transform: Transform { translation: Vec3::new(0.0, 0.0, 1000.0), scale: Vec3::splat(8.0), @@ -801,11 +823,11 @@ fn setup( .insert(Name::new("cursor_light")) .insert(OmniLightSource2D { intensity: 10.0, - color: Color::rgb_u8(254, 100, 34), + color: Color::srgb_u8(254, 100, 34), falloff: Vec3::new(50.0, 20.0, 0.05), ..default() }) - .insert(RenderLayers::all()) + .insert(RenderLayers::from_layers(ALL_LAYERS)) .insert(MouseLight); let projection = OrthographicProjection { @@ -887,14 +909,14 @@ fn system_control_mouse_light( let window_size = Vec2::new(window.width(), window.height()); let mut mouse_ndc = (screen_pos / window_size) * 2.0 - Vec2::ONE; mouse_ndc = Vec2::new(mouse_ndc.x, -mouse_ndc.y); - let ndc_to_world = camera_transform.compute_matrix() * camera.projection_matrix().inverse(); + let ndc_to_world = camera_transform.compute_matrix() * camera.clip_from_view().inverse(); let mouse_world = ndc_to_world.project_point3(mouse_ndc.extend(-1.0)); let (mut mouse_transform, mut mouse_color) = query_light.single_mut(); mouse_transform.translation = mouse_world.truncate().extend(1000.0); if mouse.just_pressed(MouseButton::Right) { - mouse_color.color = Color::rgba(rng.gen(), rng.gen(), rng.gen(), 1.0); + mouse_color.color = Color::srgba(rng.gen(), rng.gen(), rng.gen(), 1.0); } if mouse.just_pressed(MouseButton::Left) && keyboard.pressed(KeyCode::ShiftLeft) { commands @@ -906,7 +928,7 @@ fn system_control_mouse_light( ..default() }) .insert(Name::new("point_light")) - .insert(RenderLayers::all()) + .insert(RenderLayers::from_layers(ALL_LAYERS)) .insert(OmniLightSource2D { jitter_intensity: 0.0, jitter_translation: 0.0, diff --git a/examples/minimal.rs b/examples/minimal.rs index ff12cab..eb3a8e3 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -7,7 +7,7 @@ fn main() { // Basic setup. App::new() - .insert_resource(ClearColor(Color::rgb_u8(255, 255, 255))) + .insert_resource(ClearColor(Color::srgba_u8(255, 255, 255, 0))) .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { @@ -74,7 +74,7 @@ fn setup(mut commands: Commands, camera_targets: Res) "left", OmniLightSource2D { intensity: 1.0, - color: Color::rgb_u8(255, 0, 0), + color: Color::srgb_u8(255, 0, 0), falloff: Vec3::new(1.5, 10.0, 0.005), ..default() }, @@ -86,7 +86,7 @@ fn setup(mut commands: Commands, camera_targets: Res) "right", OmniLightSource2D { intensity: 1.0, - color: Color::rgb_u8(0, 0, 255), + color: Color::srgb_u8(0, 0, 255), falloff: Vec3::new(1.5, 10.0, 0.005), ..default() }, @@ -98,7 +98,7 @@ fn setup(mut commands: Commands, camera_targets: Res) "rop", OmniLightSource2D { intensity: 1.0, - color: Color::rgb_u8(0, 255, 0), + color: Color::srgb_u8(0, 255, 0), falloff: Vec3::new(1.5, 10.0, 0.005), ..default() }, diff --git a/examples/movement.rs b/examples/movement.rs index 1c88b47..119169a 100644 --- a/examples/movement.rs +++ b/examples/movement.rs @@ -12,7 +12,7 @@ fn main() { // Basic setup. App::new() - .insert_resource(ClearColor(Color::rgb_u8(255, 255, 255))) + .insert_resource(ClearColor(Color::srgba_u8(255, 255, 255, 0))) .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { @@ -92,7 +92,7 @@ fn setup(mut commands: Commands, camera_targets: Res) "left", OmniLightSource2D { intensity: 10.0, - color: Color::rgb_u8(255, 255, 0), + color: Color::srgb_u8(255, 255, 0), falloff: Vec3::new(1.5, 10.0, 0.01), ..default() }, @@ -104,7 +104,7 @@ fn setup(mut commands: Commands, camera_targets: Res) "right", OmniLightSource2D { intensity: 10.0, - color: Color::rgb_u8(0, 255, 255), + color: Color::srgb_u8(0, 255, 255), falloff: Vec3::new(1.5, 10.0, 0.01), ..default() }, diff --git a/rustchannel.toml b/rustchannel.toml index 5d56faf..292fe49 100644 --- a/rustchannel.toml +++ b/rustchannel.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly" +channel = "stable" diff --git a/src/gi/compositing.rs b/src/gi/compositing.rs index f71b749..22bf6d3 100644 --- a/src/gi/compositing.rs +++ b/src/gi/compositing.rs @@ -2,7 +2,7 @@ use bevy::core_pipeline::bloom::BloomSettings; use bevy::pbr::{MAX_CASCADES_PER_LIGHT, MAX_DIRECTIONAL_LIGHTS}; use bevy::prelude::*; use bevy::reflect::TypePath; -use bevy::render::mesh::MeshVertexBufferLayout; +use bevy::render::mesh::MeshVertexBufferLayoutRef; use bevy::render::render_resource::{ AsBindGroup, Extent3d, @@ -21,6 +21,7 @@ use bevy::sprite::{Material2d, Material2dKey, MaterialMesh2dBundle}; use crate::gi::constants::{POST_PROCESSING_MATERIAL, POST_PROCESSING_RECT}; use crate::gi::pipeline::GiTargetsWrapper; +use crate::gi::render_layer; use crate::gi::resource::ComputedTargetSizes; #[derive(Component)] @@ -138,9 +139,9 @@ impl CameraTargets let walls_image_handle: Handle = Handle::weak_from_u128(7264512947825624361); let objects_image_handle: Handle = Handle::weak_from_u128(2987462343287146234); - images.insert(floor_image_handle.clone(), floor_image); - images.insert(walls_image_handle.clone(), walls_image); - images.insert(objects_image_handle.clone(), objects_image); + images.insert(floor_image_handle.id(), floor_image); + images.insert(walls_image_handle.id(), walls_image); + images.insert(objects_image_handle.id(), objects_image); Self { floor_target: floor_image_handle, @@ -150,14 +151,16 @@ impl CameraTargets } } -impl Material2d for PostProcessingMaterial { - fn fragment_shader() -> ShaderRef { +impl Material2d for PostProcessingMaterial +{ + fn fragment_shader() -> ShaderRef + { "embedded://bevy_magic_light_2d/gi/shaders/gi_post_processing.wgsl".into() } fn specialize( descriptor: &mut RenderPipelineDescriptor, - _layout: &MeshVertexBufferLayout, + _layout: &MeshVertexBufferLayoutRef, _key: Material2dKey, ) -> Result<(), SpecializedMeshPipelineError> { @@ -195,16 +198,16 @@ pub fn setup_post_processing_camera( target_sizes.primary_target_size.y, )); - meshes.insert(POST_PROCESSING_RECT.clone(), quad); + meshes.insert(POST_PROCESSING_RECT.id(), quad); *camera_targets = CameraTargets::create(&mut images, &target_sizes); let material = PostProcessingMaterial::create(&camera_targets, &gi_targets_wrapper); - materials.insert(POST_PROCESSING_MATERIAL.clone(), material); + materials.insert(POST_PROCESSING_MATERIAL.id(), material); // This specifies the layer used for the post processing camera, which // will be attached to the post processing camera and 2d quad. - let layer = RenderLayers::layer((RenderLayers::TOTAL_LAYERS - 1) as u8); + let layer = RenderLayers::from_layers(render_layer::CAMERA_LAYER_POST_PROCESSING); commands.spawn(( PostProcessingQuad, @@ -217,7 +220,7 @@ pub fn setup_post_processing_camera( }, ..default() }, - layer, + layer.clone(), )); commands.spawn(( diff --git a/src/gi/mod.rs b/src/gi/mod.rs index ad42e09..a82465a 100644 --- a/src/gi/mod.rs +++ b/src/gi/mod.rs @@ -19,8 +19,11 @@ use crate::gi::pipeline::{ LightPassPipelineBindGroups, }; use crate::gi::pipeline_assets::{ - system_extract_pipeline_assets, system_prepare_pipeline_assets, system_load_embedded_shader_dependencies, - LightPassPipelineAssets, EmbeddedShaderDependencies + system_extract_pipeline_assets, + system_load_embedded_shader_dependencies, + system_prepare_pipeline_assets, + EmbeddedShaderDependencies, + LightPassPipelineAssets, }; use crate::gi::resource::ComputedTargetSizes; use crate::prelude::BevyMagicLight2DSettings; @@ -91,7 +94,7 @@ impl Plugin for BevyMagicLight2DPlugin ), ); - let mut render_graph = render_app.world.resource_mut::(); + let mut render_graph = render_app.world_mut().resource_mut::(); render_graph.add_node(LightPass2DRenderLabel, LightPass2DNode::default()); render_graph.add_node_edge( LightPass2DRenderLabel, @@ -138,7 +141,7 @@ pub fn handle_window_resize( ComputedTargetSizes::from_window(window, &res_plugin_config.target_scaling_params); assets_mesh.insert( - POST_PROCESSING_RECT.clone(), + POST_PROCESSING_RECT.id(), Mesh::from(bevy::math::primitives::Rectangle::new( res_target_sizes.primary_target_size.x, res_target_sizes.primary_target_size.y, @@ -146,7 +149,7 @@ pub fn handle_window_resize( ); assets_material.insert( - POST_PROCESSING_MATERIAL.clone(), + POST_PROCESSING_MATERIAL.id(), PostProcessingMaterial::create(&res_camera_targets, &res_gi_targets_wrapper), ); diff --git a/src/gi/pipeline.rs b/src/gi/pipeline.rs index a8975b7..127a7a0 100644 --- a/src/gi/pipeline.rs +++ b/src/gi/pipeline.rs @@ -4,13 +4,14 @@ use bevy::render::render_asset::{RenderAssetUsages, RenderAssets}; use bevy::render::render_resource::*; use bevy::render::renderer::RenderDevice; use bevy::render::texture::{ + GpuImage, ImageAddressMode, ImageFilterMode, ImageSampler, ImageSamplerDescriptor, }; -use crate::gi::pipeline_assets::{LightPassPipelineAssets, load_embedded_shader}; +use crate::gi::pipeline_assets::{load_embedded_shader, LightPassPipelineAssets}; use crate::gi::resource::ComputedTargetSizes; use crate::gi::types_gpu::{ GpuCameraParams, @@ -94,12 +95,12 @@ impl GiTargets let ss_filter_target: Handle = Handle::weak_from_u128(8761232615172413412); let ss_pose_target: Handle = Handle::weak_from_u128(4728165084756128470); - images.insert(sdf_target.clone(), sdf_tex); - images.insert(ss_probe_target.clone(), ss_probe_tex); - images.insert(ss_bounce_target.clone(), ss_bounce_tex); - images.insert(ss_blend_target.clone(), ss_blend_tex); - images.insert(ss_filter_target.clone(), ss_filter_tex); - images.insert(ss_pose_target.clone(), ss_pose_tex); + images.insert(sdf_target.id(), sdf_tex); + images.insert(ss_probe_target.id(), ss_probe_tex); + images.insert(ss_bounce_target.id(), ss_bounce_tex); + images.insert(ss_blend_target.id(), ss_blend_tex); + images.insert(ss_filter_target.id(), ss_filter_tex); + images.insert(ss_pose_target.id(), ss_pose_tex); Self { sdf_target, @@ -184,7 +185,7 @@ pub struct LightPassPipeline pub fn system_queue_bind_groups( mut commands: Commands, pipeline: Res, - gpu_images: Res>, + gpu_images: Res>, targets_wrapper: Res, gi_compute_assets: Res, render_device: Res, @@ -777,11 +778,11 @@ impl FromWorld for LightPassPipeline let (shader_sdf, gi_ss_probe, gi_ss_bounce, gi_ss_blend, gi_ss_filter) = { let assets_server = world.resource::(); ( - load_embedded_shader(&assets_server, "gi_sdf.wgsl"), - load_embedded_shader(&assets_server, "gi_ss_probe.wgsl"), - load_embedded_shader(&assets_server, "gi_ss_bounce.wgsl"), - load_embedded_shader(&assets_server, "gi_ss_blend.wgsl"), - load_embedded_shader(&assets_server, "gi_ss_filter.wgsl"), + load_embedded_shader(assets_server, "gi_sdf.wgsl"), + load_embedded_shader(assets_server, "gi_ss_probe.wgsl"), + load_embedded_shader(assets_server, "gi_ss_bounce.wgsl"), + load_embedded_shader(assets_server, "gi_ss_blend.wgsl"), + load_embedded_shader(assets_server, "gi_ss_filter.wgsl"), ) }; diff --git a/src/gi/pipeline_assets.rs b/src/gi/pipeline_assets.rs index 898ebf6..05adeca 100644 --- a/src/gi/pipeline_assets.rs +++ b/src/gi/pipeline_assets.rs @@ -1,9 +1,11 @@ +use std::path::Path; + +use bevy::asset::io::AssetSourceId; +use bevy::asset::AssetPath; use bevy::prelude::*; use bevy::render::render_resource::{StorageBuffer, UniformBuffer}; use bevy::render::renderer::{RenderDevice, RenderQueue}; use bevy::render::Extract; -use bevy::asset::{AssetPath, io::AssetSourceId}; -use std::path::Path; use rand::{thread_rng, Rng}; use crate::gi::constants::GI_SCREEN_PROBE_SIZE; @@ -43,7 +45,9 @@ pub(crate) fn system_load_embedded_shader_dependencies( embedded_shader_deps.loaded_shaders.push(load_embedded_shader(&asset_server, "gi_types.wgsl")); } -pub(crate) fn load_embedded_shader(asset_server: &AssetServer, shader_file: &str) -> Handle { +pub(crate) fn load_embedded_shader(asset_server: &AssetServer, shader_file: &str) + -> Handle +{ let source = AssetSourceId::from("embedded"); let path = Path::new("bevy_magic_light_2d").join("gi/shaders/"); asset_server.load(AssetPath::from_path(&path.join(shader_file)).with_source(&source)) @@ -89,8 +93,8 @@ pub fn system_extract_pipeline_assets( res_light_settings: Extract>, res_target_sizes: Extract>, - query_lights: Extract>, - query_occluders: Extract>, + query_lights: Extract>, + query_occluders: Extract>, query_camera: Extract>>, query_masks: Extract>, query_skylight_light: Extract>, @@ -108,8 +112,8 @@ pub fn system_extract_pipeline_assets( let mut rng = thread_rng(); light_sources.count = 0; light_sources.data.clear(); - for (transform, light_source, hviz, vviz) in query_lights.iter() { - if hviz.get() && vviz.get() { + for (transform, light_source, hviz) in query_lights.iter() { + if hviz.get() { light_sources.count += 1; light_sources.data.push(GpuOmniLightSource::new( OmniLightSource2D { @@ -132,8 +136,8 @@ pub fn system_extract_pipeline_assets( let light_occluders = gpu_pipeline_assets.light_occluders.get_mut(); light_occluders.count = 0; light_occluders.data.clear(); - for (occluder, global_transform, transform, hviz, vviz) in query_occluders.iter() { - if hviz.get() && vviz.get() { + for (occluder, global_transform, transform, hviz) in query_occluders.iter() { + if hviz.get() { light_occluders.count += 1; light_occluders.data.push(GpuLightOccluder2D { center: global_transform.translation().xy(), @@ -160,7 +164,7 @@ pub fn system_extract_pipeline_assets( { if let Ok((camera, camera_global_transform)) = query_camera.get_single() { let camera_params = gpu_pipeline_assets.camera_params.get_mut(); - let projection = camera.projection_matrix(); + let projection = camera.clip_from_view(); let inverse_projection = projection.inverse(); let view = camera_global_transform.compute_matrix(); let inverse_view = view.inverse(); @@ -209,9 +213,10 @@ pub fn system_extract_pipeline_assets( let light_pass_params = gpu_pipeline_assets.light_pass_params.get_mut(); light_pass_params.skylight_color = Vec3::splat(0.0); for new_gi_state in query_skylight_light.iter() { - light_pass_params.skylight_color.x += new_gi_state.color.r() * new_gi_state.intensity; - light_pass_params.skylight_color.y += new_gi_state.color.g() * new_gi_state.intensity; - light_pass_params.skylight_color.z += new_gi_state.color.b() * new_gi_state.intensity; + let srgba = new_gi_state.color.to_srgba(); + light_pass_params.skylight_color.x += srgba.red * new_gi_state.intensity; + light_pass_params.skylight_color.y += srgba.green * new_gi_state.intensity; + light_pass_params.skylight_color.z += srgba.blue * new_gi_state.intensity; } } diff --git a/src/gi/render_layer.rs b/src/gi/render_layer.rs index 236a66a..3e4d4fa 100644 --- a/src/gi/render_layer.rs +++ b/src/gi/render_layer.rs @@ -1,3 +1,14 @@ -pub const CAMERA_LAYER_FLOOR: &[u8] = &[1]; -pub const CAMERA_LAYER_WALLS: &[u8] = &[2]; -pub const CAMERA_LAYER_OBJECTS: &[u8] = &[3]; +use bevy::render::view::Layer; + +pub const LAYER_FLOOR_ID: Layer = 1; +pub const LAYER_WALLS_ID: Layer = 2; +pub const LAYER_OBJECTS_ID: Layer = 3; + +pub const CAMERA_LAYER_FLOOR: &[Layer] = &[LAYER_FLOOR_ID]; +pub const CAMERA_LAYER_WALLS: &[Layer] = &[LAYER_WALLS_ID]; +pub const CAMERA_LAYER_OBJECTS: &[Layer] = &[LAYER_OBJECTS_ID]; + +pub const ALL_LAYERS: &[Layer] = &[LAYER_FLOOR_ID, LAYER_WALLS_ID, LAYER_OBJECTS_ID]; + +pub const LAYER_POST_PROCESSING_ID: Layer = 42; +pub const CAMERA_LAYER_POST_PROCESSING: &[Layer] = &[LAYER_POST_PROCESSING_ID]; diff --git a/src/gi/types.rs b/src/gi/types.rs index ea7781a..a6de28b 100644 --- a/src/gi/types.rs +++ b/src/gi/types.rs @@ -36,18 +36,13 @@ impl From for LightOccluder2D } } -/// -/// -/// #[rustfmt::skip] #[derive(Reflect, Component, Default)] #[reflect(Component)] pub struct SkylightMask2D { pub h_size: Vec2, } -/// -/// -/// + #[rustfmt::skip] #[derive(Reflect, Component, Clone, Copy, Default)] #[reflect(Component)] diff --git a/src/gi/types_gpu.rs b/src/gi/types_gpu.rs index d83d37e..8a23547 100644 --- a/src/gi/types_gpu.rs +++ b/src/gi/types_gpu.rs @@ -1,4 +1,4 @@ -use bevy::prelude::{Mat4, Vec2, Vec3, Vec4}; +use bevy::prelude::*; use bevy::render::render_resource::ShaderType; use crate::gi::constants::GI_SCREEN_PROBE_SIZE; @@ -17,11 +17,11 @@ impl GpuOmniLightSource { pub fn new(light: OmniLightSource2D, center: Vec2) -> Self { - let color = light.color.as_rgba_f32(); + let color: Srgba = light.color.into(); Self { center, intensity: light.intensity, - color: Vec3::new(color[0], color[1], color[2]), + color: color.to_vec3(), falloff: light.falloff, } } diff --git a/src/gi/util.rs b/src/gi/util.rs index 1ce9277..b220740 100644 --- a/src/gi/util.rs +++ b/src/gi/util.rs @@ -28,7 +28,7 @@ impl AssetUtil pub fn align_to_work_group_grid(size: IVec2) -> IVec2 { let wg_size = WORKGROUP_SIZE as i32; - // Only add padding if necessary + // Only add padding if necessary IVec2::new( if size.x % wg_size == 0 { size.x