You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+81-11Lines changed: 81 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,31 +22,101 @@ As such, its use implies all the caveats of the above, plus the following:
22
22
*[Using SPIR-V in a bevy `Material` requires a custom `bevy` fork](https://github.com/Bevy-Rust-GPU/bevy-rust-gpu/issues/12)
23
23
*[Storage buffers are currently unsupported](https://github.com/Bevy-Rust-GPU/bevy-rust-gpu/issues/13)
24
24
25
-
Beyond that, `bevy-rust-gpu` is also in active development, but has a low user-facing API footprint.
25
+
Beyond that, `bevy-rust-gpu` is also in active development, but has a relatively small user-facing API footprint.
26
26
Major changes will be driven by development in the upstream `bevy` and `rust-gpu` crates.
27
27
28
+
In practical terms, it's able to support the hot-rebuild workflow depicted above,
29
+
and allows for relatively complex shader implementations (storage buffer issues notwithstanding), such as [a Rust reimplementation of `bevy_pbr`](https://github.com/Bevy-Rust-GPU/bevy-pbr-rust).
30
+
28
31
Currently, none of the [Bevy Rust-GPU](https://github.com/Bevy-Rust-GPU) crates are published on crates.io;
29
-
this may change as and when the major caveats are solved, but in the meantime will be hosted on github and versioned via tag.
32
+
this may change as and when the major caveats are solved, but in the meantime will be hosted on github and versioned by tag.
30
33
31
34
## Usage
32
35
33
-
First, implement a `Material` type to describe your material's bind group layout and pipeline specialization.
34
-
The vertex and fragment shaders specified here will be used as the fallback if their `rust-gpu` equivalents are not available,
35
-
so can be left to the default `Material` implementation if desired.
36
+
First, add `bevy-rust-gpu` to your `Cargo.toml`:
37
+
38
+
```toml
39
+
[dependencies]
40
+
bevy-rust-gpu = { git = "https://github.com/Bevy-Rust-GPU/bevy-rust-gpu", tag = "v0.3.0" }
41
+
```
42
+
43
+
Next, implement a `Material` type to describe your material's bind group layout and pipeline specialization:
44
+
45
+
```rust
46
+
structMyRustGpuMaterial {
47
+
#[uniform(0)]
48
+
color:Vec4,
49
+
}
50
+
51
+
// The vertex and fragment shaders specified here can be used as a fallback
52
+
// when entrypoints are unavailable (see the documentation of bevy_rust_gpu::prelude::RustGpuSettings),
53
+
// but are otherwise deferred to ShaderRef::Default, so can be left unimplemented.
54
+
implMaterialforMyRustGpuMaterial {}
55
+
```
36
56
37
57
Then, implement `RustGpuMaterial` for your `Material` type.
38
-
This will require creating marker structs to represent its vertex and fragment shaders,
39
-
and implementing the `EntryPoint` trait on them to describe entry point names and compile-time parameters.
58
+
59
+
```rust
60
+
// First, implement some marker structs to represent our shader entry points
61
+
62
+
pubenumMyVertex {}
63
+
64
+
implEntryPointforMyVertex {
65
+
constNAME:EntryPointName="vertex";
66
+
constPARAMETERS:EntryPointParameters=&[];
67
+
}
68
+
69
+
pubenumMyFragment {}
70
+
71
+
implEntryPointforMyFragment {
72
+
constNAME:EntryPointName="fragment";
73
+
constPARAMETERS:EntryPointParameters=&[];
74
+
}
75
+
76
+
// Then, impl RustGpuMaterial for our material to tie them together
77
+
78
+
implRustGpuMaterialforMyRustGpuMaterial {
79
+
typeVertex=MyVertex;
80
+
typeFragment=MyFragment;
81
+
}
82
+
```
83
+
40
84
(See [`bevy_pbr_rust.rs`](https://github.com/Bevy-Rust-GPU/bevy-rust-gpu/blob/master/src/bevy_pbr_rust.rs) for the [`bevy-pbr-rust`](https://github.com/Bevy-Rust-GPU/bevy-pbr-rust)-backed `StandardMaterial` reference implementation.)
41
85
42
86
Next, add `RustGpuPlugin` to your bevy app to configure the backend.
43
-
Currently this must occur before `RenderPlugin` is added (most often via `DefaultPlugins`), as it requires early access to `WgpuSettings` to disable storage buffer support.
87
+
88
+
```rust
89
+
letmutapp=App::default();
90
+
app.add_plugin(RustGpuPlugin); // Must be before RenderPlugin, i.e. before DefaultPlugins
91
+
app.add_plugins(DefaultPlugins);
92
+
```
44
93
45
94
For each `RustGpuMaterial` implementor, add a `RustGpuMaterialPlugin::<M>` to your app to setup rendering machinery and hot-reload / hot-rebuild support if the respective features are enabled (see below.)
46
95
47
-
When instantiating `RustGpu` materials, `RustGpuShader` handles will be required.
48
-
These are equivalent to `Handle<Shader>` with some extra hot-reloading machinery,
49
-
and can be acquired via the `AssetServer::load_rust_gpu_shader` extension method provided by the `LoadRustGpuShader` trait.
0 commit comments