diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 0fb2811441..b148b6da4f 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -27,7 +27,7 @@ void main() { // Increase array access by 3 to access positive values uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u; // Use an array to avoid conditional branching - vec3 f_norm = normals[norm_axis + norm_dir]; + vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u]; vec3 light, diffuse_light, ambient_light; get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0); diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index fc557a5ffd..5154c20617 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -236,7 +236,15 @@ impl + ReadVol + Debug> Meshable, norm: Vec3, col: Rgb, light: f32) -> Self { - let (norm_axis, norm_dir) = norm - .as_slice() - .into_iter() - .enumerate() - .find(|(_i, e)| **e != 0.0) - .unwrap_or((0, &1.0)); - let norm_bits = (norm_axis << 1) | if *norm_dir > 0.0 { 1 } else { 0 }; - + pub fn new(norm_bits: u32, light: u32, pos: Vec3, col: Rgb) -> Self { Self { pos_norm: 0 | ((pos.x as u32) & 0x00FF) << 0 | ((pos.y as u32) & 0x00FF) << 8 | ((pos.z.max(0.0).min((1 << 13) as f32) as u32) & 0x1FFF) << 16 - | ((norm_bits as u32) & 0x7) << 29, + | (norm_bits & 0x7) << 29, col_light: 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 - | ((light.mul(255.0) as u32) & 0xFF) << 0, + | (light & 0xFF) << 0, } } }