From 611b270ded34fd4a1997cad04d0151164cf96c3d Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 22 May 2019 10:42:19 +0100 Subject: [PATCH] Improved cache-coherency of world chunk interpolation Former-commit-id: 2f45cf47916970185c65c701dfc63ae838f05734 --- world/src/lib.rs | 2 +- world/src/sim.rs | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/world/src/lib.rs b/world/src/lib.rs index 38ab296511..6559e6cdbd 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -75,7 +75,7 @@ impl World { .get_interpolated(wpos2d, |chunk| chunk.get_max_z()) .unwrap_or(0.0) as i32; - for z in base_z..max_z { + for z in base_z..max_z.max(sim::SEA_LEVEL as i32) { let lpos = Vec3::new(x, y, z); let wpos = lpos + Vec3::from(chunk_pos) * TerrainChunkSize::SIZE.map(|e| e as i32); diff --git a/world/src/sim.rs b/world/src/sim.rs index fcdee446e2..d0a0284317 100644 --- a/world/src/sim.rs +++ b/world/src/sim.rs @@ -93,19 +93,18 @@ impl WorldSim { co0 * x2 * x + co1 * x2 + co2 * x + co3 }; - let mut y = [T::default(); 4]; + let mut x = [T::default(); 4]; - for (y_idx, j) in (-1..3).enumerate() { - let x0 = - f(self.get(pos.map2(Vec2::new(-1, j), |e, q| (e.max(0.0) as i32 + q) as u32))?); - let x1 = f(self.get(pos.map2(Vec2::new(0, j), |e, q| (e.max(0.0) as i32 + q) as u32))?); - let x2 = f(self.get(pos.map2(Vec2::new(1, j), |e, q| (e.max(0.0) as i32 + q) as u32))?); - let x3 = f(self.get(pos.map2(Vec2::new(2, j), |e, q| (e.max(0.0) as i32 + q) as u32))?); + for (x_idx, j) in (-1..3).enumerate() { + let y0 = f(self.get(pos.map2(Vec2::new(j, -1), |e, q| (e.max(0.0) as i32 + q) as u32))?); + let y1 = f(self.get(pos.map2(Vec2::new(j, 0), |e, q| (e.max(0.0) as i32 + q) as u32))?); + let y2 = f(self.get(pos.map2(Vec2::new(j, 1), |e, q| (e.max(0.0) as i32 + q) as u32))?); + let y3 = f(self.get(pos.map2(Vec2::new(j, 2), |e, q| (e.max(0.0) as i32 + q) as u32))?); - y[y_idx] = cubic(x0, x1, x2, x3, pos.x.fract() as f32); + x[x_idx] = cubic(y0, y1, y2, y3, pos.y.fract() as f32); } - Some(cubic(y[0], y[1], y[2], y[3], pos.y.fract() as f32)) + Some(cubic(x[0], x[1], x[2], x[3], pos.x.fract() as f32)) } pub fn sample(&self, pos: Vec2) -> Option { @@ -132,16 +131,22 @@ impl WorldSim { * 32.0 + rock * 15.0; + let wposf3d = Vec3::new(wposf.x, wposf.y, alt as f64); + + let marble = (self.gen_ctx.hill_nz.get((wposf3d.div(64.0)).into_array()) as f32) + .mul(0.5) + .add(1.0).mul(0.5); + // Colours let cold_grass = Rgb::new(0.0, 0.75, 0.25); let warm_grass = Rgb::new(0.55, 0.9, 0.0); let cold_stone = Rgb::new(0.78, 0.86, 1.0); - let warm_stone = Rgb::new(0.8, 0.7, 0.55); + let warm_stone = Rgb::new(0.72, 0.7, 0.33); let sand = Rgb::new(0.93, 0.84, 0.23); let grass = Rgb::lerp(cold_grass, warm_grass, temp); let ground = Rgb::lerp(grass, warm_stone, rock.mul(5.0).min(0.8)); - let cliff = Rgb::lerp(cold_stone, warm_stone, temp); + let cliff = Rgb::lerp(cold_stone, warm_stone, marble); Some(Sample { alt,