mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added rivers, improved mountains
Former-commit-id: c1b76c54d2aa8f0616c26b0724fe34c0d80ac4fd
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
mod sim;
|
mod sim;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
ops::{Add, Neg},
|
ops::{Add, Mul, Neg},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use noise::{NoiseFn, Perlin, Seedable};
|
use noise::{NoiseFn, Perlin, Seedable};
|
||||||
@ -54,12 +54,22 @@ impl World {
|
|||||||
let wpos2d = Vec2::new(x, y) + Vec3::from(chunk_pos) * TerrainChunkSize::SIZE.map(|e| e as i32);
|
let wpos2d = Vec2::new(x, y) + Vec3::from(chunk_pos) * TerrainChunkSize::SIZE.map(|e| e as i32);
|
||||||
let wposf2d = wpos2d.map(|e| e as f64);
|
let wposf2d = wpos2d.map(|e| e as f64);
|
||||||
|
|
||||||
|
let max_z = self.sim
|
||||||
|
.get_interpolated(wpos2d, |chunk| chunk.get_max_z())
|
||||||
|
.unwrap_or(0.0) as i32;
|
||||||
|
|
||||||
let chaos = self.sim
|
let chaos = self.sim
|
||||||
.get_interpolated(wpos2d, |chunk| chunk.chaos)
|
.get_interpolated(wpos2d, |chunk| chunk.chaos)
|
||||||
.unwrap_or(0.0);
|
.unwrap_or(0.0);
|
||||||
|
|
||||||
let ridge_freq = 1.0 / 128.0;
|
let damp = self.sim
|
||||||
let ridge_ampl = 96.0;
|
.get_interpolated(wpos2d, |chunk| chunk.damp)
|
||||||
|
.unwrap_or(0.0)
|
||||||
|
.abs().neg().add(1.0)
|
||||||
|
.mul(1.0 - chaos);
|
||||||
|
|
||||||
|
let ridge_freq = 1.0 / 125.0;
|
||||||
|
let ridge_ampl = 125.0;
|
||||||
|
|
||||||
let ridge = ridge_nz
|
let ridge = ridge_nz
|
||||||
.get((wposf2d * ridge_freq).into_array()).abs().neg().add(1.0) as f32 * ridge_ampl * chaos.powf(8.0);
|
.get((wposf2d * ridge_freq).into_array()).abs().neg().add(1.0) as f32 * ridge_ampl * chaos.powf(8.0);
|
||||||
@ -67,19 +77,20 @@ impl World {
|
|||||||
let height_z = self.sim
|
let height_z = self.sim
|
||||||
.get_interpolated(wpos2d, |chunk| chunk.alt)
|
.get_interpolated(wpos2d, |chunk| chunk.alt)
|
||||||
.unwrap_or(0.0)
|
.unwrap_or(0.0)
|
||||||
+ ridge;
|
+ ridge
|
||||||
|
- damp.powf(20.0) * 32.0;
|
||||||
|
|
||||||
for z in base_z..base_z + 256 {
|
for z in base_z..max_z {
|
||||||
let lpos = Vec3::new(x, y, z);
|
let lpos = Vec3::new(x, y, z);
|
||||||
let wpos = lpos
|
let wpos = lpos
|
||||||
+ 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_freq = 1.0 / 48.0;
|
let warp_freq = 1.0 / 40.0;
|
||||||
let warp_ampl = 24.0;
|
let warp_ampl = 45.0;
|
||||||
|
|
||||||
let height = height_z
|
let height = height_z
|
||||||
+ warp_nz.get((wposf * warp_freq).into_array()) as f32 * warp_ampl * (chaos + 0.05);
|
+ warp_nz.get((wposf * warp_freq).into_array()) as f32 * warp_ampl * (chaos + 0.05).min(0.85);
|
||||||
|
|
||||||
let temp =
|
let temp =
|
||||||
(temp_nz.get(Vec2::from(wposf * (1.0 / 64.0)).into_array()) as f32 + 1.0) * 0.5;
|
(temp_nz.get(Vec2::from(wposf * (1.0 / 64.0)).into_array()) as f32 + 1.0) * 0.5;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::{
|
use std::{
|
||||||
ops::{Add, Mul, Div},
|
ops::{Add, Mul, Div, Neg},
|
||||||
f32,
|
f32,
|
||||||
};
|
};
|
||||||
use noise::{NoiseFn, OpenSimplex, Seedable};
|
use noise::{NoiseFn, SuperSimplex, OpenSimplex, Seedable};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use common::{
|
use common::{
|
||||||
terrain::TerrainChunkSize,
|
terrain::TerrainChunkSize,
|
||||||
@ -19,10 +19,14 @@ pub struct WorldSim {
|
|||||||
impl WorldSim {
|
impl WorldSim {
|
||||||
pub fn generate(seed: u32) -> Self {
|
pub fn generate(seed: u32) -> Self {
|
||||||
let mut gen_ctx = GenCtx {
|
let mut gen_ctx = GenCtx {
|
||||||
alt_nz: OpenSimplex::new()
|
base_nz: OpenSimplex::new()
|
||||||
.set_seed(seed + 0),
|
.set_seed(seed + 0),
|
||||||
chaos_nz: OpenSimplex::new()
|
damp_nz: SuperSimplex::new()
|
||||||
.set_seed(seed + 1),
|
.set_seed(seed + 1),
|
||||||
|
chaos_nz: SuperSimplex::new()
|
||||||
|
.set_seed(seed + 2),
|
||||||
|
alt_nz: OpenSimplex::new()
|
||||||
|
.set_seed(seed + 3),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut chunks = Vec::new();
|
let mut chunks = Vec::new();
|
||||||
@ -60,22 +64,26 @@ impl WorldSim {
|
|||||||
.fold(None, |a: Option<f32>, x| a.map(|a| a.min(x)).or(Some(x))))
|
.fold(None, |a: Option<f32>, x| a.map(|a| a.min(x)).or(Some(x))))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_interpolated<F: FnMut(&SimChunk) -> f32>(&self, pos: Vec2<i32>, mut f: F) -> Option<f32> {
|
pub fn get_interpolated<T, F>(&self, pos: Vec2<i32>, mut f: F) -> Option<T>
|
||||||
|
where
|
||||||
|
T: Copy + Default + Add<Output=T> + Mul<f32, Output=T>,
|
||||||
|
F: FnMut(&SimChunk) -> T,
|
||||||
|
{
|
||||||
let pos = pos.map2(TerrainChunkSize::SIZE.into(), |e, sz: u32| e as f64 / sz as f64);
|
let pos = pos.map2(TerrainChunkSize::SIZE.into(), |e, sz: u32| e as f64 / sz as f64);
|
||||||
|
|
||||||
fn cubic(a: f32, b: f32, c: f32, d: f32, x: f32) -> f32 {
|
let cubic = |a: T, b: T, c: T, d: T, x: f32| -> T {
|
||||||
let x2 = x * x;
|
let x2 = x * x;
|
||||||
|
|
||||||
// Catmull-Rom splines
|
// Catmull-Rom splines
|
||||||
let co0 = -0.5 * a + 1.5 * b - 1.5 * c + 0.5 * d;
|
let co0 = a * -0.5 + b * 1.5 + c * -1.5 + d * 0.5;
|
||||||
let co1 = a - 2.5 * b + 2.0 * c - 0.5 * d;
|
let co1 = a + b * -2.5 + c * 2.0 + d * -0.5;
|
||||||
let co2 = -0.5 * a + 0.5 * c;
|
let co2 = a * -0.5 + c * 0.5;
|
||||||
let co3 = b;
|
let co3 = b;
|
||||||
|
|
||||||
co0 * x2 * x + co1 * x2 + co2 * x + co3
|
co0 * x2 * x + co1 * x2 + co2 * x + co3
|
||||||
}
|
};
|
||||||
|
|
||||||
let mut y = [0.0; 4];
|
let mut y = [T::default(); 4];
|
||||||
|
|
||||||
for (y_idx, j) in (-1..3).enumerate() {
|
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 x0 = f(self.get(pos.map2(Vec2::new(-1, j), |e, q| (e.max(0.0) as i32 + q) as u32))?);
|
||||||
@ -98,11 +106,16 @@ impl WorldSim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct GenCtx {
|
struct GenCtx {
|
||||||
chaos_nz: OpenSimplex,
|
base_nz: OpenSimplex,
|
||||||
|
damp_nz: SuperSimplex,
|
||||||
|
chaos_nz: SuperSimplex,
|
||||||
alt_nz: OpenSimplex,
|
alt_nz: OpenSimplex,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Z_TOLERANCE: f32 = 32.0;
|
||||||
|
|
||||||
pub struct SimChunk {
|
pub struct SimChunk {
|
||||||
|
pub damp: f32,
|
||||||
pub chaos: f32,
|
pub chaos: f32,
|
||||||
pub alt: f32,
|
pub alt: f32,
|
||||||
}
|
}
|
||||||
@ -111,16 +124,31 @@ impl SimChunk {
|
|||||||
fn generate(pos: Vec2<u32>, gen_ctx: &mut GenCtx) -> Self {
|
fn generate(pos: Vec2<u32>, gen_ctx: &mut GenCtx) -> Self {
|
||||||
let wposf = (pos * Vec2::from(TerrainChunkSize::SIZE)).map(|e| e as f64);
|
let wposf = (pos * Vec2::from(TerrainChunkSize::SIZE)).map(|e| e as f64);
|
||||||
|
|
||||||
|
let base = (gen_ctx.base_nz.get((wposf.div(6000.0)).into_array()) as f32)
|
||||||
|
.add(1.0).mul(0.5)
|
||||||
|
.mul(100.0)
|
||||||
|
.add(32.0);
|
||||||
|
|
||||||
|
let damp = (0.0
|
||||||
|
+ gen_ctx.damp_nz.get((wposf.div(2000.0)).into_array())
|
||||||
|
+ gen_ctx.damp_nz.get((wposf.div(250.0)).into_array()) * 0.25
|
||||||
|
) as f32;
|
||||||
|
|
||||||
let chaos = (gen_ctx.chaos_nz
|
let chaos = (gen_ctx.chaos_nz
|
||||||
.get((wposf.div(400.0)).into_array()) as f32)
|
.get((wposf.div(1000.0)).into_array()) as f32)
|
||||||
.max(0.0)
|
.add(1.0).mul(0.5)
|
||||||
|
.mul(damp.max(0.0))
|
||||||
.add(0.15)
|
.add(0.15)
|
||||||
.powf(2.0);
|
.powf(2.0)
|
||||||
|
.min(1.0);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
damp,
|
||||||
chaos,
|
chaos,
|
||||||
alt: (gen_ctx.alt_nz
|
alt: base + ((0.0
|
||||||
.get((wposf.div(125.0)).into_array()) as f32)
|
+ gen_ctx.alt_nz.get((wposf.div(650.0)).into_array()) * 0.7
|
||||||
|
+ gen_ctx.alt_nz.get((wposf.div(100.0)).into_array()) * 0.3
|
||||||
|
) as f32)
|
||||||
.add(1.0).mul(0.5)
|
.add(1.0).mul(0.5)
|
||||||
.mul(750.0)
|
.mul(750.0)
|
||||||
.mul(chaos.max(0.05)),
|
.mul(chaos.max(0.05)),
|
||||||
@ -128,8 +156,10 @@ impl SimChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_base_z(&self) -> f32 {
|
pub fn get_base_z(&self) -> f32 {
|
||||||
const BASE_Z_TOLERANCE: f32 = 32.0;
|
self.alt - Z_TOLERANCE
|
||||||
|
}
|
||||||
|
|
||||||
self.alt - BASE_Z_TOLERANCE
|
pub fn get_max_z(&self) -> f32 {
|
||||||
|
self.alt + Z_TOLERANCE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user