Compare commits

..

No commits in common. "master" and "v0.1.0" have entirely different histories.

7 changed files with 1750 additions and 474 deletions

View File

@ -1,2 +0,0 @@
[profile.dev.package."*"]
opt-level = 2

View File

@ -1,25 +0,0 @@
name: Build
on: [push]
jobs:
Build:
env:
RUNNER_TOOL_CACHE: /toolcache
container: rust:alpine
steps:
- name: Install node
run: apk add nodejs gcc libc-dev pkgconf libx11-dev alsa-lib-dev eudev-dev tar
- name: Check out repository code
uses: actions/checkout@v4
- name: Restore cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --release

24
.github/workflows/rust.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: Rust
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

2110
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
[package] [package]
name = "bevy_blacklight_material" name = "bevy_blacklight_material"
description = "A blacklight material plugin for the Bevy engine" description = "A blacklight material plugin for the Bevy engine"
version = "0.2.1" version = "0.1.0"
edition = "2021" edition = "2021"
license = "0BSD OR Apache-2.0 OR MIT" license = "0BSD OR Apache-2.0 OR MIT"
repository = "https://git.exvacuum.dev/bevy_blacklight_material" repository = "https://github.com/exvacuum/bevy_blacklight_material"
[dependencies.bevy] [dependencies.bevy]
version = "0.15" version = "0.14"
default-features = false features = ["bevy_render", "bevy_asset"]
features = ["bevy_render", "bevy_asset", "bevy_pbr"]

View File

@ -14,20 +14,19 @@ Feel free to contribute if you want to improve this, it was thrown together pret
| Crate Version | Bevy Version | | Crate Version | Bevy Version |
|--- |--- | |--- |--- |
| 0.1 | 0.14 | | 0.1 | 0.14 |
| 0.2 | 0.15 |
## Installation ## Installation
### crates.io ### crates.io
```toml ```toml
[dependencies] [dependencies]
bevy_blacklight_material = "0.2" bevy_blacklight_material = "0.1"
``` ```
### Using git URL in Cargo.toml ### Using git URL in Cargo.toml
```toml ```toml
[dependencies.bevy_rustysynth] [dependencies.bevy_rustysynth]
git = "https://git.exvacuum.dev/bevy_blacklight_material" git = "https://github.com/exvacuum/bevy_blacklight_material.git"
``` ```
## Usage ## Usage
@ -48,15 +47,26 @@ fn main() {
Then you can create blacklight-emitting spotlights, and reveal-able surfaces, like this: Then you can create blacklight-emitting spotlights, and reveal-able surfaces, like this:
```rs ```rs
// Mesh with blacklight material // Mesh with blacklight material
commands.spawn(( commands.spawn(MaterialMeshBundle {
//... material: asset_server.add(BlacklightMaterial {
MeshMaterial3d(asset_server.add(BlacklightMaterial::new(&asset_server, None, Color::WHITE))), // base texture, color, etc
)); ..Default::default()
}),
..Default::default()
});
// Blacklight // Blacklight
// Requires `SpotLight`, but you might want to add one yourself commands.spawn((
commands.spawn(Blacklight); Blacklight, // Marker component
SpotLightBundle {
spot_light: SpotLight {
// outer/inner angle, range
..Default::default()
},
..Default::default()
},
));
``` ```
## License ## License

View File

@ -10,7 +10,7 @@
use bevy::{ use bevy::{
asset::embedded_asset, asset::embedded_asset,
prelude::*, prelude::*,
render::{render_resource::{AsBindGroup, ShaderType}, storage::ShaderStorageBuffer}, render::render_resource::{AsBindGroup, ShaderType},
}; };
/// Plugin which enables and updates blacklight shaders. /// Plugin which enables and updates blacklight shaders.
@ -26,7 +26,6 @@ impl Plugin for BlacklightPlugin {
/// Marker component for spot lights to use them as blacklights for [`BlacklightMaterial`]. /// Marker component for spot lights to use them as blacklights for [`BlacklightMaterial`].
#[derive(Component, Debug)] #[derive(Component, Debug)]
#[require(SpotLight)]
pub struct Blacklight; pub struct Blacklight;
/// Shader data representing a single blacklight point light. /// Shader data representing a single blacklight point light.
@ -50,7 +49,7 @@ pub struct BlacklightData {
pub struct BlacklightMaterial { pub struct BlacklightMaterial {
/// List of light data processed by this shader /// List of light data processed by this shader
#[storage(0, read_only)] #[storage(0, read_only)]
pub lights: Handle<ShaderStorageBuffer>, pub lights: Vec<BlacklightData>,
/// Base color texture which is revealed by blacklight exposure. /// Base color texture which is revealed by blacklight exposure.
#[texture(1)] #[texture(1)]
#[sampler(2)] #[sampler(2)]
@ -62,13 +61,12 @@ pub struct BlacklightMaterial {
pub alpha_mode: AlphaMode, pub alpha_mode: AlphaMode,
} }
impl BlacklightMaterial { impl Default for BlacklightMaterial {
/// Construct a new instance of this material fn default() -> Self {
pub fn new(asset_server: &AssetServer, base_texture: Option<Handle<Image>>, base_color: impl Into<LinearRgba>) -> Self {
Self { Self {
lights: asset_server.add(ShaderStorageBuffer::default()), lights: vec![],
base_texture, base_texture: None,
base_color: base_color.into(), base_color: LinearRgba::WHITE,
alpha_mode: AlphaMode::Blend, alpha_mode: AlphaMode::Blend,
} }
} }
@ -86,9 +84,8 @@ impl Material for BlacklightMaterial {
fn update_shader_blacklight_data( fn update_shader_blacklight_data(
blacklight_query: Query<(&ViewVisibility, &GlobalTransform, &SpotLight), With<Blacklight>>, blacklight_query: Query<(&ViewVisibility, &GlobalTransform, &SpotLight), With<Blacklight>>,
blacklight_material_query: Query<&MeshMaterial3d<BlacklightMaterial>>, blacklight_material_query: Query<&Handle<BlacklightMaterial>>,
mut blacklight_materials: ResMut<Assets<BlacklightMaterial>>, mut blacklight_materials: ResMut<Assets<BlacklightMaterial>>,
mut blacklight_storage_buffers: ResMut<Assets<ShaderStorageBuffer>>,
) { ) {
let light_data = blacklight_query let light_data = blacklight_query
.iter() .iter()
@ -101,9 +98,8 @@ fn update_shader_blacklight_data(
outer_angle: light.outer_angle, outer_angle: light.outer_angle,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for blacklight_material in blacklight_material_query.iter() { for handle in blacklight_material_query.iter() {
let material = blacklight_materials.get_mut(&blacklight_material.0).unwrap(); let material = blacklight_materials.get_mut(handle).unwrap();
let storage_buffer = blacklight_storage_buffers.get_mut(&material.lights).unwrap(); material.lights = light_data.clone();
storage_buffer.set_data(light_data.clone());
} }
} }