feat: carve Jajce river into terrain

This commit is contained in:
Rijad Zuzo
2026-07-17 01:05:09 +02:00
parent 5356c34fd7
commit 145b90eb97
25 changed files with 603 additions and 74 deletions
+44 -3
View File
@@ -5,6 +5,7 @@ const HALF_SIZE := MAP_SIZE / 2
const HEIGHT_SCALE := 40.0
const DATA_DIRECTORY := "res://terrain/jajce/data"
const TEXTURE_DIRECTORY := "res://terrain/jajce/textures"
const Watercourse := preload("res://world/jajce/JajceWatercourse.gd")
func _initialize() -> void:
@@ -41,13 +42,15 @@ func _generate() -> void:
var southern_hill := (
11.0 * _elliptical_peak(world_x, world_z, -35.0, -125.0, 130.0, 85.0)
)
var river_trench := -5.0 * exp(-pow((world_x - 25.0) / 18.0, 2.0))
var broad_slope := maxf(0.0, (-world_x - 30.0) * 0.035)
var detail := noise.get_noise_2d(world_x, world_z) * 2.4
var height := (
(ridge + eastern_hill + southern_hill + river_trench + broad_slope + detail)
* outside_play_area
(ridge + eastern_hill + southern_hill + broad_slope + detail) * outside_play_area
)
height = _shape_waterfall_shelf(height, world_x, world_z, detail)
height = _shape_upper_stream(height, world_x, world_z)
height = _shape_plunge_pool(height, world_x, world_z)
height = _shape_downstream_channel(height, world_x, world_z)
height_map.set_pixel(image_x, image_z, Color(height / HEIGHT_SCALE, 0.0, 0.0, 1.0))
terrain.data.import_images(
@@ -64,6 +67,44 @@ func _elliptical_peak(
return exp(-(pow((x - center_x) / width, 2.0) + pow((z - center_z) / depth, 2.0)))
func _shape_waterfall_shelf(height: float, x: float, z: float, detail: float) -> float:
var horizontal_mask := 1.0 - smoothstep(10.0, 28.0, absf(x - Watercourse.WATERFALL_CENTER.x))
var upstream_mask := smoothstep(-76.0, -54.0, z)
var drop_mask := 1.0 - smoothstep(-25.0, -21.0, z)
var shelf_mask := horizontal_mask * upstream_mask * drop_mask
var shelf_height := Watercourse.SHELF_TOP_HEIGHT + detail * 0.08
return lerpf(height, maxf(height, shelf_height), shelf_mask)
func _shape_upper_stream(height: float, x: float, z: float) -> float:
if z < Watercourse.UPPER_STREAM_START_Z or z > Watercourse.UPPER_STREAM_END_Z:
return height
var center_x := Watercourse.upper_stream_center_x(z)
var half_width := Watercourse.upper_stream_half_width(z)
var channel_mask := 1.0 - smoothstep(half_width, half_width + 3.2, absf(x - center_x))
var target_height := minf(height, Watercourse.upper_stream_bed_height(z))
return lerpf(height, target_height, channel_mask)
func _shape_plunge_pool(height: float, x: float, z: float) -> float:
var offset := Vector2(x, z) - Watercourse.PLUNGE_POOL_CENTER
var elliptical_distance := Vector2(offset.x / 10.5, offset.y / 7.8).length()
var basin_mask := 1.0 - smoothstep(0.68, 1.15, elliptical_distance)
var cliff_front_mask := smoothstep(-25.0, -20.5, z)
var target_height := minf(height, Watercourse.PLUNGE_POOL_BED_HEIGHT)
return lerpf(height, target_height, basin_mask * cliff_front_mask)
func _shape_downstream_channel(height: float, x: float, z: float) -> float:
if z < Watercourse.DOWNSTREAM_START_Z or z > Watercourse.DOWNSTREAM_END_Z:
return height
var center_x := Watercourse.downstream_center_x(z)
var half_width := Watercourse.downstream_half_width(z)
var bank_mask := 1.0 - smoothstep(half_width, half_width + 4.5, absf(x - center_x))
var target_height := minf(height, Watercourse.downstream_bed_height(z))
return lerpf(height, target_height, bank_mask)
func _generate_texture(
file_name: String, dark_color: Color, light_color: Color, seed_value: int
) -> void: