Same near&far plane for cam and lights

This commit is contained in:
Lauri Räsänen 2023-04-15 23:32:04 +03:00
parent b978091cd4
commit e153ff5b6b
2 changed files with 7 additions and 4 deletions

View file

@ -3,6 +3,9 @@ use std::time::Duration;
use cgmath::num_traits::clamp;
use winit::{dpi::PhysicalPosition, event::*};
pub const NEAR_PLANE: f32 = 0.1;
pub const FAR_PLANE: f32 = 3000.0;
pub struct Camera {
pub position: cgmath::Point3<f32>,
pub pitch: f32,
@ -42,8 +45,8 @@ impl Camera {
projection: PerspectiveProjection {
aspect,
fovy,
znear: 0.1,
zfar: 3000.0,
znear: NEAR_PLANE,
zfar: FAR_PLANE,
},
}
}

View file

@ -1,6 +1,6 @@
use std::ops::Range;
use super::model::{Mesh, Model};
use super::{model::{Mesh, Model}, camera::{NEAR_PLANE, FAR_PLANE}};
use cgmath::{Matrix4, Vector3};
@ -15,7 +15,7 @@ pub struct LightUniform {
impl LightUniform {
pub fn new(position: [f32; 3], color: [f32; 4]) -> Self {
let proj = cgmath::perspective(cgmath::Deg(90.0), 1.0, 0.1, 1000.0);
let proj = cgmath::perspective(cgmath::Deg(90.0), 1.0, NEAR_PLANE, FAR_PLANE);
#[rustfmt::skip]
let matrices: [[[f32; 4]; 4]; 6] = [
(proj * Matrix4::look_to_rh(position.into(), Vector3::new( 1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0))).into(),