Enoki - A 2D particle system for the Bevy game engine.
Overview
The Enoki particle system is a CPU calculate particle system, that uses GPU Instancing and works well in wasm
and mobile.
You have access to a Material Trait
which let's you implement your own
fragment shaders on top. Resulting in a powerful tool to build any modern VFX effect.
Additionally, spawner configuration are provided via ron
files, which can be hot reloaded.
The default material allows not only for custom textures, but also sprite sheet animations over the particle lifetime.
Compatibility
bevy | bevy_enoki |
---|---|
0.16 | 0.4 |
0.15 | 0.3.3 |
0.14 | 0.2.2 |
0.13 | 0.1 |
Editor
Enoki has a feature rich Editor.
- load and save effect assets.
- watch a shader file with hot reload, your editor of choice.
- load a texture.
- play with values.
Get started by installing it via cargo
cargo install enoki2d_editor
Examples
cargo run -p example --bin material
cargo run -p example --bin sprites
cargo run -p example --bin dynamic
Usage
Add the bevy_enoki
dependency to your Cargo.toml
= "0.2.2"
Add the EnokiPlugin
to your app
.add_plugins
.add_plugins
.run
new
Create your first particle spawner.
use *;
Control your particles
There 4 main components you can play with. These are required by the ParticleSpawner
and thus added, if not provided.
ParticleSpawnerState
: Controls the spawner state.ParticleEffectInstance
: A unique clone of the effect. Can be changed at runtime, only affects the spawner attached to. Will reload, when the asset changes.ParticleEffectHandle
: A link the main effect asset.ParticleStore
: Holds the particle data. You mostly won't interact with this.OneShot
: A optional Tag component. That will either deactivate or delete the spawner, after first burst is done.NoAutoAabb
: Opt out of auto Aabb calculation.
Create a custom Material
Just like any other Bevy material, you can define your own fragment shader.
Create a shader
//assets/custom_material.wgsl
#import bevy_enoki::particle_vertex_out::{ VertexOutput }
@group(1) @binding(0) var texture: texture_2d<f32>;
@group(1) @binding(1) var texture_sampler: sampler;
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
var out = in.color
// go wild
return out;
}
That's it, now add the Material to your Spawner! These are the values provided by the vertex shader:
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
@location(0) @interpolate(flat) color: vec4<f32>,
@location(1) uv : vec2<f32>,
@location(2) lifetime_frac : f32,
@location(3) lifetime_total : f32,
};
The Effect Asset
This how you create a MultiCurve
. Currently, Supports LinearRgba
and f32
.
RVal
stands for any Value with a randomness property between 0 - 1.
let curve = new
.with_point
.with_point;
// max 1.0, randomness of 0.1 (0.9 - 1.1)
let rval = new;