Lighting fix

This commit is contained in:
Joshua Barretto 2019-06-06 12:25:06 +01:00
parent 427339cc9a
commit afd983f6f8
3 changed files with 17 additions and 12 deletions

View File

@ -26,11 +26,11 @@ impl Block {
}
}
pub fn get_opacity(&self) -> f32 {
pub fn get_opacity(&self) -> Option<f32> {
match self.kind {
0 => 0.0,
1 => 0.3,
2 => 1.0,
0 => None,
1 => Some(0.85),
2 => Some(1.0),
_ => unimplemented!(),
}
}

View File

@ -51,7 +51,7 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
for x in range.min.x + 1..range.max.x - 1 {
for y in range.min.y + 1..range.max.y - 1 {
let mut neighbour_light = [[1.0f32; 3]; 3];
let mut neighbour_light = [[(1.0f32, 0.0); 3]; 3];
for z in (range.min.z..range.max.z).rev() {
let pos = Vec3::new(x, y, z);
@ -62,7 +62,7 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
.iter()
.map(|col| col.iter())
.flatten()
.fold(0.0, |a, x| a + x)
.fold(0.0, |a, (x, _)| a + x)
/ 9.0;
let light = avg_light;
@ -85,13 +85,19 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
// Accumulate shade under opaque blocks
for i in 0..3 {
for j in 0..3 {
neighbour_light[i][j] = if let Ok(opacity) = self
let max_opacity = neighbour_light[i][j].1;
neighbour_light[i][j] = if let Some(opacity) = self
.get(pos + Vec3::new(i as i32 - 1, j as i32 - 1, 0))
.map(|vox| vox.get_opacity())
.ok()
.and_then(|vox| vox.get_opacity())
{
neighbour_light[i][j] * (1.0 - opacity * 0.5)
(
(neighbour_light[i][j].0 * (1.0 - max_opacity * 0.3))
.max(1.0 - max_opacity * 0.999),
max_opacity.max(opacity),
)
} else {
(neighbour_light[i][j] * 1.05).min(1.0)
((neighbour_light[i][j].0 * 1.02).min(1.0), max_opacity)
};
}
}

View File

@ -181,7 +181,7 @@ impl<'a> Sampler<'a> {
.mul(0.5);
// Colours
let cold_grass = Rgb::new(0.1, 0.6, 0.3);
let cold_grass = Rgb::new(0.0, 0.55, 0.15);
let warm_grass = Rgb::new(0.25, 0.8, 0.05);
let cold_stone = Rgb::new(0.55, 0.7, 0.75);
let warm_stone = Rgb::new(0.65, 0.65, 0.35);
@ -461,7 +461,6 @@ impl SimChunk {
.add(1.0)
.mul(0.5)
.mul(1.0 - chaos * 0.85)
.mul(1.2)
.add(0.1)
.mul(if alt > SEA_LEVEL + 2.0 { 1.0 } else { 0.0 }),
}