uncommented and fixed the lights, but everything still is mega-dark

This commit is contained in:
2021-02-03 22:56:38 -08:00
parent 80ac21e9d3
commit 8d7a62da7f
4 changed files with 150 additions and 301 deletions

View File

@@ -1,13 +1,7 @@
use bytemuck::__core::ops::Range;
use bytemuck::{Zeroable, Pod};
use crate::OPENGL_TO_WGPU_MATRIX;
use crate::{OPENGL_TO_WGPU_MATRIX, DirectionalLight, Position};
pub struct Light {
pub(crate) pos: cgmath::Point3<f32>,
pub(crate) color: wgpu::Color,
pub(crate) fov: f32,
pub(crate) depth: Range<f32>,
}
#[repr(C)]
#[derive(Clone, Copy)]
@@ -21,11 +15,12 @@ unsafe impl Pod for LightRaw {}
unsafe impl Zeroable for LightRaw {}
impl Light {
fn to_raw(&self) -> LightRaw {
impl DirectionalLight {
pub fn to_raw(&self, pos: Position) -> LightRaw {
use cgmath::{Deg, EuclideanSpace, Matrix4, PerspectiveFov, Point3, Vector3};
let mx_view = Matrix4::look_at(self.pos, Point3::origin(), Vector3::unit_z());
let pos = cgmath::Point3::new(pos.x, pos.y, pos.z);
let mx_view = Matrix4::look_at(pos, Point3::origin(), Vector3::unit_z());
let projection = PerspectiveFov {
fovy: Deg(self.fov).into(),
aspect: 1.0,
@@ -37,7 +32,7 @@ impl Light {
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,