Better water/cave/cliff interaction

This commit is contained in:
Joshua Barretto 2021-02-14 17:55:48 +00:00
parent 466f3919d2
commit e5b02ff7da
4 changed files with 21 additions and 14 deletions

View File

@ -121,7 +121,7 @@ impl<'a> BlockGen<'a> {
if stone_factor >= 0.5 {
if wposf.z as f32 > height - cliff_offset.max(0.0) {
if cliff_offset.max(0.0) > cliff_height - (FastNoise::new(37).get(wposf / Vec3::new(6.0, 6.0, 10.0)) * 0.5 + 0.5) * (height - wposf.z as f32).mul(0.25).clamped(0.0, 12.0) {
if cliff_offset.max(0.0) > cliff_height - (FastNoise::new(37).get(wposf / Vec3::new(6.0, 6.0, 10.0)) * 0.5 + 0.5) * (height - wposf.z as f32).mul(0.25).clamped(0.0, 10.0) {
Some(Block::empty())
} else {
let col = Lerp::lerp(

View File

@ -267,9 +267,9 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
// Cliffs
let cliff_height =
sim.get_interpolated(wpos, |chunk| chunk.cliff_height)? * (1.0 - near_water).powf(2.0);
sim.get_interpolated(wpos, |chunk| chunk.cliff_height)?;
let cliff_factor = (alt
+ self.sim.gen_ctx.hill_nz.get(wposf.div(32.0).into_array()) as f32 * 10.0
+ self.sim.gen_ctx.hill_nz.get(wposf.div(32.0).into_array()) as f32 * 8.0
+ self.sim.gen_ctx.hill_nz.get(wposf.div(256.0).into_array()) as f32 * 64.0)
.rem_euclid(128.0)
/ 64.0
@ -282,7 +282,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
cliff_factor.abs().powf(1.5)
} else {
0.0
};
} * (1.0 - near_water * 3.0).max(0.0).powi(2);
let cliff_offset = cliff * cliff_height;
let alt = alt + (cliff - 0.5) * cliff_height;

View File

@ -110,7 +110,7 @@ pub fn apply_paths_to(canvas: &mut Canvas) {
pub fn apply_caves_to(canvas: &mut Canvas, rng: &mut impl Rng) {
let info = canvas.info();
canvas.foreach_col(|canvas, wpos2d, col| {
let surface_z = col.riverless_alt.floor() as i32;
let surface_z = col.alt.floor() as i32;
if let Some((cave_dist, _, cave, _)) =
col.cave.filter(|(dist, _, cave, _)| *dist < cave.width)
@ -164,14 +164,21 @@ pub fn apply_caves_to(canvas: &mut Canvas, rng: &mut impl Rng) {
)
.mul(45.0) as i32;
for z in cave_roof - stalagtites..cave_roof {
canvas.set(
Vec3::new(wpos2d.x, wpos2d.y, z),
Block::new(
BlockKind::WeakRock,
info.index().colors.layer.stalagtite.into(),
),
);
// Generate stalagtites if there's something for them to hold on to
if canvas
.get(Vec3::new(wpos2d.x, wpos2d.y, cave_roof))
.map(|b| b.is_filled())
.unwrap_or(false)
{
for z in cave_roof - stalagtites..cave_roof {
canvas.set(
Vec3::new(wpos2d.x, wpos2d.y, z),
Block::new(
BlockKind::WeakRock,
info.index().colors.layer.stalagtite.into(),
),
);
}
}
let cave_depth = (col.alt - cave.alt).max(0.0);

View File

@ -287,9 +287,9 @@ impl World {
chunk: &mut chunk,
};
layer::apply_caves_to(&mut canvas, &mut dynamic_rng);
layer::apply_trees_to(&mut canvas, &mut dynamic_rng);
layer::apply_scatter_to(&mut canvas, &mut dynamic_rng);
layer::apply_caves_to(&mut canvas, &mut dynamic_rng);
layer::apply_paths_to(&mut canvas);
layer::apply_coral_to(&mut canvas);