Skip to content

Commit 4e14451

Browse files
authored
Add mesh tag feature to release notes. (#2081)
1 parent 095f766 commit 4e14451

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Bevy has powerful support for [automatic instancing] for any entities that share the same mesh and material. However, sometimes it can still be useful to reference data that is not the same across all instances of a material. Previously, this required either writing significant amount of custom rendering code or giving up the performance benefits of automatic instancing by creating more materials.
2+
3+
The new `MeshTag` component allows adding a custom `u32` tag to mesh-material entities that can be referenced in the vertex shader for a material. In combination with storage textures or the [`ShaderStorageBuffer` asset] added in Bevy 0.15, this provides a flexible new mechanism to access external data on a per-instance basis or otherwise tag your mesh instances.
4+
5+
Spawn a mesh tag with a mesh-material entity:
6+
```rust
7+
commands.spawn((
8+
// Clone a mesh and material handle to enable automatic instancing
9+
Mesh3d(mesh_handle.clone()),
10+
MeshMaterial3d(material_handle.clone()),
11+
// The mesh tag can be any `u32` that is meaningful to your application, like
12+
// a particular variant of an enum or an index into some external data
13+
MeshTag(1234),
14+
));
15+
```
16+
17+
Lookup the tag in a vertex shader:
18+
```wgsl
19+
#import bevy_pbr::mesh_functions
20+
21+
@vertex
22+
fn vertex(vertex: Vertex) -> VertexOutput {
23+
// Lookup the tag for the given mesh
24+
let tag = mesh_functions::get_tag(vertex.instance_index);
25+
26+
// Index into a storage buffer, read a storage texture texel, etc...
27+
}
28+
29+
```
30+
31+
[automatic instancing]: https://bevyengine.org/examples/shaders/automatic-instancing/
32+
[`ShaderStorageBuffer` asset]: https://bevyengine.org/news/bevy-0-15/#shader-storage-buffer-asset

release-content/0.16/release-notes/_release-notes.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ contributors = ["@atlv24"]
148148
prs = [17765, 16947, 16941]
149149
file_name = "virtual_geometry_improvements.md"
150150

151+
[[release_notes]]
152+
title = "Mesh tags"
153+
authors = ["@tychedelia"]
154+
contributors = []
155+
prs = [17648]
156+
file_name = "17648_mesh_tags.md"
157+
151158
# UI
152159

153160
[[release_notes]]

0 commit comments

Comments
 (0)