Skip to main content

bevy_flash/
material.rs

1use bevy::{
2    asset::{Asset, Handle},
3    image::Image,
4    math::Mat4,
5    reflect::TypePath,
6    render::render_resource::{AsBindGroup, ShaderType},
7};
8use bytemuck::{Pod, Zeroable};
9
10#[derive(AsBindGroup, TypePath, Asset, Debug, Clone, Default)]
11pub struct GradientMaterial {
12    #[texture(0)]
13    #[sampler(1)]
14    pub texture: Handle<Image>,
15    #[uniform(2)]
16    pub gradient: GradientUniformsVab,
17    #[uniform(3)]
18    pub texture_transform: Mat4,
19    /// Normalized V coordinate inside a packed gradient atlas (`0.0` defaults to `0.5`).
20    pub ramp_v: f32,
21}
22
23#[repr(C)]
24#[derive(Debug, Clone, Copy, Default, ShaderType, Pod, Zeroable)]
25pub struct GradientUniformsVab {
26    pub focal_point: f32,
27    pub interpolation: i32,
28    pub shape: i32,
29    pub repeat: i32,
30    pub texture_transform: [f32; 6],
31}
32
33impl GradientUniformsVab {
34    pub fn from_vab(gu: &vatf::GradientUniforms) -> Self {
35        Self {
36            focal_point: gu.focal_point,
37            interpolation: gu.interpolation,
38            shape: gu.shape,
39            repeat: gu.repeat,
40            texture_transform: gu.texture_transform,
41        }
42    }
43}
44
45#[derive(AsBindGroup, TypePath, Asset, Debug, Clone, Default)]
46pub struct BitmapMaterial {
47    #[texture(0)]
48    #[sampler(1)]
49    pub texture: Handle<Image>,
50    #[uniform(2)]
51    pub texture_transform: Mat4,
52}