diff --git a/src/worldgen.rs b/src/worldgen.rs index 0908009..fe93c60 100644 --- a/src/worldgen.rs +++ b/src/worldgen.rs @@ -338,7 +338,10 @@ pub fn get_sea(heightmap: &Map) -> (HashSet, HashSet) { (sinks, sea) } -pub fn simulate_water(heightmap: &mut Map, rain_map: &Map, sea: &HashSet, sinks: &HashSet) -> Map { +const SALT_REMOVAL: f32 = 0.13; +const SALT_RANGE: f32 = 0.33; + +pub fn simulate_water(heightmap: &mut Map, rain_map: &Map, sea: &HashSet, sinks: &HashSet) -> (Map, Map) { let mut watermap = Map::::new(heightmap.radius, 0.0); let sources = generate_separated_high_points(WATER_SOURCES, WORLD_RADIUS / 10, &rain_map); @@ -363,6 +366,16 @@ pub fn simulate_water(heightmap: &mut Map, rain_map: &Map, sea: &HashS } } + let mut salt = distance_map(watermap.radius, sea.iter().copied()); + normalize(&mut salt, |x| (SALT_RANGE - x).max(0.0) / SALT_RANGE); + + for (coord, rain) in rain_map.iter() { + if *rain > 0.0 { + salt[coord] -= *rain * 0.3; + salt[coord] = salt[coord].max(0.0); + } + } + for sink in sinks.iter() { watermap[*sink] = 10.0; } @@ -409,15 +422,19 @@ pub fn simulate_water(heightmap: &mut Map, rain_map: &Map, sea: &HashS if !watermap.in_range(point + nearby) { continue; } + // Erode ground (down to sea level at most) if this_range > 0 { - heightmap[point + nearby] -= EROSION * watermap[point] / (this_range as f32) / erosion_range_raw.max(1.0).powf(EROSION_EXPONENT); + let water_rate = watermap[point] / (this_range as f32) / erosion_range_raw.max(1.0).powf(EROSION_EXPONENT); + heightmap[point + nearby] -= EROSION * water_rate; heightmap[point + nearby] = heightmap[point + nearby].max(SEA_LEVEL); + salt[point + nearby] -= SALT_REMOVAL * water_rate; // freshwater rivers reduce salt nearby + salt[point + nearby] = salt[point + nearby].max(0.0); } } } } - watermap + (watermap, salt) } struct WindSlice { @@ -554,7 +571,7 @@ pub fn generate_world() -> GeneratedWorld { let (rain, temperature, atmo_humidity) = simulate_air(&heightmap, &sea, CoordVec::new(0, -1), CoordVec::new(1, 0)); - let water = simulate_water(&mut heightmap, &rain, &sea, &sinks); + let (water, salt) = simulate_water(&mut heightmap, &rain, &sea, &sinks); let contours = generate_contours(&heightmap, 0.15); diff --git a/src/worldgen_test.rs b/src/worldgen_test.rs index b806974..3b9aa31 100644 --- a/src/worldgen_test.rs +++ b/src/worldgen_test.rs @@ -16,7 +16,7 @@ fn main() -> Result<()> { let (rain, temperature, atmo_humidity) = simulate_air(&heightmap, &sea, CoordVec::new(0, -1), CoordVec::new(1, 0)); println!("hydro..."); - let water = simulate_water(&mut heightmap, &rain, &sea, &sinks); + let (water, salt) = simulate_water(&mut heightmap, &rain, &sea, &sinks); println!("contours..."); let contours = generate_contours(&heightmap, 0.15); @@ -39,7 +39,7 @@ fn main() -> Result<()> { let row = position.y + WORLD_RADIUS; //let height = ((*value + 1.0) * 127.5) as u8; let green_channel = groundwater[position]; - let red_channel = temperature[position]; + let red_channel = salt[position]; let blue_channel = water[position].min(1.0); image.put_pixel(col as u32, row as u32, Rgb::from([(red_channel * 255.0) as u8, (green_channel * 255.0) as u8, (blue_channel * 255.0) as u8])); }