bevy_hanabi
bevy_hanabi copied to clipboard
Allow particles to be arbitrary meshes.
Allow particles to be arbitrary meshes.
Currently, Hanabi requires that particles be 2D quads. This is
sufficient for a good deal of VFX, but in many cases 3D objects are
required: smoke puffs, bullet casings, etc. This commit fixes this
deficiency by allowing particles to take on arbitrary meshes. To set the
mesh of a particle, use the new EffectAsset::mesh
builder method. By
default, the mesh is a 2D quad.
The implementation is straightforward. The previously-hard-wired quad
vertices have been replaced with a Handle<Mesh>
. The patch uses the
existing bevy_render
infrastructure to upload the mesh to the GPU and
retrieve the vertices. Perhaps the most significant change is the
generalization of rendering to allow for indexed drawing in addition to
non-indexed. Because indexed drawing has a different on-GPU format for
indirect draw commands from that of non-indirect draw commands, some
additional bookkeeping is required.
This patch also adds support for a few features useful for 3D rendering:
-
A
size3
attribute has been added, to allow the size to be controlled in 3D. -
The
SetSizeModifier
now takes a 3D size gradient instead of a 2D one. -
Vertex normals are available to modifiers via the
normal
shader variable, as long as they call the newRenderContext::set_needs_normal
method.
A new example, puffs
, has been added to demonstrate the use of 3D
meshes. It depicts the Bevy test fox running with cartoony smoke puffs
emitted at a constant rate behind it. Each puff consists of multiple
spherical mesh particles offset with some random jitter. A custom
Lambertian lighting modifier is supplied with the example, in order to
make the smoke puffs not appear solid white. (This modifier dramatically
improves the look of this example, but it's very limited, so I didn't
upstream it to Hanabi proper. A proper PBR lighting modifier would be
useful, but would be a significant amount of work, so I chose to defer
that to a follow-up.)