1use crate::color::{bevy_color_into_vec4, MY_BLUE_COLOR};
2use bevy::prelude::*;
3use bevy::{
4 reflect::TypePath,
5 render::render_resource::{AsBindGroup, ShaderRef},
6};
7
8#[derive(Asset, TypePath, AsBindGroup, Clone)]
26pub struct LEDMaterial {
27 #[uniform(0)]
28 color: Vec4,
29}
30
31impl LEDMaterial {
32 pub fn new(color: Color) -> Self {
33 Self {
34 color: bevy_color_into_vec4(color),
35 }
36 }
37
38 pub fn with_emission(mut self, intensity: f32) -> Self {
39 let rgb = self.color.xyz() * intensity;
40 self.color.x = rgb.x;
41 self.color.y = rgb.y;
42 self.color.z = rgb.z;
43 self
44 }
45}
46
47impl Default for LEDMaterial {
48 fn default() -> Self {
49 Self::new(MY_BLUE_COLOR).with_emission(3.0)
50 }
51}
52
53impl Material for LEDMaterial {
54 fn fragment_shader() -> ShaderRef {
55 "shaders/led.wgsl".into()
56 }
57
58 fn alpha_mode(&self) -> AlphaMode {
59 AlphaMode::Blend
60 }
61}