From e153ff5b6b93a2b0b1bf755bb01a62f37864887f Mon Sep 17 00:00:00 2001 From: nullprop Date: Sat, 15 Apr 2023 23:32:04 +0300 Subject: [PATCH] Same near&far plane for cam and lights --- src/core/camera.rs | 7 +++++-- src/core/light.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/camera.rs b/src/core/camera.rs index 18889c8..7ed2f3e 100644 --- a/src/core/camera.rs +++ b/src/core/camera.rs @@ -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, 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, }, } } diff --git a/src/core/light.rs b/src/core/light.rs index bd0eb30..e4ec017 100644 --- a/src/core/light.rs +++ b/src/core/light.rs @@ -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(),