fixed the lights, but I somehow broke shadowing

master
mitchellhansen 4 years ago
parent da2c6a436a
commit c625dc61af

@ -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

@ -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,

@ -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),
},
},
}
}

@ -122,7 +122,7 @@ pub fn render_test(
renderer.queue.write_buffer(
&renderer.light_uniform_buf,
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
bytemuck::bytes_of(&light.to_raw()),
bytemuck::bytes_of(&light.to_raw(&pos)),
);
}
}

Loading…
Cancel
Save