veloren/voxygen/src/render/pipelines/mod.rs

136 lines
3.5 KiB
Rust
Raw Normal View History

pub mod figure;
pub mod fluid;
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;
2019-01-14 23:13:58 +00:00
pub mod terrain;
pub mod ui;
2019-01-11 20:14:37 +00:00
use super::util::arr_to_mat;
2019-08-16 14:58:14 +00:00
use common::terrain::BlockKind;
2019-01-11 20:14:37 +00:00
use gfx::{
self,
gfx_constant_struct_meta,
2019-01-11 20:14:37 +00:00
// Macros
gfx_defines,
gfx_impl_struct_meta,
};
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",
cam_pos: [f32; 4] = "cam_pos",
focus_pos: [f32; 4] = "focus_pos",
// 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",
time_of_day: [f32; 4] = "time_of_day", // TODO: Make this f64.
2019-01-14 15:47:57 +00:00
tick: [f32; 4] = "tick",
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",
2019-01-11 20:14:37 +00:00
}
2019-07-21 15:04:36 +00:00
constant Light {
pos: [f32; 4] = "light_pos",
col: [f32; 4] = "light_col",
}
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-07-21 15:04:36 +00:00
impl Globals {
/// Create global consts from the provided parameters.
pub fn new(
view_mat: Mat4<f32>,
proj_mat: Mat4<f32>,
cam_pos: Vec3<f32>,
focus_pos: Vec3<f32>,
view_distance: f32,
time_of_day: f64,
2019-01-14 15:47:57 +00:00
tick: f64,
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>>,
) -> Self {
Self {
view_mat: arr_to_mat(view_mat.into_col_array()),
proj_mat: arr_to_mat(proj_mat.into_col_array()),
cam_pos: Vec4::from(cam_pos).into_array(),
focus_pos: Vec4::from(focus_pos).into_array(),
view_distance: [view_distance; 4],
time_of_day: [time_of_day as f32; 4],
2019-01-14 15:47:57 +00:00
tick: [tick as f32; 4],
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(),
}
}
}
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,
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
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 {
fn default() -> Self {
Self::new(Vec3::zero(), Rgb::zero(), 0.0)
}
}
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 {
fn default() -> Self {
Self::new(Vec3::zero(), 0.0)
}
}