should a directional light even have roll?
This commit is contained in:
12
src/light.rs
12
src/light.rs
@@ -4,7 +4,7 @@ use cgmath::Point3;
|
||||
use crate::render::OPENGL_TO_WGPU_MATRIX;
|
||||
use std::sync::Arc;
|
||||
use wgpu::TextureView;
|
||||
use crate::components::RangeCopy;
|
||||
use crate::components::{RangeCopy, Position};
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
@@ -25,14 +25,16 @@ 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, pos: Point3<f32>) -> LightRaw {
|
||||
pub fn to_raw(&self) -> LightRaw {
|
||||
use cgmath::{Deg, EuclideanSpace, Matrix4, PerspectiveFov, Point3, Vector3};
|
||||
|
||||
//let pos = cgmath::Point3::new(pos.x, pos.y, pos.z);
|
||||
let mx_view = Matrix4::look_at(pos, Point3::origin(), Vector3::unit_z());
|
||||
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 projection = PerspectiveFov {
|
||||
fovy: Deg(self.fov).into(),
|
||||
aspect: 1.0,
|
||||
@@ -44,7 +46,7 @@ impl DirectionalLight {
|
||||
mx_correction * cgmath::Matrix4::from(projection.to_perspective()) * mx_view;
|
||||
LightRaw {
|
||||
proj: *mx_view_proj.as_ref(),
|
||||
pos: [pos.x, pos.y, pos.z, 1.0],
|
||||
pos: [self.pos.x, self.pos.y, self.pos.z, 1.0],
|
||||
color: [
|
||||
self.color.r as f32,
|
||||
self.color.g as f32,
|
||||
|
||||
Reference in New Issue
Block a user