From 0bd84b58ec3e5c6171785e6f8ed35d73d7b63b35 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 29 Apr 2019 17:06:27 +0200 Subject: [PATCH] Fix occlusion artifact Former-commit-id: 23be3f1173706076802809576e3455833e64b4e4 --- voxygen/src/mesh/vol.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/voxygen/src/mesh/vol.rs b/voxygen/src/mesh/vol.rs index ea47d9bde5..e24279bbb7 100644 --- a/voxygen/src/mesh/vol.rs +++ b/voxygen/src/mesh/vol.rs @@ -15,24 +15,28 @@ fn get_ao_quad(vol: &V, pos: Vec3, dirs: &[Vec3]) -> Vec4< .map(|offs| { let (s1, s2) = ( vol.get(pos + offs[0]) - .map(|v| v.is_empty() as i32) - .unwrap_or(1), + .map(|v| !v.is_empty()) + .unwrap_or(false), vol.get(pos + offs[1]) - .map(|v| v.is_empty() as i32) - .unwrap_or(1), + .map(|v| !v.is_empty()) + .unwrap_or(false), ); - if s1 == 0 && s2 == 0 { - 0 + if s1 && s2 { + 0.0 } else { let corner = vol .get(pos + offs[0] + offs[1]) - .map(|v| v.is_empty() as i32) - .unwrap_or(1); - s1 + s2 + corner + .map(|v| !v.is_empty()) + .unwrap_or(false); + // Map both 1 and 2 neighbors to 0.5 occlusion + if s1 || s2 || corner { + 0.5 + } else { + 1.0 + } } }) - .map(|i| i as f32 / 3.0) .collect::>() }