From 899a7c56abfee88c0d6d0a6146e934c4612eb92c Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 25 Sep 2019 11:25:32 +0100 Subject: [PATCH] Dark water --- assets/voxygen/shaders/include/light.glsl | 2 +- assets/voxygen/shaders/include/sky.glsl | 2 +- voxygen/src/mesh/terrain.rs | 30 ++++++++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/assets/voxygen/shaders/include/light.glsl b/assets/voxygen/shaders/include/light.glsl index e3f4e8f915..c8f92233a7 100644 --- a/assets/voxygen/shaders/include/light.glsl +++ b/assets/voxygen/shaders/include/light.glsl @@ -12,7 +12,7 @@ uniform u_lights { vec3 illuminate(vec3 color, vec3 light, vec3 diffuse, vec3 ambience) { float avg_col = (color.r + color.g + color.b) / 3.0; - return ((color - avg_col) * light + (diffuse + ambience) * avg_col) * (diffuse); + return ((color - avg_col) * light + (diffuse + ambience) * avg_col) * diffuse; } float attenuation_strength(vec3 rpos) { diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index ccdc492607..c53a156493 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -29,7 +29,7 @@ vec3 get_sun_dir(float time_of_day) { const float PERSISTENT_AMBIANCE = 0.1; float get_sun_brightness(vec3 sun_dir) { - return max(-sun_dir.z + 0.6, 0.0); + return max(-sun_dir.z + 0.6, 0.0) * 0.8; } void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 light, out vec3 diffuse_light, out vec3 ambient_light) { diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 49987590a9..d06c6a47a5 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -47,24 +47,26 @@ fn calc_light + ReadVol + Debug>( for y in 0..outer.size().h { let mut outside = true; for z in (0..outer.size().d).rev() { - if vol + let block = vol .get(outer.min + Vec3::new(x, y, z)) - .map(|vox| vox.is_air() || vox.is_fluid()) - .unwrap_or(true) - { - if !outside { - voids.insert(Vec3::new(x, y, z), None); - } - } else if outside { + .ok() + .copied() + .unwrap_or(Block::empty()); + + if !block.is_air() && outside { rays[(outer.size().w * y + x) as usize] = z; outside = false; } + + if (block.is_air() || block.is_fluid()) && !outside { + voids.insert(Vec3::new(x, y, z), None); + } } } } let mut opens = HashSet::new(); - for (pos, l) in &mut voids { + 'voids: for (pos, l) in &mut voids { for dir in &DIRS { let col = Vec2::::from(*pos) + dir; if pos.z @@ -74,8 +76,18 @@ fn calc_light + ReadVol + Debug>( { *l = Some(sunlight - 1); opens.insert(*pos); + continue 'voids; } } + + if pos.z + >= *rays + .get(((outer.size().w * pos.y) + pos.x) as usize) + .unwrap_or(&0) + { + *l = Some(sunlight - 1); + opens.insert(*pos); + } } while opens.len() > 0 {