should a directional light even have roll?

master
mitchellhansen 4 years ago
parent 9665a70bac
commit 9824c1ad61

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

@ -265,10 +265,15 @@ pub fn entity_loading(world: &mut World, renderer: &mut Renderer) {
let light_mesh = renderer.load_mesh_to_buffer("./resources/light.obj");
let light_entity: Entity = world.push((
cgmath::Point3 {
x: 5.0 as f32,
y: 5.0 as f32,
z: 5.0 as f32,
Position {
x: 0.0,
y: 0.0,
z: 0.0,
rot: Euler {
x: Deg(0.0),
y: Deg(-25.0),
z: Deg(0.0)
}
},
Color {
r: 1.0,

@ -23,7 +23,7 @@ use winit::window::Window;
use crate::camera::{Camera, CameraController};
use crate::components::{Color, Mesh, Position, RangeCopy};
use crate::geometry::{create_plane, import_mesh, vertex, Vertex};
use crate::light::{LightRaw, DirectionalLight};
use crate::light::{DirectionalLight, LightRaw};
#[cfg_attr(rustfmt, rustfmt_skip)]
#[allow(unused)]
@ -109,7 +109,7 @@ pub fn render_test(world: &mut SubWorld, #[resource] renderer: &mut Renderer) {
let d = Decomposed {
scale: 1.0,
rot: Quaternion::from(pos.rot),
disp: Vector3::new(pos.x, pos.y, pos.z)
disp: Vector3::new(pos.x, pos.y, pos.z),
};
let m = Matrix4::from(d);
let data = EntityUniforms {
@ -135,7 +135,7 @@ pub fn render_test(world: &mut SubWorld, #[resource] renderer: &mut Renderer) {
renderer.queue.write_buffer(
&renderer.light_uniform_buf,
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
bytemuck::bytes_of(&light.to_raw(*pos)),
bytemuck::bytes_of(&light.to_raw()),
);
}
}
@ -337,6 +337,16 @@ impl Renderer {
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),
},
},
}
}
@ -371,7 +381,6 @@ impl Renderer {
}
pub fn init(window: &Window) -> Renderer {
// Grab the GPU instance, and query its features
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
let (size, surface) = unsafe {

Loading…
Cancel
Save