|
|
|
@ -25,15 +25,15 @@ pub struct DirectionalLight {
|
|
|
|
|
pub fov: f32,
|
|
|
|
|
pub depth: RangeCopy<f32>,
|
|
|
|
|
pub target_view: Arc<TextureView>,
|
|
|
|
|
pub pos: Position,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl DirectionalLight {
|
|
|
|
|
pub fn to_raw(&self) -> LightRaw {
|
|
|
|
|
pub fn to_raw(&self, pos: &Position) -> LightRaw {
|
|
|
|
|
use cgmath::{Deg, EuclideanSpace, Matrix4, PerspectiveFov, Point3, Vector3};
|
|
|
|
|
|
|
|
|
|
let point3d = Point3::new(self.pos.x, self.pos.y, self.pos.z);
|
|
|
|
|
let mx_view = Matrix4::look_at(point3d, Point3::origin(), Vector3::unit_y());
|
|
|
|
|
let point3d = Point3::new(pos.x, pos.y, pos.z);
|
|
|
|
|
let point3d_2 = Point3::new(pos.x, pos.y - 1.0, pos.z);
|
|
|
|
|
let mx_view = Matrix4::look_at(point3d, point3d_2, Vector3::unit_y());
|
|
|
|
|
|
|
|
|
|
let projection = PerspectiveFov {
|
|
|
|
|
fovy: Deg(self.fov).into(),
|
|
|
|
@ -46,7 +46,7 @@ impl DirectionalLight {
|
|
|
|
|
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],
|
|
|
|
|
pos: [pos.x, pos.y, pos.z, 1.0],
|
|
|
|
|
color: [
|
|
|
|
|
self.color.r as f32,
|
|
|
|
|
self.color.g as f32,
|
|
|
|
|