Skip to main content

mraphics_core/material/
basic.rs

1use crate::{Color, GadgetData, GadgetIndex, Material};
2
3const COLOR_UNIFORM_LABEL: &'static str = "mraphics-color-uniform";
4const COLOR_UNIFORM_INDEX: GadgetIndex = GadgetIndex {
5    group_index: 2,
6    binding_index: 0,
7};
8
9#[derive(Clone)]
10pub struct BasicMaterial {
11    pub color: Color<f32>,
12}
13
14impl BasicMaterial {
15    pub fn new() -> Self {
16        Self {
17            color: Color::from_hex_str(crate::constants::SEIYA_PINK).unwrap(),
18        }
19    }
20
21    pub fn with_color(mut self, new_color: &Color<f32>) -> Self {
22        self.color = new_color.clone();
23        self
24    }
25}
26
27impl Material for BasicMaterial {
28    fn identifier(&self) -> &str {
29        "Mraphics Basic Materil"
30    }
31
32    fn shader_code(&self) -> &str {
33        include_str!("shaders/basic.wgsl")
34    }
35
36    fn update_view(&self, view: &mut super::MaterialView) {
37        view.reset();
38
39        view.uniforms.push(GadgetData {
40            label: COLOR_UNIFORM_LABEL.to_string(),
41            index: COLOR_UNIFORM_INDEX,
42            data: bytemuck::cast_slice::<f32, u8>(&self.color).to_vec(),
43            needs_update_value: true,
44            needs_update_buffer: true,
45        });
46    }
47}