diff --git a/voxygen/shaders/terrain.vert b/voxygen/shaders/terrain.vert index e7cf46b882..2a0fb39c90 100644 --- a/voxygen/shaders/terrain.vert +++ b/voxygen/shaders/terrain.vert @@ -2,9 +2,8 @@ #include -in vec3 v_pos; -in vec3 v_norm; -in vec3 v_col; +in uint v_pos; +in uint v_col_norm; layout (std140) uniform u_locals { @@ -16,12 +15,26 @@ out vec3 f_norm; out vec3 f_col; void main() { - f_pos = v_pos; - f_norm = v_norm; - f_col = v_col; + f_pos = vec3( + float((v_pos >> 0) & 0x00FFu), + float((v_pos >> 8) & 0x00FFu), + float((v_pos >> 16) & 0xFFFFu) + ); + + f_norm = vec3( + float((v_col_norm >> 0) & 0x3u), + float((v_col_norm >> 2) & 0x3u), + float((v_col_norm >> 4) & 0x3u) + ) - 1.0; + + f_col = vec3( + float((v_col_norm >> 8) & 0xFFu), + float((v_col_norm >> 16) & 0xFFu), + float((v_col_norm >> 24) & 0xFFu) + ) / 255.0; gl_Position = proj_mat * view_mat * - vec4(v_pos + model_offs, 1); + vec4(f_pos + model_offs, 1); } diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index e687afa18c..06bec4cd98 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -1,4 +1,7 @@ -// Library +use super::{ + super::{Pipeline, TgtColorFmt, TgtDepthFmt}, + Globals, +}; use gfx::{ self, gfx_constant_struct_meta, @@ -9,19 +12,13 @@ use gfx::{ gfx_pipeline_inner, gfx_vertex_struct_meta, }; +use std::ops::{Add, Div, Mul}; use vek::*; -// Local -use super::{ - super::{Pipeline, TgtColorFmt, TgtDepthFmt}, - Globals, -}; - gfx_defines! { vertex Vertex { - pos: [f32; 3] = "v_pos", - norm: [f32; 3] = "v_norm", - col: [f32; 3] = "v_col", + pos: u32 = "v_pos", + col_norm: u32 = "v_col_norm", } constant Locals { @@ -42,9 +39,17 @@ gfx_defines! { impl Vertex { pub fn new(pos: Vec3, norm: Vec3, col: Rgb) -> Self { Self { - pos: pos.into_array(), - col: col.into_array(), - norm: norm.into_array(), + pos: 0 + | ((pos.x as u32) & 0x00FF) << 0 + | ((pos.y as u32) & 0x00FF) << 8 + | ((pos.z as u32) & 0xFFFF) << 16, + col_norm: 0 + | ((col.r.mul(255.0) as u32) & 0xFF) << 8 + | ((col.g.mul(255.0) as u32) & 0xFF) << 16 + | ((col.b.mul(255.0) as u32) & 0xFF) << 24 + | ((norm.x.add(1.0) as u32) & 0x3) << 0 + | ((norm.y.add(1.0) as u32) & 0x3) << 2 + | ((norm.z.add(1.0) as u32) & 0x3) << 4, } } }