Merge branch 'zesterer/worldgen' into 'master'

Various worldgen improvements

See merge request veloren/veloren!4152
This commit is contained in:
Christof Petig 2023-11-10 00:15:29 +00:00
commit 0ddd40336a
10 changed files with 135 additions and 45 deletions

View File

@ -128,7 +128,11 @@ void main() {
// vec3 surf_norm = normalize(vec3(nz * 0.03 / (1.0 + dist * 0.1), 1));
// refr_dir = refract(dir, surf_norm * -sign(dir.z), 1.0 / n2);
// } else {
refr_dir = normalize(dir + vec3(nz * 1.5 / dist, 0.0));
if (mat.a == MAT_FLUID) {
refr_dir = normalize(dir + vec3(nz * 1.5 / dist, 0.0));
} else {
refr_dir = dir;
}
// }
vec4 clip = (all_mat * vec4(cam_pos.xyz + refr_dir, 1.0));

View File

@ -60,6 +60,7 @@
#define BLOCK_SNOW 0x21
#define BLOCK_ART_SNOW 0x22
#define BLOCK_ICE 0x43
// An arbitrary value that represents a very far distance (at least as far as the player should be able to see) without
// being too far that we end up with precision issues (used in clouds and elsewhere).

View File

@ -698,7 +698,11 @@ void main() {
sin(lifetime * 5 + rand2)
) * 0.03,
vec3(pow(1.0 - abs(percent() - 0.5) * 2.0, 0.2)),
vec4(mix(vec3(0.4, 0.2, 0.8), vec3(5, 2, 10), pow(percent(), 2)), 1),
mix(
vec4(mix(vec3(0.4, 0.8, 0.2), vec3(5, 10, 2), pow(percent(), 2)), 1),
vec4(mix(vec3(0.6, 0.2, 0.8), vec3(9, 2, 10), pow(percent(), 2)), 1),
clamp((dot(normalize(focus_pos.xyz - start_pos), inst_dir) - 0.25) * 3.0, 0.0, 1.0)
),
/* vec4(vec3(1.8 - percent() * 2, 0.4 + percent() * 2, 5.0 + rand6), 1), */
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
);

View File

@ -1,4 +1,4 @@
#version 420 core
#version 430 core
#define FIGURE_SHADER

View File

@ -1,4 +1,4 @@
#version 420 core
#version 430 core
#include <constants.glsl>

View File

@ -93,6 +93,8 @@ void main() {
uint f_kind;
vec3 f_col = greedy_extract_col_light_kind_terrain(t_col_light, s_col_light, t_kind, f_uv_pos, f_light, f_glow, f_ao, f_sky_exposure, f_kind);
uint f_mat = MAT_BLOCK;
#ifdef EXPERIMENTAL_BAREMINIMUM
tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_light), 1);
return;
@ -280,6 +282,7 @@ void main() {
alpha = mix(1.0, 0.2, puddle);
f_col.rgb *= mix(1.0, 0.7, puddle);
k_s = mix(k_s, vec3(0.7, 0.7, 1.0), puddle);
f_mat = MAT_FLUID;
}
#endif
@ -306,6 +309,12 @@ void main() {
}
#endif
// Reflections on ice
if (f_kind == BLOCK_ICE && f_norm.z == 1.0) {
f_alpha = min(f_alpha, 0.3);
k_s = mix(k_s, vec3(0.7, 0.7, 1.0), 0.5);
}
// float sun_light = get_sun_brightness(sun_dir);
// float moon_light = get_moon_brightness(moon_dir);
/* float sun_shade_frac = horizon_at(f_pos, sun_dir);
@ -559,6 +568,6 @@ void main() {
surf_color += f_select * (surf_color + 0.1) * vec3(0.5, 0.5, 0.5);
tgt_color = vec4(surf_color, f_alpha);
tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_BLOCK);
tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), f_mat);
//tgt_color = vec4(f_norm, f_alpha);
}

View File

@ -62,6 +62,16 @@
grass_high: (0.15, 0.2, 0.15),
tropical_high: (0.95, 0.55, 0.50),
mesa_layers: [
(0.6, 0.3, 0.2),
(0.4, 0.03, 0.1),
(0.8, 0.5, 0.2),
(0.6, 0.25, 0.1),
(0.35, 0.3, 0.15),
(0.4, 0.15, 0.05),
(0.2, 0.15, 0.1),
(0.7, 0.6, 0.3),
],
),
// NOTE: I think (but am not sure) that this is the color of stuff below the bottom-most
// ground. I'm not sure how easy it is to see.

View File

@ -2,7 +2,7 @@ use crate::{
all::ForestKind,
sim::{local_cells, Cave, Path, RiverKind, SimChunk, WorldSim},
site::SpawnRules,
util::{RandomField, Sampler},
util::{RandomField, RandomPerm, Sampler},
IndexRef, CONFIG,
};
use common::{
@ -14,6 +14,7 @@ use common::{
vol::RectVolSize,
};
use noise::NoiseFn;
use rand::seq::SliceRandom;
use serde::Deserialize;
use std::ops::{Add, Div, Mul, Sub};
use tracing::error;
@ -47,6 +48,7 @@ pub struct Colors {
pub grass_high: (f32, f32, f32),
pub tropical_high: (f32, f32, f32),
pub mesa_layers: Vec<(f32, f32, f32)>,
}
/// Generalised power function, pushes values in the range 0-1 to extremes.
@ -864,11 +866,18 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
let surface_rigidity =
surface_rigidity.max(((basement_sub_alt + 3.0) / 1.5).clamped(0.0, 2.0));
let warp = ((marble_mid * 0.2 + marble * 0.8) * 2.0 - 1.0)
* 15.0
* (10.0 + rockiness * 15.0)
* gradient.unwrap_or(0.0).min(1.0)
* surface_rigidity
* warp_factor;
let mesa = 1.0f32
.min(30.0 / (1.0 + -basement_sub_alt.min(0.0)))
.min(1.0 - humidity * 4.0)
.min(temp)
.min(Lerp::lerp(-0.4, 1.0, gradient.unwrap_or(0.0)).max(0.0))
.max(0.0);
let riverless_alt_delta = Lerp::lerp(0.0, riverless_alt_delta, warp_factor);
let alt = alt + riverless_alt_delta + warp;
let basement = alt + basement_sub_alt;
@ -919,25 +928,27 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
warm_stone_high,
grass_high,
tropical_high,
} = index.colors.column;
mesa_layers,
} = &index.colors.column;
let cold_grass = cold_grass.into();
let warm_grass = warm_grass.into();
let dark_grass = dark_grass.into();
let wet_grass = wet_grass.into();
let cold_stone = cold_stone.into();
let hot_stone = hot_stone.into();
let warm_stone: Rgb<f32> = warm_stone.into();
let beach_sand = beach_sand.into();
let desert_sand = desert_sand.into();
let snow = snow.into();
let stone_col = stone_col.into();
let dirt_low: Rgb<f32> = dirt_low.into();
let dirt_high = dirt_high.into();
let snow_high = snow_high.into();
let warm_stone_high = warm_stone_high.into();
let grass_high = grass_high.into();
let tropical_high = tropical_high.into();
let cold_grass = (*cold_grass).into();
let warm_grass = (*warm_grass).into();
let dark_grass = (*dark_grass).into();
let wet_grass = (*wet_grass).into();
let cold_stone = (*cold_stone).into();
let hot_stone = (*hot_stone).into();
let warm_stone: Rgb<f32> = (*warm_stone).into();
let beach_sand = (*beach_sand).into();
let desert_sand = (*desert_sand).into();
let snow = (*snow).into();
let snow_moss = (*snow_moss).into();
let stone_col = (*stone_col).into();
let dirt_low: Rgb<f32> = (*dirt_low).into();
let dirt_high = (*dirt_high).into();
let snow_high = (*snow_high).into();
let warm_stone_high = (*warm_stone_high).into();
let grass_high = (*grass_high).into();
let tropical_high = (*tropical_high).into();
let dirt = Lerp::lerp(dirt_low, dirt_high, marble_mixed);
let tundra = Lerp::lerp(snow, snow_high, 0.4 + marble_mixed * 0.6);
@ -952,11 +963,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
.add(1.0.sub(humidity).mul(0.5))
.powf(1.5),
);
let snow_moss = Rgb::lerp(
snow_moss.into(),
cold_grass,
0.4 + marble_mixed.powf(1.5) * 0.6,
);
let snow_moss = Rgb::lerp(snow_moss, cold_grass, 0.4 + marble_mixed.powf(1.5) * 0.6);
let moss = Rgb::lerp(dark_grass, cold_grass, marble_mixed.powf(1.5));
let rainforest = Rgb::lerp(wet_grass, warm_grass, marble_mixed.powf(1.5));
let sand = Rgb::lerp(beach_sand, desert_sand, marble_mixed);
@ -1128,6 +1135,56 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
.map(|wd| Lerp::lerp(sub_surface_color, ground, (wd / 3.0).clamped(0.0, 1.0)))
.unwrap_or(ground);
let (sub_surface_color, ground, alt, basement) = if mesa > 0.0 {
let marble_big = (sim.gen_ctx.hill_nz.get((wposf3d.div(128.0)).into_array()) as f32)
.mul(0.75)
.add(1.0)
.mul(0.5);
let cliff_scale = 130.0;
let cliff2_scale = 50.0;
let cliff_offset = |scale: f32| {
let x = (alt * 0.95 * (1.0 / scale) + marble_mixed * 0.07).fract() - 0.75;
if x > 0.0 { x * 3.0 * scale } else { -x * scale }
};
let mesa_alt = alt
+ Lerp::lerp(
cliff_offset(cliff_scale),
cliff_offset(cliff2_scale),
((marble_big - 0.5) * 3.0 + (marble_mixed - 0.5) * 0.0).clamped(-0.5, 0.5)
+ 0.5,
) * 0.9;
let alt = Lerp::lerp(alt, mesa_alt, mesa.powf(2.0) * warp_factor);
let idx = alt * 0.35 + (alt * 0.35 + marble * 10.0).sin();
let mesa_color = Lerp::lerp(
Rgb::from(
mesa_layers
.choose(&mut RandomPerm::new(idx as u32))
.copied()
.unwrap_or_default(),
),
Rgb::from(
mesa_layers
.choose(&mut RandomPerm::new(idx as u32 + 1))
.copied()
.unwrap_or_default(),
),
idx.fract(),
);
let sub_surface_color = Lerp::lerp(sub_surface_color, mesa_color, mesa.powf(0.25));
let basement = Lerp::lerp(
basement,
alt,
(mesa * (marble_mixed - 0.35) * 1.5).clamped(0.0, 1.0) * warp_factor,
);
(sub_surface_color, ground, alt, basement)
} else {
(sub_surface_color, ground, alt, basement)
};
// Ground under thick trees should be receive less sunlight and so often become
// dirt
let ground = Lerp::lerp(ground, sub_surface_color, marble_mid * tree_density);

View File

@ -2472,15 +2472,19 @@ impl SimChunk {
let mut alt = CONFIG.sea_level.add(alt_pre);
let basement = CONFIG.sea_level.add(basement_pre);
let water_alt = CONFIG.sea_level.add(water_alt_pre);
let downhill = if downhill_pre == -2 {
None
let (downhill, _gradient) = if downhill_pre == -2 {
(None, 0.0)
} else if downhill_pre < 0 {
panic!("Uh... shouldn't this never, ever happen?");
} else {
Some(
uniform_idx_as_vec2(map_size_lg, downhill_pre as usize)
* TerrainChunkSize::RECT_SIZE.map(|e| e as i32)
+ TerrainChunkSize::RECT_SIZE.map(|e| e as i32 / 2),
(
Some(
uniform_idx_as_vec2(map_size_lg, downhill_pre as usize)
* TerrainChunkSize::RECT_SIZE.map(|e| e as i32)
+ TerrainChunkSize::RECT_SIZE.map(|e| e as i32 / 2),
),
(alt_pre - gen_cdf.alt[downhill_pre as usize] as f32).abs()
/ TerrainChunkSize::RECT_SIZE.x as f32,
)
};
@ -2528,10 +2532,12 @@ impl SimChunk {
let tree_density = if is_underwater {
0.0
} else {
let tree_density = (gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array()))
.mul(0.75)
.add(0.55)
.clamp(0.0, 1.0);
let tree_density = Lerp::lerp(
-1.5,
2.5,
gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array()) * 0.5 + 0.5,
)
.clamp(0.0, 1.0);
// Tree density should go (by a lot) with humidity.
if humidity <= 0.0 || tree_density <= 0.0 {
0.0
@ -2546,8 +2552,9 @@ impl SimChunk {
.add(0.5)
} as f32;
const MIN_TREE_HUM: f32 = 0.15;
// Tree density increases exponentially with humidity...
let tree_density = (tree_density * (humidity - MIN_TREE_HUM).max(0.0).mul(1.0 + MIN_TREE_HUM) / temp.max(0.75))
let tree_density = tree_density
// Tree density increases exponentially with humidity...
.mul((humidity - MIN_TREE_HUM).max(0.0).mul(1.0 + MIN_TREE_HUM) / temp.max(0.75))
// Places that are *too* wet (like marshes) also get fewer trees because the ground isn't stable enough for
// them.
//.mul((1.0 - flux * 0.05/*(humidity - 0.9).max(0.0) / 0.1*/).max(0.0))

View File

@ -27,9 +27,7 @@ impl SavannahPit {
};
Self {
bounds,
alt: land.get_alt_approx(site.tile_center_wpos((tile_aabr.max - tile_aabr.min) / 2))
as i32
+ 2,
alt: land.get_alt_approx(site.tile_center_wpos(tile_aabr.center())) as i32 + 2,
}
}
}