mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Switched to FastNoise
This commit is contained in:
parent
4777921680
commit
b0293ecce4
@ -171,31 +171,18 @@ impl<'a> BlockGen<'a> {
|
|||||||
(true, alt, CONFIG.sea_level /*water_level*/)
|
(true, alt, CONFIG.sea_level /*water_level*/)
|
||||||
} else {
|
} else {
|
||||||
// Apply warping
|
// Apply warping
|
||||||
let warp = (world
|
let warp = (world.sim().gen_ctx.warp_nz.get(wposf.div(16.0)) as f32)
|
||||||
.sim()
|
|
||||||
.gen_ctx
|
|
||||||
.warp_nz
|
|
||||||
.get((wposf.div(Vec3::new(150.0, 150.0, 150.0))).into_array())
|
|
||||||
as f32)
|
|
||||||
.mul((chaos - 0.1).max(0.0))
|
.mul((chaos - 0.1).max(0.0))
|
||||||
.mul(96.0);
|
.mul(15.0);
|
||||||
|
|
||||||
let height = if (wposf.z as f32) < alt + warp - 10.0 {
|
let height = if (wposf.z as f32) < alt + warp - 10.0 {
|
||||||
// Shortcut cliffs
|
// Shortcut cliffs
|
||||||
alt + warp
|
alt + warp
|
||||||
} else {
|
} else {
|
||||||
let turb = Vec2::new(
|
let turb = Vec2::new(
|
||||||
world
|
world.sim().gen_ctx.fast_turb_x_nz.get(wposf.div(16.0)) as f32,
|
||||||
.sim()
|
world.sim().gen_ctx.fast_turb_y_nz.get(wposf.div(16.0)) as f32,
|
||||||
.gen_ctx
|
) * 8.0;
|
||||||
.turb_x_nz
|
|
||||||
.get((wposf.div(48.0)).into_array()) as f32,
|
|
||||||
world
|
|
||||||
.sim()
|
|
||||||
.gen_ctx
|
|
||||||
.turb_y_nz
|
|
||||||
.get((wposf.div(48.0)).into_array()) as f32,
|
|
||||||
) * 12.0;
|
|
||||||
|
|
||||||
let wpos_turb = Vec2::from(wpos).map(|e: i32| e as f32) + turb;
|
let wpos_turb = Vec2::from(wpos).map(|e: i32| e as f32) + turb;
|
||||||
let cliff_height = Self::get_cliff_height(
|
let cliff_height = Self::get_cliff_height(
|
||||||
|
@ -12,7 +12,7 @@ use self::util::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
all::ForestKind,
|
all::ForestKind,
|
||||||
generator::TownState,
|
generator::TownState,
|
||||||
util::{seed_expan, Sampler, StructureGen2d},
|
util::{seed_expan, FastNoise, Sampler, StructureGen2d},
|
||||||
CONFIG,
|
CONFIG,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
@ -75,7 +75,7 @@ pub(crate) struct GenCtx {
|
|||||||
pub small_nz: BasicMulti,
|
pub small_nz: BasicMulti,
|
||||||
pub rock_nz: HybridMulti,
|
pub rock_nz: HybridMulti,
|
||||||
pub cliff_nz: HybridMulti,
|
pub cliff_nz: HybridMulti,
|
||||||
pub warp_nz: BasicMulti,
|
pub warp_nz: FastNoise,
|
||||||
pub tree_nz: BasicMulti,
|
pub tree_nz: BasicMulti,
|
||||||
|
|
||||||
pub cave_0_nz: SuperSimplex,
|
pub cave_0_nz: SuperSimplex,
|
||||||
@ -84,6 +84,9 @@ pub(crate) struct GenCtx {
|
|||||||
pub structure_gen: StructureGen2d,
|
pub structure_gen: StructureGen2d,
|
||||||
pub region_gen: StructureGen2d,
|
pub region_gen: StructureGen2d,
|
||||||
pub cliff_gen: StructureGen2d,
|
pub cliff_gen: StructureGen2d,
|
||||||
|
|
||||||
|
pub fast_turb_x_nz: FastNoise,
|
||||||
|
pub fast_turb_y_nz: FastNoise,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WorldSim {
|
pub struct WorldSim {
|
||||||
@ -117,7 +120,7 @@ impl WorldSim {
|
|||||||
small_nz: BasicMulti::new().set_octaves(2).set_seed(gen_seed()),
|
small_nz: BasicMulti::new().set_octaves(2).set_seed(gen_seed()),
|
||||||
rock_nz: HybridMulti::new().set_persistence(0.3).set_seed(gen_seed()),
|
rock_nz: HybridMulti::new().set_persistence(0.3).set_seed(gen_seed()),
|
||||||
cliff_nz: HybridMulti::new().set_persistence(0.3).set_seed(gen_seed()),
|
cliff_nz: HybridMulti::new().set_persistence(0.3).set_seed(gen_seed()),
|
||||||
warp_nz: BasicMulti::new().set_octaves(3).set_seed(gen_seed()),
|
warp_nz: FastNoise::new(gen_seed()), //BasicMulti::new().set_octaves(3).set_seed(gen_seed()),
|
||||||
tree_nz: BasicMulti::new()
|
tree_nz: BasicMulti::new()
|
||||||
.set_octaves(12)
|
.set_octaves(12)
|
||||||
.set_persistence(0.75)
|
.set_persistence(0.75)
|
||||||
@ -135,6 +138,9 @@ impl WorldSim {
|
|||||||
// .set_octaves(6)
|
// .set_octaves(6)
|
||||||
// .set_persistence(0.5)
|
// .set_persistence(0.5)
|
||||||
.set_seed(gen_seed()),
|
.set_seed(gen_seed()),
|
||||||
|
|
||||||
|
fast_turb_x_nz: FastNoise::new(gen_seed()),
|
||||||
|
fast_turb_y_nz: FastNoise::new(gen_seed()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// "Base" of the chunk, to be multiplied by CONFIG.mountain_scale (multiplied value is
|
// "Base" of the chunk, to be multiplied by CONFIG.mountain_scale (multiplied value is
|
||||||
|
47
world/src/util/fast_noise.rs
Normal file
47
world/src/util/fast_noise.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
use super::{RandomField, Sampler};
|
||||||
|
use std::f32;
|
||||||
|
use vek::*;
|
||||||
|
|
||||||
|
pub struct FastNoise {
|
||||||
|
noise: RandomField,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FastNoise {
|
||||||
|
pub const fn new(seed: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
noise: RandomField::new(seed),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn noise_at(&self, pos: Vec3<i32>) -> f32 {
|
||||||
|
(self.noise.get(pos) % 4096) as f32 / 4096.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sampler<'static> for FastNoise {
|
||||||
|
type Index = Vec3<f64>;
|
||||||
|
type Sample = f32;
|
||||||
|
|
||||||
|
fn get(&self, pos: Self::Index) -> Self::Sample {
|
||||||
|
let v000 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(0, 0, 0));
|
||||||
|
let v100 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(1, 0, 0));
|
||||||
|
let v010 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(0, 1, 0));
|
||||||
|
let v110 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(1, 1, 0));
|
||||||
|
let v001 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(0, 0, 1));
|
||||||
|
let v101 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(1, 0, 1));
|
||||||
|
let v011 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(0, 1, 1));
|
||||||
|
let v111 = self.noise_at(pos.map(|e| e.floor() as i32) + Vec3::new(1, 1, 1));
|
||||||
|
|
||||||
|
let factor = pos.map(|e| 0.5 - (e.fract() as f32 * f32::consts::PI).cos() * 0.5);
|
||||||
|
|
||||||
|
let x00 = Lerp::lerp(v000, v100, factor.x);
|
||||||
|
let x10 = Lerp::lerp(v010, v110, factor.x);
|
||||||
|
let x01 = Lerp::lerp(v001, v101, factor.x);
|
||||||
|
let x11 = Lerp::lerp(v011, v111, factor.x);
|
||||||
|
|
||||||
|
let y0 = Lerp::lerp(x00, x10, factor.y);
|
||||||
|
let y1 = Lerp::lerp(x01, x11, factor.y);
|
||||||
|
|
||||||
|
Lerp::lerp(y0, y1, factor.z) * 2.0 - 1.0
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
pub mod fast_noise;
|
||||||
pub mod hash_cache;
|
pub mod hash_cache;
|
||||||
pub mod random;
|
pub mod random;
|
||||||
pub mod sampler;
|
pub mod sampler;
|
||||||
@ -7,6 +8,7 @@ pub mod unit_chooser;
|
|||||||
|
|
||||||
// Reexports
|
// Reexports
|
||||||
pub use self::{
|
pub use self::{
|
||||||
|
fast_noise::FastNoise,
|
||||||
hash_cache::HashCache,
|
hash_cache::HashCache,
|
||||||
random::{RandomField, RandomPerm},
|
random::{RandomField, RandomPerm},
|
||||||
sampler::{Sampler, SamplerMut},
|
sampler::{Sampler, SamplerMut},
|
||||||
|
Loading…
Reference in New Issue
Block a user