Skip to content

Commit

Permalink
Adds HeightmapPainter modifier
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
BenjaTK committed Aug 8, 2023
1 parent c9a9e53 commit 89acfc1
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 92 deletions.
28 changes: 28 additions & 0 deletions addons/gaea/modifiers/heightmap_painter.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@tool
@icon("heightmap_painter.svg")
class_name HeightmapPainter
extends Modifier
## Replaces tiles in the map with [param tile] based on a noise heightmap.


@export var noise: FastNoiseLite = FastNoiseLite.new()
@export var random_noise_seed := true
@export var tile: TileInfo
## The medium height at which the painter will start replacing tiles.
## The heightmap displaces this height by a random number
## between -[param height_intensity] and [param height_intensity].
@export var height_offset := 128
## The heightmap displaces [param height_offset] by a random number
## from -[param height_intensity] to [param height_intensity].
@export var height_intensity := 20


func apply(grid: Dictionary, generator: GaeaGenerator) -> Dictionary:
if random_noise_seed:
noise.seed = randi()

for tile_pos in grid.keys():
var height = floor(noise.get_noise_1d(tile_pos.x) * height_intensity + height_offset)
if tile_pos.y >= -height:
grid[tile_pos] = tile
return grid
1 change: 1 addition & 0 deletions addons/gaea/modifiers/heightmap_painter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions addons/gaea/modifiers/heightmap_painter.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cpr55vjlgktnu"
path="res://.godot/imported/heightmap_painter.svg-685fb9a529f4b41cf3fdbd99488425b3.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

[deps]

source_file="res://addons/gaea/modifiers/heightmap_painter.svg"
dest_files=["res://.godot/imported/heightmap_painter.svg-685fb9a529f4b41cf3fdbd99488425b3.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
7 changes: 6 additions & 1 deletion docs/modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There are a few modifiers in Gaea at the moment:

Generate border tiles around already placed tiles.

### Fill
### Fill

Fills the full rectangle of tiles.

Expand Down Expand Up @@ -40,8 +40,13 @@ An example without the Walls modifier looks like this:

Replaces tiles in the map with another tile based on a noise texture and a threshold.

### Heightmap Painter

Replaces tiles in the map with another tile based on a noise heightmap.

### Remove Disconnected

Uses flood fill to remove all tiles that aren't connected to `starting_tile`.


_**TODO**: Better explanations._
130 changes: 39 additions & 91 deletions scenes/demos/heightmap/heightmap_demo.tscn

Large diffs are not rendered by default.

Binary file modified scenes/demos/heightmap/ores.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions scenes/demos/heightmap/terraria-like_generation_settings.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
[gd_resource type="Resource" script_class="HeightmapGenerator2DSettings" load_steps=22 format=3 uid="uid://db18nmw5jkbtc"]

[ext_resource type="Script" path="res://addons/gaea/modifiers/heightmap_painter.gd" id="1_xfnry"]
[ext_resource type="Script" path="res://addons/gaea/generators/tile_info.gd" id="2_6f082"]
[ext_resource type="Script" path="res://addons/gaea/modifiers/carver.gd" id="3_51wbb"]
[ext_resource type="Script" path="res://addons/gaea/modifiers/noise_painter.gd" id="4_cgpdt"]
[ext_resource type="Script" path="res://addons/gaea/generators/heightmap_generator/heightmap_generator_2d_settings.gd" id="5_haojk"]

[sub_resource type="FastNoiseLite" id="FastNoiseLite_pl5m1"]
seed = -1007263643

[sub_resource type="Resource" id="Resource_jm03i"]
script = ExtResource("2_6f082")
type = 0
layer = 0
source_id = 1
atlas_coord = Vector2i(0, 0)
alternative_tile = 0

[sub_resource type="Resource" id="Resource_ud61g"]
resource_name = "Stone"
script = ExtResource("1_xfnry")
noise = SubResource("FastNoiseLite_pl5m1")
random_noise_seed = true
tile = SubResource("Resource_jm03i")
threshold = 0.6
height_offset = 145
height_intensity = 5

[sub_resource type="FastNoiseLite" id="FastNoiseLite_macji"]
seed = 701514640

[sub_resource type="Resource" id="Resource_fvob8"]
script = ExtResource("2_6f082")
type = 0
layer = 0
source_id = 1
atlas_coord = Vector2i(0, 1)
alternative_tile = 0

[sub_resource type="Resource" id="Resource_c7ke6"]
resource_name = "Bedrock"
script = ExtResource("1_xfnry")
noise = SubResource("FastNoiseLite_macji")
random_noise_seed = true
tile = SubResource("Resource_fvob8")
threshold = 0.6
height_offset = 2
height_intensity = 3

[sub_resource type="FastNoiseLite" id="FastNoiseLite_uxcj3"]
noise_type = 3
seed = -498798840
frequency = 0.012
fractal_type = 2
fractal_octaves = 3
domain_warp_frequency = 0.57

[sub_resource type="Resource" id="Resource_gma4i"]
resource_name = "Caves"
script = ExtResource("3_51wbb")
noise = SubResource("FastNoiseLite_uxcj3")
random_noise_seed = true
threshold = 0.8
max_height = 145
max_height_random = 1.0

[sub_resource type="FastNoiseLite" id="FastNoiseLite_n7hry"]
seed = 1592526331
frequency = 0.0617
fractal_octaves = 2
fractal_lacunarity = 2.95

[sub_resource type="Resource" id="Resource_d1s74"]
script = ExtResource("2_6f082")
type = 0
layer = 0
source_id = 1
atlas_coord = Vector2i(2, 0)
alternative_tile = 0

[sub_resource type="Resource" id="Resource_x7aqc"]
resource_name = "Gold Ore"
script = ExtResource("4_cgpdt")
noise = SubResource("FastNoiseLite_n7hry")
random_noise_seed = true
tile = SubResource("Resource_d1s74")
threshold = 0.65
max = Vector2(inf, inf)
min = Vector2(inf_neg, -120)

[sub_resource type="FastNoiseLite" id="FastNoiseLite_77hcd"]
seed = 1028908029
frequency = 0.0511
fractal_lacunarity = 0.565
domain_warp_type = 2
domain_warp_amplitude = 30.52

[sub_resource type="Resource" id="Resource_efh25"]
script = ExtResource("2_6f082")
type = 0
layer = 0
source_id = 1
atlas_coord = Vector2i(1, 0)
alternative_tile = 0

[sub_resource type="Resource" id="Resource_blv43"]
resource_name = "Diamond Ore"
script = ExtResource("4_cgpdt")
noise = SubResource("FastNoiseLite_77hcd")
random_noise_seed = true
tile = SubResource("Resource_efh25")
threshold = 0.6
max = Vector2(inf, inf)
min = Vector2(inf_neg, -100)

[sub_resource type="FastNoiseLite" id="FastNoiseLite_vcq1r"]
noise_type = 3
seed = 1472160431

[sub_resource type="Resource" id="Resource_ja6xv"]
script = ExtResource("2_6f082")
type = 1
layer = 0
terrain_set = 0
terrain = 0

[resource]
resource_name = "Terraria-like Settings"
script = ExtResource("5_haojk")
tile = SubResource("Resource_ja6xv")
noise = SubResource("FastNoiseLite_vcq1r")
random_noise_seed = true
world_length = 128
height_offset = 160
height_intensity = 25
modifiers = Array[Resource("res://addons/gaea/modifiers/modifier.gd")]([SubResource("Resource_ud61g"), SubResource("Resource_c7ke6"), SubResource("Resource_gma4i"), SubResource("Resource_x7aqc"), SubResource("Resource_blv43")])

0 comments on commit 89acfc1

Please sign in to comment.