From bed114900f679176117e1a27005daf87e7366601 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 11 Feb 2021 01:36:42 +0000 Subject: [PATCH] Better static light propagation between translucent objects --- common/src/terrain/block.rs | 11 ++++++----- voxygen/src/mesh/terrain.rs | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index f72ef8e950..d95acc9db6 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -194,13 +194,14 @@ impl Block { } } + // minimum block, attenuation #[inline] - pub fn get_max_sunlight(&self) -> Option { + pub fn get_max_sunlight(&self) -> (u8, u8) { match self.kind() { - BlockKind::Water => Some(4), - BlockKind::Leaves => Some(10), - _ if self.is_opaque() => Some(0), - _ => None, + BlockKind::Water => (1, 1), + BlockKind::Leaves => (10, 255), + _ if self.is_opaque() => (0, 255), + _ => (0, 0), } } diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 551b3267a0..8dbf7892ae 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -71,20 +71,21 @@ fn calc_light + ReadVol + Debug>( for y in 0..outer.size().h { let mut light = SUNLIGHT; for z in (0..outer.size().d).rev() { - match vol_cached + let (min_light, attenuation) = vol_cached .get(outer.min + Vec3::new(x, y, z)) - .map_or(None, |b| b.get_max_sunlight()) - { - None => {}, - Some(0) => { - light_map[lm_idx(x, y, z)] = 0; - break; - }, - Some(max_sunlight) => light = light.min(max_sunlight), + .map_or((0, 0), |b| b.get_max_sunlight()); + + if light > min_light { + light = light.saturating_sub(attenuation).max(min_light); } light_map[lm_idx(x, y, z)] = light; - prop_que.push_back((x as u8, y as u8, z as u16)); + + if light == 0 { + break; + } else { + prop_que.push_back((x as u8, y as u8, z as u16)); + } } } }