use bytemuck::__core::ops::Range; use bytemuck::{Zeroable, Pod}; use crate::OPENGL_TO_WGPU_MATRIX; pub struct Light { pos: cgmath::Point3, color: wgpu::Color, fov: f32, depth: Range, target_view: wgpu::TextureView, } #[repr(C)] #[derive(Clone, Copy)] pub struct LightRaw { proj: [[f32; 4]; 4], pos: [f32; 4], color: [f32; 4], } unsafe impl Pod for LightRaw {} unsafe impl Zeroable for LightRaw {} impl Light { fn to_raw(&self) -> LightRaw { use cgmath::{Deg, EuclideanSpace, Matrix4, PerspectiveFov, Point3, Vector3}; let mx_view = Matrix4::look_at(self.pos, Point3::origin(), Vector3::unit_z()); let projection = PerspectiveFov { fovy: Deg(self.fov).into(), aspect: 1.0, near: self.depth.start, far: self.depth.end, }; let mx_correction = OPENGL_TO_WGPU_MATRIX; let mx_view_proj = mx_correction * cgmath::Matrix4::from(projection.to_perspective()) * mx_view; LightRaw { proj: *mx_view_proj.as_ref(), pos: [self.pos.x, self.pos.y, self.pos.z, 1.0], color: [ self.color.r as f32, self.color.g as f32, self.color.b as f32, 1.0, ], } } }