From 48ebe004c0a18f0e55eff5aeb4fc420c32440646 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 21 Oct 2023 22:19:32 +0100 Subject: [PATCH 1/6] Added mesa generation --- world/src/column/mod.rs | 49 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index 03cfb8ef8e..5a8c996000 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -864,11 +864,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; @@ -1128,6 +1135,46 @@ 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) = 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 mesa_color = Lerp::lerp( + Lerp::lerp( + Rgb::new(0.6, 0.3, 0.2), + Rgb::new(0.4, 0.03, 0.1), + (alt * 0.2).sin() * 0.5 + 0.5, + ), + Lerp::lerp( + Rgb::new(0.8, 0.5, 0.2), + Rgb::new(0.6, 0.25, 0.25), + (alt * 0.3).sin() * 0.5 + 0.5, + ), + (alt * 0.5).sin() * 0.5 + 0.5, + ); + let sub_surface_color = Lerp::lerp(sub_surface_color, mesa_color, mesa.powf(0.25)); + + (sub_surface_color, ground, alt) + } else { + (sub_surface_color, ground, alt) + }; + // 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); From 05863eb1efcc68a06a4b078d12efe2d3f80cd68b Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 22 Oct 2023 18:21:13 +0100 Subject: [PATCH 2/6] Better mesa layer colours --- assets/world/style/colors.ron | 10 +++++ world/src/column/mod.rs | 70 ++++++++++++++++++----------------- world/src/sim/mod.rs | 31 ++++++++++------ 3 files changed, 66 insertions(+), 45 deletions(-) diff --git a/assets/world/style/colors.ron b/assets/world/style/colors.ron index 0024da6795..fc70b613ce 100644 --- a/assets/world/style/colors.ron +++ b/assets/world/style/colors.ron @@ -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. diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index 5a8c996000..73d24e6ab7 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -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. @@ -926,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 = 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 = 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 = (*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 = (*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); @@ -959,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); @@ -1155,19 +1155,23 @@ impl<'a> Sampler<'a> for ColumnGen<'a> { ) * 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( - Lerp::lerp( - Rgb::new(0.6, 0.3, 0.2), - Rgb::new(0.4, 0.03, 0.1), - (alt * 0.2).sin() * 0.5 + 0.5, + Rgb::from( + mesa_layers + .choose(&mut RandomPerm::new(idx as u32)) + .copied() + .unwrap_or_default(), ), - Lerp::lerp( - Rgb::new(0.8, 0.5, 0.2), - Rgb::new(0.6, 0.25, 0.25), - (alt * 0.3).sin() * 0.5 + 0.5, + Rgb::from( + mesa_layers + .choose(&mut RandomPerm::new(idx as u32 + 1)) + .copied() + .unwrap_or_default(), ), - (alt * 0.5).sin() * 0.5 + 0.5, + idx.fract(), ); + let sub_surface_color = Lerp::lerp(sub_surface_color, mesa_color, mesa.powf(0.25)); (sub_surface_color, ground, alt) diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index b3729c4165..d8bdc52a12 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -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)) From 83dc22dfbf264588bc1049688e4470481f37d1c9 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 22 Oct 2023 18:21:25 +0100 Subject: [PATCH 3/6] Made ice reflective --- assets/voxygen/shaders/clouds-frag.glsl | 6 +++++- assets/voxygen/shaders/include/constants.glsl | 1 + assets/voxygen/shaders/rope-frag.glsl | 2 +- assets/voxygen/shaders/rope-vert.glsl | 2 +- assets/voxygen/shaders/terrain-frag.glsl | 11 ++++++++++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 21fdbc60fb..2ea6e1f3af 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -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)); diff --git a/assets/voxygen/shaders/include/constants.glsl b/assets/voxygen/shaders/include/constants.glsl index 2ffb537df6..e1f4c01884 100644 --- a/assets/voxygen/shaders/include/constants.glsl +++ b/assets/voxygen/shaders/include/constants.glsl @@ -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). diff --git a/assets/voxygen/shaders/rope-frag.glsl b/assets/voxygen/shaders/rope-frag.glsl index d7cc9e487c..65779f060d 100644 --- a/assets/voxygen/shaders/rope-frag.glsl +++ b/assets/voxygen/shaders/rope-frag.glsl @@ -1,4 +1,4 @@ -#version 420 core +#version 430 core #define FIGURE_SHADER diff --git a/assets/voxygen/shaders/rope-vert.glsl b/assets/voxygen/shaders/rope-vert.glsl index d01917b1b3..01859636fe 100644 --- a/assets/voxygen/shaders/rope-vert.glsl +++ b/assets/voxygen/shaders/rope-vert.glsl @@ -1,4 +1,4 @@ -#version 420 core +#version 430 core #include diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index e5a0af2277..0176e41f56 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -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); } From 23e239275c5b8f1becf4e143751bff39d3bf96b8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 23 Oct 2023 21:10:18 +0100 Subject: [PATCH 4/6] Better mesa basement --- world/src/column/mod.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index 73d24e6ab7..f625a48648 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -1135,7 +1135,7 @@ 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) = if mesa > 0.0 { + 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) @@ -1174,9 +1174,15 @@ impl<'a> Sampler<'a> for ColumnGen<'a> { let sub_surface_color = Lerp::lerp(sub_surface_color, mesa_color, mesa.powf(0.25)); - (sub_surface_color, ground, alt) + let basement = Lerp::lerp( + basement, + alt, + (mesa * (marble_mixed - 0.35) * 1.5).clamped(0.0, 1.0), + ); + + (sub_surface_color, ground, alt, basement) } else { - (sub_surface_color, ground, alt) + (sub_surface_color, ground, alt, basement) }; // Ground under thick trees should be receive less sunlight and so often become From 84e59c52fbcdba110fd036b5892db296030ceac9 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 24 Oct 2023 12:38:30 +0100 Subject: [PATCH 5/6] Made portal fizz better convey access --- assets/voxygen/shaders/particle-vert.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index 3f34e42159..4e8d9b0a79 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -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) ); From 5418f49ecb8a21f613969fa80000edc6f510d6a8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 2 Nov 2023 14:48:10 +0000 Subject: [PATCH 6/6] Fixed broken savannah pit altitude --- world/src/column/mod.rs | 2 +- world/src/site2/plot/savannah_pit.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index f625a48648..4ed831deb0 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -1177,7 +1177,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> { let basement = Lerp::lerp( basement, alt, - (mesa * (marble_mixed - 0.35) * 1.5).clamped(0.0, 1.0), + (mesa * (marble_mixed - 0.35) * 1.5).clamped(0.0, 1.0) * warp_factor, ); (sub_surface_color, ground, alt, basement) diff --git a/world/src/site2/plot/savannah_pit.rs b/world/src/site2/plot/savannah_pit.rs index 94ec4dad8a..523ed876ec 100644 --- a/world/src/site2/plot/savannah_pit.rs +++ b/world/src/site2/plot/savannah_pit.rs @@ -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, } } }