From 7d084ef6a416204409a166b39e56e4f9987aa025 Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Tue, 10 Dec 2024 14:56:41 -0500 Subject: Upgrade to Bevy 0.15 --- Cargo.toml | 6 +++--- README.md | 28 +++++++++------------------- src/lib.rs | 26 +++++++++++++++----------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 57e24a1..7f60ec0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "bevy_blacklight_material" description = "A blacklight material plugin for the Bevy engine" -version = "0.1.0" +version = "0.2.0" edition = "2021" license = "0BSD OR Apache-2.0 OR MIT" -repository = "https://github.com/exvacuum/bevy_blacklight_material" +repository = "https://git.exvacuum.dev/bevy_blacklight_material" [dependencies.bevy] -version = "0.14" +version = "0.15" features = ["bevy_render", "bevy_asset"] diff --git a/README.md b/README.md index e191f8e..6a09a8f 100644 --- a/README.md +++ b/README.md @@ -14,19 +14,20 @@ Feel free to contribute if you want to improve this, it was thrown together pret | Crate Version | Bevy Version | |--- |--- | | 0.1 | 0.14 | +| 0.2 | 0.15 | ## Installation ### crates.io ```toml [dependencies] -bevy_blacklight_material = "0.1" +bevy_blacklight_material = "0.2" ``` ### Using git URL in Cargo.toml ```toml [dependencies.bevy_rustysynth] -git = "https://github.com/exvacuum/bevy_blacklight_material.git" +git = "https://git.exvacuum.dev/bevy_blacklight_material" ``` ## Usage @@ -47,26 +48,15 @@ fn main() { Then you can create blacklight-emitting spotlights, and reveal-able surfaces, like this: ```rs // Mesh with blacklight material -commands.spawn(MaterialMeshBundle { - material: asset_server.add(BlacklightMaterial { - // base texture, color, etc - ..Default::default() - }), - ..Default::default() -}); +commands.spawn(( + //... + MeshMaterial3d(asset_server.add(BlacklightMaterial::new(&asset_server, None, Color::WHITE))), +)); // Blacklight -commands.spawn(( - Blacklight, // Marker component - SpotLightBundle { - spot_light: SpotLight { - // outer/inner angle, range - ..Default::default() - }, - ..Default::default() - }, -)); +// Requires `SpotLight`, but you might want to add one yourself +commands.spawn(Blacklight); ``` ## License diff --git a/src/lib.rs b/src/lib.rs index c7a86f8..d06c710 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ use bevy::{ asset::embedded_asset, prelude::*, - render::render_resource::{AsBindGroup, ShaderType}, + render::{render_resource::{AsBindGroup, ShaderType}, storage::ShaderStorageBuffer}, }; /// Plugin which enables and updates blacklight shaders. @@ -26,6 +26,7 @@ impl Plugin for BlacklightPlugin { /// Marker component for spot lights to use them as blacklights for [`BlacklightMaterial`]. #[derive(Component, Debug)] +#[require(SpotLight)] pub struct Blacklight; /// Shader data representing a single blacklight point light. @@ -49,7 +50,7 @@ pub struct BlacklightData { pub struct BlacklightMaterial { /// List of light data processed by this shader #[storage(0, read_only)] - pub lights: Vec, + pub lights: Handle, /// Base color texture which is revealed by blacklight exposure. #[texture(1)] #[sampler(2)] @@ -61,12 +62,13 @@ pub struct BlacklightMaterial { pub alpha_mode: AlphaMode, } -impl Default for BlacklightMaterial { - fn default() -> Self { +impl BlacklightMaterial { + /// Construct a new instance of this material + pub fn new(asset_server: &AssetServer, base_texture: Option>, base_color: impl Into) -> Self { Self { - lights: vec![], - base_texture: None, - base_color: LinearRgba::WHITE, + lights: asset_server.add(ShaderStorageBuffer::default()), + base_texture, + base_color: base_color.into(), alpha_mode: AlphaMode::Blend, } } @@ -84,8 +86,9 @@ impl Material for BlacklightMaterial { fn update_shader_blacklight_data( blacklight_query: Query<(&ViewVisibility, &GlobalTransform, &SpotLight), With>, - blacklight_material_query: Query<&Handle>, + blacklight_material_query: Query<&MeshMaterial3d>, mut blacklight_materials: ResMut>, + mut blacklight_storage_buffers: ResMut>, ) { let light_data = blacklight_query .iter() @@ -98,8 +101,9 @@ fn update_shader_blacklight_data( outer_angle: light.outer_angle, }) .collect::>(); - for handle in blacklight_material_query.iter() { - let material = blacklight_materials.get_mut(handle).unwrap(); - material.lights = light_data.clone(); + for blacklight_material in blacklight_material_query.iter() { + let material = blacklight_materials.get_mut(&blacklight_material.0).unwrap(); + let storage_buffer = blacklight_storage_buffers.get_mut(&material.lights).unwrap(); + storage_buffer.set_data(light_data.clone()); } } -- cgit v1.2.3