wip
This commit is contained in:
parent
965aa40858
commit
d511a39178
3 changed files with 121 additions and 5 deletions
88
Cargo.lock
generated
88
Cargo.lock
generated
|
|
@ -400,6 +400,7 @@ dependencies = [
|
|||
"futures-io",
|
||||
"futures-lite",
|
||||
"js-sys",
|
||||
"notify-debouncer-full",
|
||||
"parking_lot",
|
||||
"ron",
|
||||
"serde",
|
||||
|
|
@ -1971,6 +1972,15 @@ dependencies = [
|
|||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "file-id"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1fc6a637b6dc58414714eddd9170ff187ecb0933d4c7024d1abbd23a3cc26e9"
|
||||
dependencies = [
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.5.7"
|
||||
|
|
@ -2058,6 +2068,15 @@ version = "0.3.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
|
||||
|
||||
[[package]]
|
||||
name = "fsevent-sys"
|
||||
version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.31"
|
||||
|
|
@ -2535,6 +2554,26 @@ version = "3.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
||||
|
||||
[[package]]
|
||||
name = "kqueue"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eac30106d7dce88daf4a3fcb4879ea939476d5074a9b7ddd0fb97fa4bed5596a"
|
||||
dependencies = [
|
||||
"kqueue-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kqueue-sys"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ktx2"
|
||||
version = "0.3.0"
|
||||
|
|
@ -2711,6 +2750,18 @@ dependencies = [
|
|||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi 0.11.1+wasi-snapshot-preview1",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "naga"
|
||||
version = "24.0.0"
|
||||
|
|
@ -2847,6 +2898,43 @@ version = "0.5.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51"
|
||||
|
||||
[[package]]
|
||||
name = "notify"
|
||||
version = "8.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"fsevent-sys",
|
||||
"inotify",
|
||||
"kqueue",
|
||||
"libc",
|
||||
"log",
|
||||
"mio",
|
||||
"notify-types",
|
||||
"walkdir",
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "notify-debouncer-full"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2d88b1a7538054351c8258338df7c931a590513fb3745e8c15eb9ff4199b8d1"
|
||||
dependencies = [
|
||||
"file-id",
|
||||
"log",
|
||||
"notify",
|
||||
"notify-types",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "notify-types"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d"
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.4.1"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
[package]
|
||||
name = "bevy_test"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
edition = "2024"
|
||||
name = "bevy_test"
|
||||
version = "0.1.0"
|
||||
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.16.1"
|
||||
bevy = { version = "0.16.1", features = ["file_watcher"] }
|
||||
|
|
|
|||
30
src/main.rs
30
src/main.rs
|
|
@ -1,10 +1,11 @@
|
|||
//! A shader that uses the WGSL shading language.
|
||||
|
||||
use bevy::{
|
||||
asset::AssetEvent,
|
||||
input::common_conditions::*,
|
||||
prelude::*,
|
||||
reflect::TypePath,
|
||||
render::render_resource::{AsBindGroup, ShaderRef},
|
||||
render::render_resource::{AsBindGroup, Shader, ShaderRef},
|
||||
sprite::{AlphaMode2d, Material2d, Material2dPlugin},
|
||||
window::{PrimaryWindow, WindowMode},
|
||||
};
|
||||
|
|
@ -23,6 +24,7 @@ fn main() {
|
|||
(
|
||||
update_material_time,
|
||||
resize_fullscreen_quad,
|
||||
shader_hot_reload,
|
||||
exit_app.run_if(input_just_pressed(KeyCode::Escape)),
|
||||
toggle_fullscreen.run_if(input_just_pressed(KeyCode::F11)),
|
||||
),
|
||||
|
|
@ -88,6 +90,32 @@ fn toggle_fullscreen(mut primary_window: Single<&mut Window, With<PrimaryWindow>
|
|||
};
|
||||
}
|
||||
|
||||
/// Listen for shader asset changes and force materials to update so the new shader is used.
|
||||
fn shader_hot_reload(
|
||||
mut shader_events: EventReader<AssetEvent<Shader>>,
|
||||
mut materials: ResMut<Assets<CustomMaterial>>,
|
||||
) {
|
||||
let mut reload_needed = false;
|
||||
for event in shader_events.read() {
|
||||
match event {
|
||||
AssetEvent::Modified { .. } => {
|
||||
info!("shader changed: {event:?}");
|
||||
reload_needed = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if reload_needed {
|
||||
// iterate all materials and 'touch' them so Bevy updates bindings using the recompiled shader
|
||||
for (_handle, material) in materials.iter_mut() {
|
||||
// assign to itself to mark changed
|
||||
let cloned = material.clone();
|
||||
*material = cloned;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is the struct that will be passed to your shader
|
||||
#[derive(Asset, TypePath, AsBindGroup, Clone)]
|
||||
struct CustomMaterial {
|
||||
|
|
|
|||
Loading…
Reference in a new issue