From c625dc61af05db4fd979085b2eb706faf44112d5 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sat, 20 Feb 2021 21:25:38 -0800 Subject: [PATCH] fixed the lights, but I somehow broke shadowing --- conf/entity_spawns.toml | 4 ++-- src/light.rs | 10 +++++----- src/render/state.rs | 10 ---------- src/render/system.rs | 2 +- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/conf/entity_spawns.toml b/conf/entity_spawns.toml index 8d375ed..3a8dbfe 100644 --- a/conf/entity_spawns.toml +++ b/conf/entity_spawns.toml @@ -41,6 +41,6 @@ type = "Light" mesh = "light.obj" [entities.position] - x = 20.0 - y = 20.0 + x = 25.0 + y = 25.0 z = 20.0 \ No newline at end of file diff --git a/src/light.rs b/src/light.rs index 03017e0..04d1c0a 100644 --- a/src/light.rs +++ b/src/light.rs @@ -25,15 +25,15 @@ pub struct DirectionalLight { pub fov: f32, pub depth: RangeCopy, pub target_view: Arc, - 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, diff --git a/src/render/state.rs b/src/render/state.rs index bccd90f..6b65311 100644 --- a/src/render/state.rs +++ b/src/render/state.rs @@ -202,16 +202,6 @@ impl RenderState { end: 20.0, }, target_view: target.clone(), - pos: Position { - x: 0.0, - y: 0.0, - z: 0.0, - rot: Euler { - x: Deg(0.0), - y: Deg(-25.0), - z: Deg(0.0), - }, - }, } } diff --git a/src/render/system.rs b/src/render/system.rs index 489c0d2..9548e49 100644 --- a/src/render/system.rs +++ b/src/render/system.rs @@ -122,7 +122,7 @@ pub fn render_test( renderer.queue.write_buffer( &renderer.light_uniform_buf, (i * mem::size_of::()) as wgpu::BufferAddress, - bytemuck::bytes_of(&light.to_raw()), + bytemuck::bytes_of(&light.to_raw(&pos)), ); } }