Merge branch 'ao-artifact-fix' into 'master'

Fix ambient occlusion artifact

See merge request veloren/veloren!89

Former-commit-id: b529f9df722d8b174b0c8e5ce9ef2d32965d7294
This commit is contained in:
Forest Anderson 2019-04-29 17:00:56 +00:00
commit 3c45d3c996

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>>()
}