2019-01-13 20:53:55 +00:00
|
|
|
pub mod figure;
|
2019-08-14 21:28:37 +00:00
|
|
|
pub mod fluid;
|
2019-05-06 08:22:47 +00:00
|
|
|
pub mod postprocess;
|
2019-01-11 20:14:37 +00:00
|
|
|
pub mod skybox;
|
2019-08-19 17:01:23 +00:00
|
|
|
pub mod sprite;
|
2020-06-30 14:29:35 +00:00
|
|
|
pub mod particle;
|
2019-01-14 23:13:58 +00:00
|
|
|
pub mod terrain;
|
2019-01-30 12:11:34 +00:00
|
|
|
pub mod ui;
|
2019-01-11 20:14:37 +00:00
|
|
|
|
2020-04-04 19:36:55 +00:00
|
|
|
use crate::scene::camera::CameraMode;
|
2019-08-16 14:58:14 +00:00
|
|
|
use common::terrain::BlockKind;
|
2020-02-01 20:39:39 +00:00
|
|
|
use gfx::{self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta};
|
2019-01-11 23:18:34 +00:00
|
|
|
use vek::*;
|
2019-01-11 20:14:37 +00:00
|
|
|
|
|
|
|
gfx_defines! {
|
|
|
|
constant Globals {
|
|
|
|
view_mat: [[f32; 4]; 4] = "view_mat",
|
|
|
|
proj_mat: [[f32; 4]; 4] = "proj_mat",
|
2020-01-21 12:57:59 +00:00
|
|
|
all_mat: [[f32; 4]; 4] = "all_mat",
|
2019-01-11 20:14:37 +00:00
|
|
|
cam_pos: [f32; 4] = "cam_pos",
|
|
|
|
focus_pos: [f32; 4] = "focus_pos",
|
2019-05-17 09:22:32 +00:00
|
|
|
// TODO: Fix whatever alignment issue requires these uniforms to be aligned.
|
2019-01-11 20:14:37 +00:00
|
|
|
view_distance: [f32; 4] = "view_distance",
|
2019-05-17 09:22:32 +00:00
|
|
|
time_of_day: [f32; 4] = "time_of_day", // TODO: Make this f64.
|
2019-01-14 15:47:57 +00:00
|
|
|
tick: [f32; 4] = "tick",
|
2019-05-07 10:27:52 +00:00
|
|
|
screen_res: [f32; 4] = "screen_res",
|
2019-09-25 12:00:00 +00:00
|
|
|
light_shadow_count: [u32; 4] = "light_shadow_count",
|
2019-08-16 14:58:14 +00:00
|
|
|
medium: [u32; 4] = "medium",
|
2019-09-26 10:43:03 +00:00
|
|
|
select_pos: [i32; 4] = "select_pos",
|
2020-02-13 12:28:03 +00:00
|
|
|
gamma: [f32; 4] = "gamma",
|
2020-04-04 19:36:55 +00:00
|
|
|
cam_mode: u32 = "cam_mode",
|
2020-04-25 13:04:30 +00:00
|
|
|
sprite_render_distance: f32 = "sprite_render_distance",
|
2020-06-30 14:29:35 +00:00
|
|
|
particle_render_distance: f32 = "particle_render_distance",
|
2019-01-11 20:14:37 +00:00
|
|
|
}
|
2019-01-11 23:18:34 +00:00
|
|
|
|
2019-07-21 15:04:36 +00:00
|
|
|
constant Light {
|
|
|
|
pos: [f32; 4] = "light_pos",
|
|
|
|
col: [f32; 4] = "light_col",
|
2019-01-11 23:18:34 +00:00
|
|
|
}
|
2019-09-25 12:00:00 +00:00
|
|
|
|
|
|
|
constant Shadow {
|
|
|
|
pos_radius: [f32; 4] = "shadow_pos_radius",
|
|
|
|
}
|
2019-07-21 15:04:36 +00:00
|
|
|
}
|
2019-01-12 01:14:58 +00:00
|
|
|
|
2019-07-21 15:04:36 +00:00
|
|
|
impl Globals {
|
2019-01-12 01:14:58 +00:00
|
|
|
/// Create global consts from the provided parameters.
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587
|
|
|
|
#[allow(clippy::too_many_arguments)] // TODO: Pending review in #587
|
2019-01-12 01:14:58 +00:00
|
|
|
pub fn new(
|
|
|
|
view_mat: Mat4<f32>,
|
|
|
|
proj_mat: Mat4<f32>,
|
|
|
|
cam_pos: Vec3<f32>,
|
|
|
|
focus_pos: Vec3<f32>,
|
|
|
|
view_distance: f32,
|
2019-01-12 15:57:19 +00:00
|
|
|
time_of_day: f64,
|
2019-01-14 15:47:57 +00:00
|
|
|
tick: f64,
|
2019-05-07 10:27:52 +00:00
|
|
|
screen_res: Vec2<u16>,
|
2019-07-21 15:04:36 +00:00
|
|
|
light_count: usize,
|
2019-09-25 12:00:00 +00:00
|
|
|
shadow_count: usize,
|
2019-08-16 14:58:14 +00:00
|
|
|
medium: BlockKind,
|
2019-09-26 10:43:03 +00:00
|
|
|
select_pos: Option<Vec3<i32>>,
|
2020-02-13 12:28:03 +00:00
|
|
|
gamma: f32,
|
2020-04-04 19:36:55 +00:00
|
|
|
cam_mode: CameraMode,
|
2020-04-25 13:04:30 +00:00
|
|
|
sprite_render_distance: f32,
|
2020-06-30 14:29:35 +00:00
|
|
|
particle_render_distance: f32,
|
2019-01-12 01:14:58 +00:00
|
|
|
) -> Self {
|
|
|
|
Self {
|
2020-06-17 07:49:14 +00:00
|
|
|
view_mat: view_mat.into_col_arrays(),
|
|
|
|
proj_mat: proj_mat.into_col_arrays(),
|
|
|
|
all_mat: (proj_mat * view_mat).into_col_arrays(),
|
2019-01-12 01:14:58 +00:00
|
|
|
cam_pos: Vec4::from(cam_pos).into_array(),
|
|
|
|
focus_pos: Vec4::from(focus_pos).into_array(),
|
|
|
|
view_distance: [view_distance; 4],
|
2019-01-12 15:57:19 +00:00
|
|
|
time_of_day: [time_of_day as f32; 4],
|
2019-01-14 15:47:57 +00:00
|
|
|
tick: [tick as f32; 4],
|
2019-05-07 10:27:52 +00:00
|
|
|
screen_res: Vec4::from(screen_res.map(|e| e as f32)).into_array(),
|
2019-09-25 12:00:00 +00:00
|
|
|
light_shadow_count: [light_count as u32, shadow_count as u32, 0, 0],
|
2019-08-16 14:58:14 +00:00
|
|
|
medium: [if medium.is_fluid() { 1 } else { 0 }; 4],
|
2019-09-26 10:43:03 +00:00
|
|
|
select_pos: select_pos
|
|
|
|
.map(|sp| Vec4::from(sp) + Vec4::unit_w())
|
|
|
|
.unwrap_or(Vec4::zero())
|
|
|
|
.into_array(),
|
2020-02-13 12:28:03 +00:00
|
|
|
gamma: [gamma; 4],
|
2020-04-04 19:36:55 +00:00
|
|
|
cam_mode: cam_mode as u32,
|
2020-04-25 13:04:30 +00:00
|
|
|
sprite_render_distance,
|
2020-06-30 14:29:35 +00:00
|
|
|
particle_render_distance,
|
2019-01-12 01:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-11 23:18:34 +00:00
|
|
|
}
|
2019-07-21 15:04:36 +00:00
|
|
|
|
|
|
|
impl Default for Globals {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new(
|
|
|
|
Mat4::identity(),
|
|
|
|
Mat4::identity(),
|
|
|
|
Vec3::zero(),
|
|
|
|
Vec3::zero(),
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
Vec2::new(800, 500),
|
|
|
|
0,
|
2019-09-25 12:00:00 +00:00
|
|
|
0,
|
2019-08-16 14:58:14 +00:00
|
|
|
BlockKind::Air,
|
2019-09-26 10:43:03 +00:00
|
|
|
None,
|
2020-02-13 12:28:03 +00:00
|
|
|
1.0,
|
2020-04-04 19:36:55 +00:00
|
|
|
CameraMode::ThirdPerson,
|
2020-04-25 13:04:30 +00:00
|
|
|
250.0,
|
2020-06-30 14:29:35 +00:00
|
|
|
250.0,
|
2019-07-21 15:04:36 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Light {
|
|
|
|
pub fn new(pos: Vec3<f32>, col: Rgb<f32>, strength: f32) -> Self {
|
|
|
|
Self {
|
|
|
|
pos: Vec4::from(pos).into_array(),
|
|
|
|
col: Rgba::new(col.r, col.g, col.b, strength).into_array(),
|
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:00:00 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn get_pos(&self) -> Vec3<f32> { Vec3::new(self.pos[0], self.pos[1], self.pos[2]) }
|
2019-07-21 15:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Light {
|
2020-02-01 20:39:39 +00:00
|
|
|
fn default() -> Self { Self::new(Vec3::zero(), Rgb::zero(), 0.0) }
|
2019-07-21 15:04:36 +00:00
|
|
|
}
|
2019-09-25 12:00:00 +00:00
|
|
|
|
|
|
|
impl Shadow {
|
|
|
|
pub fn new(pos: Vec3<f32>, radius: f32) -> Self {
|
|
|
|
Self {
|
|
|
|
pos_radius: [pos.x, pos.y, pos.z, radius],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_pos(&self) -> Vec3<f32> {
|
|
|
|
Vec3::new(self.pos_radius[0], self.pos_radius[1], self.pos_radius[2])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Shadow {
|
2020-02-01 20:39:39 +00:00
|
|
|
fn default() -> Self { Self::new(Vec3::zero(), 0.0) }
|
2019-09-25 12:00:00 +00:00
|
|
|
}
|