Added more terrain noise, better snow

This commit is contained in:
Joshua Barretto 2019-06-10 15:22:59 +01:00
parent 8071670a37
commit df2594cbb4
3 changed files with 49 additions and 24 deletions

View File

@ -52,6 +52,7 @@ impl<'a> Sampler for BlockGen<'a> {
cave_xy, cave_xy,
cave_alt, cave_alt,
rock, rock,
cliff,
} = self.sample_column(Vec2::from(wpos))?; } = self.sample_column(Vec2::from(wpos))?;
let wposf = wpos.map(|e| e as f64); let wposf = wpos.map(|e| e as f64);
@ -64,9 +65,20 @@ impl<'a> Sampler for BlockGen<'a> {
.get((wposf.div(Vec3::new(120.0, 120.0, 140.0))).into_array()) .get((wposf.div(Vec3::new(120.0, 120.0, 140.0))).into_array())
as f32) as f32)
.mul((chaos - 0.1).max(0.0)) .mul((chaos - 0.1).max(0.0))
.mul(90.0); .mul(120.0);
let cliff = (0.0 let is_cliff = if cliff > 0.0 {
(self.world.sim()
.gen_ctx
.warp_nz
.get((wposf.div(Vec3::new(300.0, 300.0, 800.0))).into_array())
as f32) * cliff > 0.3
} else {
false
};
let cliff = if is_cliff {
(0.0
+ (self.world.sim() + (self.world.sim()
.gen_ctx .gen_ctx
.warp_nz .warp_nz
@ -75,18 +87,15 @@ impl<'a> Sampler for BlockGen<'a> {
+ (self.world.sim() + (self.world.sim()
.gen_ctx .gen_ctx
.warp_nz .warp_nz
.get((wposf.div(Vec3::new(100.0, 100.0, 100.0))).into_array()) .get((wposf.div(Vec3::new(100.0, 100.0, 70.0))).into_array())
as f32) * 0.2) as f32) * 0.3)
.add(0.6) .add(0.4)
.mul(64.0); .mul(64.0)
} else {
0.0
};
let is_cliff = (self.world.sim() let height = alt + warp + cliff;
.gen_ctx
.warp_nz
.get((wposf.div(Vec3::new(300.0, 300.0, 800.0))).into_array())
as f32) > 0.25;//4;
let height = alt + warp + if is_cliff { cliff } else { 0.0 };
// Sample blocks // Sample blocks
@ -98,7 +107,7 @@ impl<'a> Sampler for BlockGen<'a> {
let water = Block::new(1, Rgb::new(100, 150, 255)); let water = Block::new(1, Rgb::new(100, 150, 255));
let warm_stone = Block::new(1, Rgb::new(165, 165, 90)); let warm_stone = Block::new(1, Rgb::new(165, 165, 90));
let block = if (wposf.z as f32) < height - 4.0 { let block = if (wposf.z as f32) < height - 2.0 {
// Underground // Underground
if (wposf.z as f32) > alt { if (wposf.z as f32) > alt {
Some(surface_stone) Some(surface_stone)

View File

@ -36,6 +36,7 @@ impl<'a> Sampler for ColumnGen<'a> {
let chaos = sim.get_interpolated(wpos, |chunk| chunk.chaos)?; let chaos = sim.get_interpolated(wpos, |chunk| chunk.chaos)?;
let temp = sim.get_interpolated(wpos, |chunk| chunk.temp)?; let temp = sim.get_interpolated(wpos, |chunk| chunk.temp)?;
let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?; let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?;
let cliffiness = sim.get_interpolated(wpos, |chunk| chunk.cliffiness)?;
let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?; let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?;
let alt = sim.get_interpolated(wpos, |chunk| chunk.alt)? let alt = sim.get_interpolated(wpos, |chunk| chunk.alt)?
@ -53,26 +54,30 @@ impl<'a> Sampler for ColumnGen<'a> {
let marble = (0.0 let marble = (0.0
+ (sim.gen_ctx.hill_nz.get((wposf3d.div(48.0)).into_array()) as f32).mul(0.75) + (sim.gen_ctx.hill_nz.get((wposf3d.div(48.0)).into_array()) as f32).mul(0.75)
+ (sim.gen_ctx.hill_nz.get((wposf3d.div(3.0)).into_array()) as f32).mul(0.5)) + (sim.gen_ctx.hill_nz.get((wposf3d.div(3.0)).into_array()) as f32).mul(0.25))
.add(1.0) .add(1.0)
.mul(0.5); .mul(0.5);
// Colours // Colours
let cold_grass = Rgb::new(0.0, 0.4, 0.1); let cold_grass = Rgb::new(0.0, 0.3, 0.1);
let warm_grass = Rgb::new(0.25, 0.8, 0.05); let warm_grass = Rgb::new(0.25, 0.9, 0.05);
let cold_stone = Rgb::new(0.55, 0.7, 0.75); let cold_stone = Rgb::new(0.55, 0.7, 0.75);
let warm_stone = Rgb::new(0.65, 0.65, 0.35); let warm_stone = Rgb::new(0.65, 0.65, 0.35);
let beach_sand = Rgb::new(0.93, 0.84, 0.33); let beach_sand = Rgb::new(0.93, 0.84, 0.4);
let desert_sand = Rgb::new(0.97, 0.84, 0.23); let desert_sand = Rgb::new(0.98, 0.8, 0.15);
let snow = Rgb::broadcast(1.0); let snow = Rgb::broadcast(1.0);
let grass = Rgb::lerp(cold_grass, warm_grass, marble); let grass = Rgb::lerp(cold_grass, warm_grass, marble);
let grassland = grass; //Rgb::lerp(grass, warm_stone, rock.mul(5.0).min(0.8)); let sand = Rgb::lerp(beach_sand, desert_sand, marble);
let cliff = Rgb::lerp(cold_stone, warm_stone, marble); let cliff = Rgb::lerp(cold_stone, warm_stone, marble);
let ground = Rgb::lerp( let ground = Rgb::lerp(
Rgb::lerp(snow, grassland, temp.add(0.4).mul(32.0).sub(0.4)), Rgb::lerp(
desert_sand, snow,
grass,
temp.add(0.4).add(marble * 0.05).mul(256.0).sub(0.4),
),
sand,
temp.sub(0.4).mul(32.0).add(0.4), temp.sub(0.4).mul(32.0).add(0.4),
); );
@ -108,7 +113,7 @@ impl<'a> Sampler for ColumnGen<'a> {
alt, alt,
chaos, chaos,
surface_color: Rgb::lerp( surface_color: Rgb::lerp(
beach_sand, sand,
// Land // Land
Rgb::lerp( Rgb::lerp(
ground, ground,
@ -133,6 +138,7 @@ impl<'a> Sampler for ColumnGen<'a> {
cave_xy, cave_xy,
cave_alt, cave_alt,
rock, rock,
cliff: cliffiness,
}) })
} }
} }
@ -147,4 +153,5 @@ pub struct ColumnSample {
pub cave_xy: f32, pub cave_xy: f32,
pub cave_alt: f32, pub cave_alt: f32,
pub rock: f32, pub rock: f32,
pub cliff: f32,
} }

View File

@ -24,6 +24,7 @@ pub(crate) struct GenCtx {
pub temp_nz: SuperSimplex, pub temp_nz: SuperSimplex,
pub small_nz: BasicMulti, pub small_nz: BasicMulti,
pub rock_nz: HybridMulti, pub rock_nz: HybridMulti,
pub cliff_nz: HybridMulti,
pub warp_nz: BasicMulti, pub warp_nz: BasicMulti,
pub tree_nz: BasicMulti, pub tree_nz: BasicMulti,
@ -53,6 +54,7 @@ impl WorldSim {
temp_nz: SuperSimplex::new().set_seed(seed + 5), temp_nz: SuperSimplex::new().set_seed(seed + 5),
small_nz: BasicMulti::new().set_octaves(2).set_seed(seed + 6), small_nz: BasicMulti::new().set_octaves(2).set_seed(seed + 6),
rock_nz: HybridMulti::new().set_persistence(0.3).set_seed(seed + 7), rock_nz: HybridMulti::new().set_persistence(0.3).set_seed(seed + 7),
cliff_nz: HybridMulti::new().set_persistence(0.3).set_seed(seed + 7),
warp_nz: BasicMulti::new().set_octaves(3).set_seed(seed + 8), warp_nz: BasicMulti::new().set_octaves(3).set_seed(seed + 8),
tree_nz: BasicMulti::new() tree_nz: BasicMulti::new()
.set_octaves(12) .set_octaves(12)
@ -140,7 +142,7 @@ impl WorldSim {
} }
} }
const Z_TOLERANCE: (f32, f32) = (128.0, 128.0); const Z_TOLERANCE: (f32, f32) = (128.0, 96.0);
pub struct SimChunk { pub struct SimChunk {
pub chaos: f32, pub chaos: f32,
@ -148,6 +150,7 @@ pub struct SimChunk {
pub alt: f32, pub alt: f32,
pub temp: f32, pub temp: f32,
pub rockiness: f32, pub rockiness: f32,
pub cliffiness: f32,
pub tree_density: f32, pub tree_density: f32,
} }
@ -207,6 +210,12 @@ impl SimChunk {
.sub(0.1) .sub(0.1)
.mul(1.2) .mul(1.2)
.max(0.0), .max(0.0),
cliffiness: (gen_ctx.cliff_nz.get((wposf.div(2048.0)).into_array()) as f32)
.sub(0.15)
.mul(3.0)
.mul(1.1 - chaos)
.max(0.0)
.min(1.0),
tree_density: (gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array()) as f32) tree_density: (gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array()) as f32)
.add(1.0) .add(1.0)
.mul(0.5) .mul(0.5)