docs/bevy/release-content/release-notes/sprite_materials.md 1.1 K · 26 lines · raw · history

1 ---
2 title: Sprite materials
3 authors: ["@cookie1170"]
4 pull_requests: [25415]
5 ---
6
7 **TODO: Add recording showcasing the `sprite_material` example**
8
9 Until now, Bevy's sprite renderer has been lacking a major feature: the ability to extend it with custom shaders!
10 With this release, it's now possible to create custom materials for sprites by implementing the `MaterialExtension2d` trait,
11 inserting the `SpriteMaterial` component and adding the `SpriteMaterialPlugin` to your app.
12
13 The shader can use functions exported from `bevy_sprite_render::sprite_mesh::functions`, including:
14
15 ```wesl
16 // Samples the sprite's final color, including the tint and alpha discard, at a given UV.
17 fn sample_final_color(uv: vec2<f32>, instance_index: u32) -> vec4<f32>;
18
19 // Samples the sprite's texture without tint and alpha discard at a given UV.
20 fn sample_sprite_texture(uv: vec2<f32>, instance_index: u32) -> vec4<f32>;
21
22 // Applies tint and alpha discard to the sprite's color.
23 fn get_final_color(sprite_color: vec4<f32>, instance_index: u32) -> vec4<f32>;
24 ```
25
26 Check out the `sprite_material` example to see it in action!