Added water, beaches, craggs

Former-commit-id: 0213bbac23cf01df31896461d0cdda3b0ee708dc
This commit is contained in:
Joshua Barretto 2019-05-21 22:50:12 +01:00
parent dcd2b4392d
commit 8909a4220f
2 changed files with 40 additions and 38 deletions

View File

@ -43,16 +43,9 @@ impl World {
let sand = Block::new(4, Rgb::new(180, 150, 50)); let sand = Block::new(4, Rgb::new(180, 150, 50));
let water = Block::new(5, Rgb::new(100, 150, 255)); let water = Block::new(5, Rgb::new(100, 150, 255));
let warp_nz = Perlin::new().set_seed(self.sim.seed + 0); let warp_nz = BasicMulti::new()
let temp_nz = Perlin::new().set_seed(self.sim.seed + 1); .set_octaves(3)
/* .set_seed(self.sim.seed + 0);
let cliff_nz = BasicMulti::new()
.set_octaves(2)
.set_seed(self.sim.seed + 2);
let cliff_mask_nz = BasicMulti::new()
.set_octaves(4)
.set_seed(self.sim.seed + 3);
*/
let base_z = match self.sim.get_base_z(chunk_pos.map(|e| e as u32)) { let base_z = match self.sim.get_base_z(chunk_pos.map(|e| e as u32)) {
Some(base_z) => base_z as i32, Some(base_z) => base_z as i32,
@ -68,6 +61,7 @@ impl World {
let sim::Sample { let sim::Sample {
alt, alt,
chaos,
surface_color surface_color
} = if let Some(sample) = self.sim.sample(wpos2d) { } = if let Some(sample) = self.sim.sample(wpos2d) {
sample sample
@ -85,31 +79,22 @@ impl World {
+ Vec3::from(chunk_pos) * TerrainChunkSize::SIZE.map(|e| e as i32); + Vec3::from(chunk_pos) * TerrainChunkSize::SIZE.map(|e| e as i32);
let wposf = wpos.map(|e| e as f64); let wposf = wpos.map(|e| e as f64);
/* let warp = (warp_nz.get((wposf.div(Vec3::new(120.0, 120.0, 150.0))).into_array()) as f32)
let cliff_mask = cliff_mask_nz.get((wposf.div(Vec3::new(512.0, 512.0, 2048.0))).into_array()) .mul((chaos - 0.1).max(0.0))
.sub(0.1) .mul(90.0);
.max(0.0)
.mul(1.5)
.round() as f32;
let cliff = (cliff_nz.get((wposf.div(Vec3::new(256.0, 256.0, 128.0))).into_array()) as f32)
.mul(cliff_mask)
//.mul((30.0).div((wposf.z as f32 - alt)).max(0.0))
.mul(150.0)
.min(64.0);
*/
let height = alt;// + cliff; let height = alt + warp;
let temp = 0.0; let temp = 0.0;
let z = wposf.z as f32; let z = wposf.z as f32;
let _ = chunk.set( let _ = chunk.set(
lpos, lpos,
if z < height - 6.0 { if z < height - 4.0 {
stone stone
} else if z < height - 2.0 {
dirt
} else if z < height { } else if z < height {
Block::new(1, surface_color.map(|e| (e * 255.0) as u8)) Block::new(1, surface_color.map(|e| (e * 255.0) as u8))
} else if z < sim::SEA_LEVEL {
water
} else { } else {
air air
}, },

View File

@ -124,34 +124,48 @@ impl WorldSim {
let temp = self.get_interpolated(pos, |chunk| chunk.temp)?; let temp = self.get_interpolated(pos, |chunk| chunk.temp)?;
let rockiness = self.get_interpolated(pos, |chunk| chunk.rockiness)?; let rockiness = self.get_interpolated(pos, |chunk| chunk.rockiness)?;
let rock = (self.gen_ctx.small_nz.get((wposf.div(200.0)).into_array()) as f32) let rock = (self.gen_ctx.small_nz.get((wposf.div(100.0)).into_array()) as f32)
.mul(rockiness) .mul(rockiness)
.sub(0.3) .sub(0.2)
.max(0.0) .max(0.0)
.mul(2.5); .mul(2.0);
let alt = self.get_interpolated(pos, |chunk| chunk.alt)? let alt = self.get_interpolated(pos, |chunk| chunk.alt)?
+ self.gen_ctx.small_nz.get((wposf.div(128.0)).into_array()) as f32 * chaos.max(0.2) * 32.0 + self.gen_ctx.small_nz.get((wposf.div(128.0)).into_array()) as f32 * chaos.max(0.15) * 32.0
+ rock * 30.0; + rock * 15.0;
// Colours // Colours
let cold_grass = Rgb::new(0.0, 0.75, 0.25); let cold_grass = Rgb::new(0.0, 0.75, 0.25);
let warm_grass = Rgb::new(0.55, 0.9, 0.0); let warm_grass = Rgb::new(0.55, 0.9, 0.0);
let stone = Rgb::new(0.8, 0.7, 0.551); let cold_stone = Rgb::new(0.78, 0.86, 1.0);
let warm_stone = Rgb::new(0.8, 0.7, 0.55);
let sand = Rgb::new(0.93, 0.84, 0.23);
let grass = Rgb::lerp(cold_grass, warm_grass, temp); let grass = Rgb::lerp(cold_grass, warm_grass, temp);
let ground = Rgb::lerp(grass, stone, rock.mul(5.0).min(0.8)); let ground = Rgb::lerp(grass, warm_stone, rock.mul(5.0).min(0.8));
let cliff = stone; let cliff = Rgb::lerp(cold_stone, warm_stone, temp);
Some(Sample { Some(Sample {
alt, alt,
surface_color: Rgb::lerp(ground, cliff, (alt - SEA_LEVEL) / 150.0), chaos,
surface_color: Rgb::lerp(
sand,
// Land
Rgb::lerp(
ground,
cliff,
(alt - SEA_LEVEL - 100.0) / 150.0
),
// Beach
(alt - SEA_LEVEL - 2.0) / 5.0,
),
}) })
} }
} }
pub struct Sample { pub struct Sample {
pub alt: f32, pub alt: f32,
pub chaos: f32,
pub surface_color: Rgb<f32>, pub surface_color: Rgb<f32>,
} }
@ -167,7 +181,7 @@ struct GenCtx {
} }
const Z_TOLERANCE: (f32, f32) = (32.0, 64.0); const Z_TOLERANCE: (f32, f32) = (32.0, 64.0);
const SEA_LEVEL: f32 = 64.0; pub const SEA_LEVEL: f32 = 64.0;
pub struct SimChunk { pub struct SimChunk {
pub chaos: f32, pub chaos: f32,
@ -182,7 +196,7 @@ impl SimChunk {
let hill = (gen_ctx.hill_nz let hill = (gen_ctx.hill_nz
.get((wposf.div(3500.0)).into_array()) as f32) .get((wposf.div(3500.0)).into_array()) as f32)
.add(1.0).mul(0.5); .max(0.0);
let chaos = (gen_ctx.chaos_nz let chaos = (gen_ctx.chaos_nz
.get((wposf.div(3500.0)).into_array()) as f32) .get((wposf.div(3500.0)).into_array()) as f32)
@ -192,15 +206,18 @@ impl SimChunk {
let chaos = chaos + chaos.mul(20.0).sin().mul(0.05); let chaos = chaos + chaos.mul(20.0).sin().mul(0.05);
let alt_base = gen_ctx.alt_nz.get((wposf.div(5000.0)).into_array()) as f32 * 0.4;
let alt_main = gen_ctx.alt_nz.get((wposf.div(750.0)).into_array()) as f32; let alt_main = gen_ctx.alt_nz.get((wposf.div(750.0)).into_array()) as f32;
Self { Self {
chaos, chaos,
alt: SEA_LEVEL + (0.0 alt: SEA_LEVEL + (0.0
+ alt_main + alt_main
+ gen_ctx.small_nz.get((wposf.div(300.0)).into_array()) as f32 * alt_main * 1.3) + gen_ctx.small_nz.get((wposf.div(300.0)).into_array()) as f32 * alt_main.max(0.05) * chaos * 1.3)
.add(1.0).mul(0.5) .add(1.0).mul(0.5)
.mul(chaos) .mul(chaos)
.add(alt_base)
.mul(750.0), .mul(750.0),
temp: (gen_ctx.temp_nz.get((wposf.div(48.0)).into_array()) as f32) temp: (gen_ctx.temp_nz.get((wposf.div(48.0)).into_array()) as f32)
.add(1.0).mul(0.5), .add(1.0).mul(0.5),