and here's the rust:
use bevy::{
prelude::*,
sprite::{Material2d, Material2dPlugin, MaterialMesh2dBundle},
render::render_resource::{AsBindGroup, ShaderRef, ShaderType},
reflect::{TypeUuid, TypePath}
};
use crate::prelude::*;
#[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone)]
#[uuid = "dc31daf2-d31e-43ae-b31a-95e5377f7f10"]
pub struct LightingMaterial {
#[uniform(0)]
light_data: LightingData,
}
#[derive(Clone, ShaderType, Debug)]
pub struct LightingData {
pub global_color: Color,
pub light_count: i32,
pub _padding: Vec3,
pub lights: [PointLight; 64],
}
impl Default for LightingData {
fn default() -> Self {
Self {
global_color: Color::Rgba { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 },
light_count: 0,
_padding: Vec3::ZERO,
lights: [PointLight::default(); 64],
}
}
}
#[derive(Default, Clone, Copy, ShaderType, Debug)]
pub struct PointLight {
pub position: Vec2,
pub radius: f32,
pub intensity: f32,
}
impl Material2d for LightingMaterial {
fn fragment_shader() -> ShaderRef {
"shaders/lighting.wgsl".into()
}
fn vertex_shader() -> ShaderRef {
"shaders/lighting.wgsl".into()
}
}