Skip to content

Commit

Permalink
add shore height param to landmass
Browse files Browse the repository at this point in the history
  • Loading branch information
jice-nospam committed Oct 24, 2022
1 parent 823c2b8 commit 7325d4b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Added
- seamless flag on exporter for game engines not supporting multi-texture heightmaps
- now you can export to either 16 bits PNG (preferred format for Unreal Engine) or 16 bits float OpenExr format (for Godot)
- added shore height parameter to landmass generator to avoid z fighting issues between the land mesh and a water plane

### Fixed
- changing the height scale in the 3D preview preserves the water level
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The current version features those generators :
- Fbm : fractal brownian motion can be used to add noise to an existing terrain or as first step to generate a continent-like terrain.
- MidPoint : square-diamond mid-point deplacement generates a realistic looking heightmap
- Normalize : scales the heightmap back to the range 0.0..1.0. Some generators work better with a normalized heightmap. Check your heightmap values range in the 2D preview.
- LandMass : scale the terrain so that a defined proportion is above a defined water level. Also applies a x^3 curve above water level to have a nice plain/mountain ratio
- LandMass : scale the terrain so that a defined proportion is above a defined water level. Also applies a x^3 curve above water level to have a nice plain/mountain ratio and can lower underwater terrain to have a crisp coast line
- MudSlide : smoothen the terrain by simulating earth sliding along slopes
- WaterErosion : carves rivers by simulating rain drops dragging earth along slopes
- Island : lower the altitude along the borders of the map
Expand Down Expand Up @@ -83,4 +83,4 @@ This might be needed for other engines where each tile is an independant terrain
Unreal natively support multi-textures heightmap. All you have to do is to choose the texture size (preferably 1024x1024 or 2048x2048 PNG) and adjust the number of tiles to match your total terrain size. The seamless flag should be unchecked as Unreal automatically joins the tile borders.

## Godot 3
As of version 3.5, Godot only support 8bits PNG so using the PNG format will result in posterization of the heightmap and a staircase effect. So the prefered format here when using the Heightmap Terrain plugin is a single square EXR file with a "power of two plus one" size (1025x1025, 2049x2049 and so on). The EXR file contains values between 0.0 and 1.0 and might be very flat in Godot, so increase the y scale of your HTerrain object to something near 500.
As of version 3.5, Godot only support 8bits PNG so using the PNG format will result in posterization of the heightmap and a staircase effect. So the prefered format here when using the Heightmap Terrain plugin is a single square EXR file with a "power of two plus one" size (1025x1025, 2049x2049 or 4097x4097). The EXR file contains values between 0.0 and 1.0 and might look completely flat in Godot, so increase the y scale of your HTerrain object to something near 500.
2 changes: 1 addition & 1 deletion ex_continent.wgen
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(version:"0.3.1",steps:[(disabled:false,mask:None,typ:Hills((nb_hill:50,base_radius:16.0,radius_var:0.7,height:0.3))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:Fbm((mulx:16.0,muly:16.0,addx:0.0,addy:0.0,octaves:10.0,delta:0.0,scale:0.2))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:Island((coast_range:25.0))),(disabled:false,mask:None,typ:LandMass((land_proportion:0.6,water_level:0.12,plain_factor:1.71))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:WaterErosion((drop_amount:0.5,erosion_strength:0.08,evaporation:0.05,capacity:6.0,min_slope:0.05,deposition:0.06,inertia:0.4,radius:4.0))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:1.0,strength:0.4,water_level:0.0)))],cur_step:(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:0.9,strength:0.4,water_level:0.12))),selected_step:9,move_to_pos:0,hovered:false,seed:3735928559)
(version:"0.3.1",steps:[(disabled:false,mask:None,typ:Hills((nb_hill:50,base_radius:16.0,radius_var:0.7,height:0.3))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:Fbm((mulx:16.0,muly:16.0,addx:0.0,addy:0.0,octaves:10.0,delta:0.0,scale:0.2))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:Island((coast_range:25.0))),(disabled:false,mask:None,typ:LandMass((land_proportion:0.6,water_level:0.12,plain_factor:1.71,shore_height:0.1))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:WaterErosion((drop_amount:0.5,erosion_strength:0.08,evaporation:0.05,capacity:6.0,min_slope:0.05,deposition:0.06,inertia:0.4,radius:4.0))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:1.0,strength:0.4,water_level:0.0)))],cur_step:(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:0.9,strength:0.4,water_level:0.12))),selected_step:9,move_to_pos:0,hovered:false,seed:3735928559)
2 changes: 1 addition & 1 deletion ex_island.wgen
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(version:"0.3.1",steps:[(disabled:false,mask:None,typ:MidPoint((roughness:0.7))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:LandMass((land_proportion:0.6,water_level:0.12,plain_factor:2.5))),(disabled:false,mask:None,typ:Island((coast_range:50.0))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:WaterErosion((drop_amount:0.5,erosion_strength:0.08,evaporation:0.05,capacity:6.0,min_slope:0.05,deposition:0.06,inertia:0.5,radius:4.0))),(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:0.9,strength:0.4,water_level:0.12)))],cur_step:(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:0.9,strength:0.4,water_level:0.12))),selected_step:6,move_to_pos:0,hovered:false,seed:3735928559)
(version:"0.3.1",steps:[(disabled:false,mask:None,typ:MidPoint((roughness:0.7))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:LandMass((land_proportion:0.6,water_level:0.12,plain_factor:2.5,shore_height:0.1))),(disabled:false,mask:None,typ:Island((coast_range:50.0))),(disabled:false,mask:None,typ:Normalize((min:0.0,max:1.0))),(disabled:false,mask:None,typ:WaterErosion((drop_amount:0.5,erosion_strength:0.08,evaporation:0.05,capacity:6.0,min_slope:0.05,deposition:0.06,inertia:0.5,radius:4.0))),(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:0.9,strength:0.4,water_level:0.12)))],cur_step:(disabled:false,mask:None,typ:MudSlide((iterations:5.0,max_erosion_alt:0.9,strength:0.4,water_level:0.12))),selected_step:6,move_to_pos:0,hovered:false,seed:3735928559)
24 changes: 20 additions & 4 deletions src/generators/landmass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ use super::{normalize, report_progress};

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct LandMassConf {
/// what proportion of the map should be above water 0.0-1.0
pub land_proportion: f32,
/// height of the water plane
pub water_level: f32,
/// apply h^plain_factor above sea level for sharper mountains and flatter plains
pub plain_factor: f32,
/// lower everything under water level by this value to avoid z fighting between land and water plane near shores
pub shore_height: f32,
}

impl Default for LandMassConf {
Expand All @@ -20,32 +25,43 @@ impl Default for LandMassConf {
land_proportion: 0.6,
water_level: 0.12,
plain_factor: 2.5,
shore_height: 0.05,
}
}
}

pub fn render_landmass(ui: &mut egui::Ui, conf: &mut LandMassConf) {
ui.horizontal(|ui| {
ui.label("land proportion");
ui.label("land proportion")
.on_hover_text("what proportion of the map should be above water");
ui.add(
egui::DragValue::new(&mut conf.land_proportion)
.speed(0.01)
.clamp_range(0.0..=1.0),
);
ui.label("water level");
ui.label("water level")
.on_hover_text("height of the water plane");
ui.add(
egui::DragValue::new(&mut conf.water_level)
.speed(0.01)
.clamp_range(0.0..=1.0),
);
});
ui.horizontal(|ui| {
ui.label("plain factor");
ui.label("plain factor")
.on_hover_text("increase for sharper mountains and flatter plains");
ui.add(
egui::DragValue::new(&mut conf.plain_factor)
.speed(0.01)
.clamp_range(1.0..=4.0),
);
ui.label("shore height")
.on_hover_text("lower underwater land by this value");
ui.add(
egui::DragValue::new(&mut conf.shore_height)
.speed(0.01)
.clamp_range(0.0..=0.1),
);
});
}

Expand Down Expand Up @@ -91,7 +107,7 @@ pub fn gen_landmass(
if h > new_water_level {
h = conf.water_level + (h - new_water_level) * land_coef;
} else {
h *= water_coef;
h = h * water_coef - conf.shore_height;
}
hmap[x + yoff] = h;
}
Expand Down

0 comments on commit 7325d4b

Please sign in to comment.