diff --git a/voxygen/src/mesh/segment.rs b/voxygen/src/mesh/segment.rs index 3d8657f4eb..a588c33b3d 100644 --- a/voxygen/src/mesh/segment.rs +++ b/voxygen/src/mesh/segment.rs @@ -25,14 +25,12 @@ impl Meshable for Segment { for (pos, vox) in self.full_vol_iter() { if let Some(col) = vox.get_color() { - let col = col.map(|e| e as f32 / 255.0); - vol::push_vox_verts( &mut mesh, self, pos, offs + pos.map(|e| e as f32), - &[[[Some(col); 3]; 3]; 3], + &[[[Rgba::from_opaque(col); 3]; 3]; 3], |origin, norm, col, ao, light| { FigureVertex::new( origin, @@ -62,7 +60,6 @@ impl Meshable for Segment { ls }, |vox| vox.is_empty(), - |vox| !vox.is_empty(), ); } } @@ -84,14 +81,12 @@ impl Meshable for Segment { for (pos, vox) in self.full_vol_iter() { if let Some(col) = vox.get_color() { - let col = col.map(|e| e as f32 / 255.0); - vol::push_vox_verts( &mut mesh, self, pos, offs + pos.map(|e| e as f32), - &[[[Some(col); 3]; 3]; 3], + &[[[Rgba::from_opaque(col); 3]; 3]; 3], |origin, norm, col, ao, light| { SpriteVertex::new( origin, @@ -102,7 +97,6 @@ impl Meshable for Segment { true, &[[[1.0; 3]; 3]; 3], |vox| vox.is_empty(), - |vox| !vox.is_empty(), ); } } diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index bb38183b15..6f31f622fa 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -160,10 +160,11 @@ impl + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable( - vol: &V, - pos: Vec3, +#[allow(unsafe_code)] +fn get_ao_quad( shift: Vec3, dirs: &[Vec3], darknesses: &[[[f32; 3]; 3]; 3], - is_opaque: impl Fn(&V::Vox) -> bool, ) -> Vec4<(f32, f32)> { dirs.windows(2) .map(|offs| { + let vox_opaque = |pos: Vec3| { + let pos = (pos + 1).map(|e| e as usize); + unsafe { + darknesses + .get_unchecked(pos.z) + .get_unchecked(pos.y) + .get_unchecked(pos.x) + <= &0.0 + } + }; + let (s1, s2) = ( + vox_opaque(shift + offs[0]), + vox_opaque(shift + offs[1]), + /* vol.get(pos + shift + offs[0]) .map(&is_opaque) .unwrap_or(false), vol.get(pos + shift + offs[1]) .map(&is_opaque) .unwrap_or(false), + */ ); let mut darkness = 0.0; for x in 0..2 { for y in 0..2 { let dark_pos = shift + offs[0] * x + offs[1] * y + 1; - darkness += darknesses[dark_pos.z as usize][dark_pos.y as usize] - [dark_pos.x as usize] - / 4.0; + darkness += unsafe { + darknesses + .get_unchecked(dark_pos.z as usize) + .get_unchecked(dark_pos.y as usize) + .get_unchecked(dark_pos.x as usize) + } / 4.0; } } @@ -44,10 +60,7 @@ fn get_ao_quad( if s1 && s2 { 0.0 } else { - let corner = vol - .get(pos + shift + offs[0] + offs[1]) - .map(&is_opaque) - .unwrap_or(false); + let corner = vox_opaque(shift + offs[0] + offs[1]); // Map both 1 and 2 neighbors to 0.5 occlusion. if s1 || s2 || corner { 0.5 @@ -61,32 +74,27 @@ fn get_ao_quad( } #[allow(unsafe_code)] -fn get_col_quad( - _vol: &V, - _pos: Vec3, - _shift: Vec3, - dirs: &[Vec3], - cols: &[[[Option>; 3]; 3]; 3], - _is_opaque: impl Fn(&V::Vox) -> bool, -) -> Vec4> { +fn get_col_quad(dirs: &[Vec3], cols: &[[[Rgba; 3]; 3]; 3]) -> Vec4> { dirs.windows(2) .map(|offs| { - let primary_col = cols[1][1][1].unwrap_or(Rgb::zero()); + let primary_col = Rgb::from(cols[1][1][1]).map(|e: u8| e as f32); let mut color = Rgb::zero(); let mut total = 0.0; for x in 0..2 { for y in 0..2 { let col_pos = offs[0] * x + offs[1] * y + 1; - if let Some(col) = unsafe { + let col = unsafe { cols.get_unchecked(col_pos.z as usize) .get_unchecked(col_pos.y as usize) .get_unchecked(col_pos.x as usize) - } { - if Vec3::::from(primary_col).distance_squared(Vec3::from(*col)) - < 0.25 * 0.25 + }; + if col.a > 0 { + let col = Rgb::new(col.r, col.g, col.b).map(|e| e as f32); + if Vec3::::from(primary_col).distance_squared(Vec3::from(col)) + < (0.25f32 * 256.0).powf(2.0) { - color += *col; - total += 1.0; + color += col; + total += 256.0; } } } @@ -110,7 +118,7 @@ fn create_quad, Vec3, Rgb, f32, f32) -> P let darkness = darkness_ao.map(|e| e.0); let ao = darkness_ao.map(|e| e.1); - let ao_map = ao.map(|e| e); //0.05 + e.powf(1.2) * 0.95); + let ao_map = ao; if ao[0].min(ao[2]).min(darkness[0]).min(darkness[2]) < ao[1].min(ao[3]).min(darkness[1]).min(darkness[3]) @@ -148,12 +156,11 @@ pub fn push_vox_verts( vol: &V, pos: Vec3, offs: Vec3, - cols: &[[[Option>; 3]; 3]; 3], + cols: &[[[Rgba; 3]; 3]; 3], vcons: impl Fn(Vec3, Vec3, Rgb, f32, f32) -> P::Vertex, error_makes_face: bool, darknesses: &[[[f32; 3]; 3]; 3], should_add: impl Fn(&V::Vox) -> bool, - is_opaque: impl Fn(&V::Vox) -> bool, ) { let (x, y, z) = (Vec3::unit_x(), Vec3::unit_y(), Vec3::unit_z()); @@ -168,22 +175,8 @@ pub fn push_vox_verts( Vec3::unit_z(), Vec3::unit_y(), -Vec3::unit_x(), - get_col_quad( - vol, - pos, - -Vec3::unit_x(), - &[-z, -y, z, y, -z], - cols, - &is_opaque, - ), - get_ao_quad( - vol, - pos, - -Vec3::unit_x(), - &[-z, -y, z, y, -z], - darknesses, - &is_opaque, - ), + get_col_quad(&[-z, -y, z, y, -z], cols), + get_ao_quad(-Vec3::unit_x(), &[-z, -y, z, y, -z], darknesses), &vcons, )); } @@ -198,22 +191,8 @@ pub fn push_vox_verts( Vec3::unit_y(), Vec3::unit_z(), Vec3::unit_x(), - get_col_quad( - vol, - pos, - Vec3::unit_x(), - &[-y, -z, y, z, -y], - cols, - &is_opaque, - ), - get_ao_quad( - vol, - pos, - Vec3::unit_x(), - &[-y, -z, y, z, -y], - darknesses, - &is_opaque, - ), + get_col_quad(&[-y, -z, y, z, -y], cols), + get_ao_quad(Vec3::unit_x(), &[-y, -z, y, z, -y], darknesses), &vcons, )); } @@ -228,22 +207,8 @@ pub fn push_vox_verts( Vec3::unit_x(), Vec3::unit_z(), -Vec3::unit_y(), - get_col_quad( - vol, - pos, - -Vec3::unit_y(), - &[-x, -z, x, z, -x], - cols, - &is_opaque, - ), - get_ao_quad( - vol, - pos, - -Vec3::unit_y(), - &[-x, -z, x, z, -x], - darknesses, - &is_opaque, - ), + get_col_quad(&[-x, -z, x, z, -x], cols), + get_ao_quad(-Vec3::unit_y(), &[-x, -z, x, z, -x], darknesses), &vcons, )); } @@ -258,22 +223,8 @@ pub fn push_vox_verts( Vec3::unit_z(), Vec3::unit_x(), Vec3::unit_y(), - get_col_quad( - vol, - pos, - Vec3::unit_y(), - &[-z, -x, z, x, -z], - cols, - &is_opaque, - ), - get_ao_quad( - vol, - pos, - Vec3::unit_y(), - &[-z, -x, z, x, -z], - darknesses, - &is_opaque, - ), + get_col_quad(&[-z, -x, z, x, -z], cols), + get_ao_quad(Vec3::unit_y(), &[-z, -x, z, x, -z], darknesses), &vcons, )); } @@ -288,22 +239,8 @@ pub fn push_vox_verts( Vec3::unit_y(), Vec3::unit_x(), -Vec3::unit_z(), - get_col_quad( - vol, - pos, - -Vec3::unit_z(), - &[-y, -x, y, x, -y], - cols, - &is_opaque, - ), - get_ao_quad( - vol, - pos, - -Vec3::unit_z(), - &[-y, -x, y, x, -y], - darknesses, - &is_opaque, - ), + get_col_quad(&[-y, -x, y, x, -y], cols), + get_ao_quad(-Vec3::unit_z(), &[-y, -x, y, x, -y], darknesses), &vcons, )); } @@ -318,22 +255,8 @@ pub fn push_vox_verts( Vec3::unit_x(), Vec3::unit_y(), Vec3::unit_z(), - get_col_quad( - vol, - pos, - Vec3::unit_z(), - &[-x, -y, x, y, -x], - cols, - &is_opaque, - ), - get_ao_quad( - vol, - pos, - Vec3::unit_z(), - &[-x, -y, x, y, -x], - darknesses, - &is_opaque, - ), + get_col_quad(&[-x, -y, x, y, -x], cols), + get_ao_quad(Vec3::unit_z(), &[-x, -y, x, y, -x], darknesses), &vcons, )); } diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index a2a8d0598d..1cf62479d3 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -246,7 +246,8 @@ impl WorldSim { for y in pos.y - 1..=pos.y + 1 { if x >= 0 && y >= 0 && x < WORLD_SIZE.x as i32 && y < WORLD_SIZE.y as i32 { let posi = vec2_as_uniform_idx(Vec2::new(x, y)); - if alt[posi].1.mul(CONFIG.mountain_scale) > 0.0 { + if alt[posi].1.mul(CONFIG.mountain_scale) > -8.0 { + // Account for warping in later stages return false; } }