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