Skip to content

Commit e42783c

Browse files
committed
Add noise painter modifier
1 parent 4978682 commit e42783c

14 files changed

+205
-20
lines changed

addons/gaea/generators/generator.gd

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static func get_tiles_of_type(type: TileInfo, grid: Dictionary) -> Array[Vector2
9898

9999
### Steps ###
100100

101+
101102
func _draw_tiles() -> void:
102103
var terrains: Dictionary
103104
for tile in grid:
@@ -123,6 +124,7 @@ func _draw_tiles() -> void:
123124
tile_info.terrain_set, tile_info.terrain
124125
)
125126

127+
126128
func _apply_modifiers(modifiers: Array[Modifier]) -> void:
127129
for modifier in modifiers:
128130
if not (modifier is Modifier):

addons/gaea/modifiers/fill.svg.import

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type="CompressedTexture2D"
55
uid="uid://dhj5tue5b4xee"
66
path="res://.godot/imported/fill.svg-ec2be405a48fb20393b6f64386305662.ctex"
77
metadata={
8+
"has_editor_variant": true,
89
"vram_texture": false
910
}
1011

@@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
3334
process/size_limit=0
3435
detect_3d/compress_to=1
3536
svg/scale=1.0
36-
editor/scale_with_editor_scale=false
37-
editor/convert_colors_with_editor_theme=false
37+
editor/scale_with_editor_scale=true
38+
editor/convert_colors_with_editor_theme=true

addons/gaea/modifiers/generate_borders.svg.import

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type="CompressedTexture2D"
55
uid="uid://bi1ap5r85f6yh"
66
path="res://.godot/imported/generate_borders.svg-370d223e8b1e5807fdc98a385a72d72c.ctex"
77
metadata={
8+
"has_editor_variant": true,
89
"vram_texture": false
910
}
1011

@@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
3334
process/size_limit=0
3435
detect_3d/compress_to=1
3536
svg/scale=1.0
36-
editor/scale_with_editor_scale=false
37-
editor/convert_colors_with_editor_theme=false
37+
editor/scale_with_editor_scale=true
38+
editor/convert_colors_with_editor_theme=true
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@tool
2+
@icon("noise_painter.svg")
3+
class_name NoisePainter
4+
extends Modifier
5+
## Replaces the tiles in the map with [param tile] based on a noise texture.
6+
##
7+
## Useful for placing ores or decorations.
8+
9+
10+
@export var noise: FastNoiseLite = FastNoiseLite.new()
11+
@export var random_noise_seed := true
12+
@export var tile: TileInfo
13+
## Any values in the noise texture that go above this threshold
14+
## will be replaced with [param tile]. (-1.0 is black, 1.0 is white)
15+
@export var threshold: float = 0.6
16+
@export_group("Bounds")
17+
## Leave any or both axis as [code]inf[/code] to not have any limits.
18+
@export var max := Vector2(INF, INF)
19+
## Leave any or both axis as [code]-inf[/code] to not have any limits.
20+
@export var min := Vector2(-INF, -INF)
21+
22+
23+
func apply(grid: Dictionary, _generator: GaeaGenerator) -> Dictionary:
24+
if random_noise_seed:
25+
noise.seed = randi()
26+
27+
for tile_pos in grid.keys():
28+
if _is_out_of_bounds(tile_pos):
29+
continue
30+
if noise.get_noise_2dv(tile_pos) > threshold:
31+
grid[tile_pos] = tile
32+
return grid
33+
34+
35+
func _is_out_of_bounds(tile_pos: Vector2) -> bool:
36+
return tile_pos.x > max.x or tile_pos.y > max.y or tile_pos.x < min.x or tile_pos.y < min.y
+1
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://b8v10j7odcypp"
6+
path="res://.godot/imported/noise_painter.svg-96075148f66f2f08ed38499ed61359ae.ctex"
7+
metadata={
8+
"has_editor_variant": true,
9+
"vram_texture": false
10+
}
11+
12+
[deps]
13+
14+
source_file="res://addons/gaea/modifiers/noise_painter.svg"
15+
dest_files=["res://.godot/imported/noise_painter.svg-96075148f66f2f08ed38499ed61359ae.ctex"]
16+
17+
[params]
18+
19+
compress/mode=0
20+
compress/high_quality=false
21+
compress/lossy_quality=0.7
22+
compress/hdr_compression=1
23+
compress/normal_map=0
24+
compress/channel_pack=0
25+
mipmaps/generate=false
26+
mipmaps/limit=-1
27+
roughness/mode=0
28+
roughness/src_normal=""
29+
process/fix_alpha_border=true
30+
process/premult_alpha=false
31+
process/normal_map_invert_y=false
32+
process/hdr_as_srgb=false
33+
process/hdr_clamp_exposure=false
34+
process/size_limit=0
35+
detect_3d/compress_to=1
36+
svg/scale=1.0
37+
editor/scale_with_editor_scale=true
38+
editor/convert_colors_with_editor_theme=true

addons/gaea/modifiers/smooth.svg.import

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type="CompressedTexture2D"
55
uid="uid://7upd5olshig5"
66
path="res://.godot/imported/smooth.svg-aa9008b20913c477aa5034ce7d7061b9.ctex"
77
metadata={
8+
"has_editor_variant": true,
89
"vram_texture": false
910
}
1011

@@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
3334
process/size_limit=0
3435
detect_3d/compress_to=1
3536
svg/scale=1.0
36-
editor/scale_with_editor_scale=false
37-
editor/convert_colors_with_editor_theme=false
37+
editor/scale_with_editor_scale=true
38+
editor/convert_colors_with_editor_theme=true

addons/gaea/modifiers/walls.svg.import

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type="CompressedTexture2D"
55
uid="uid://iors6wiv6esb"
66
path="res://.godot/imported/walls.svg-82e0a16c1f7882576e195391b523ce5f.ctex"
77
metadata={
8+
"has_editor_variant": true,
89
"vram_texture": false
910
}
1011

@@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
3334
process/size_limit=0
3435
detect_3d/compress_to=1
3536
svg/scale=1.0
36-
editor/scale_with_editor_scale=false
37-
editor/convert_colors_with_editor_theme=false
37+
editor/scale_with_editor_scale=true
38+
editor/convert_colors_with_editor_theme=true

docs/modifiers.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ An example without the Walls modifier looks like this:
3636

3737
![without walls modifier](assets/walls-modifier-showcase-before.png)
3838

39+
### Noise Painter
40+
41+
Replaces tiles in the map with another tile based on a noise texture and a threshold.
42+
3943
### Remove Disconnected
4044

41-
Uses flood fill to remove all tiles that aren't connected to starting_tile.
45+
Uses flood fill to remove all tiles that aren't connected to `starting_tile`.
4246

4347
_**TODO**: Better explanations._

scenes/demos/heightmap/heightmap_demo.tscn

+105-5
Large diffs are not rendered by default.

scenes/demos/heightmap/ores.png

479 Bytes
Loading

scenes/demos/walker/dungeon-tileset - Pixel_Poem.png.import scenes/demos/heightmap/ores.png.import

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
importer="texture"
44
type="CompressedTexture2D"
5-
uid="uid://clw7caw7l8w5n"
6-
path="res://.godot/imported/dungeon-tileset - Pixel_Poem.png-0d253906626af1fde8597005addaed6f.ctex"
5+
uid="uid://6gwie8e2kpg2"
6+
path="res://.godot/imported/ores.png-965ca0b56f12b26b33092e5330190ebe.ctex"
77
metadata={
88
"vram_texture": false
99
}
1010

1111
[deps]
1212

13-
source_file="res://scenes/demos/walker/dungeon-tileset - Pixel_Poem.png"
14-
dest_files=["res://.godot/imported/dungeon-tileset - Pixel_Poem.png-0d253906626af1fde8597005addaed6f.ctex"]
13+
source_file="res://scenes/demos/heightmap/ores.png"
14+
dest_files=["res://.godot/imported/ores.png-965ca0b56f12b26b33092e5330190ebe.ctex"]
1515

1616
[params]
1717

Binary file not shown.

0 commit comments

Comments
 (0)