Fix occlusion artifact

Former-commit-id: 23be3f1173706076802809576e3455833e64b4e4
This commit is contained in:
robojumper 2019-04-29 17:06:27 +02:00
parent 7091557b82
commit 0bd84b58ec

View File

@ -15,24 +15,28 @@ fn get_ao_quad<V: ReadVol>(vol: &V, pos: Vec3<i32>, dirs: &[Vec3<i32>]) -> 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::<Vec4<f32>>()
}