Skip to content

Commit

Permalink
Add noise painter modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaTK committed Aug 8, 2023
1 parent 4978682 commit e42783c
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 20 deletions.
2 changes: 2 additions & 0 deletions addons/gaea/generators/generator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static func get_tiles_of_type(type: TileInfo, grid: Dictionary) -> Array[Vector2

### Steps ###


func _draw_tiles() -> void:
var terrains: Dictionary
for tile in grid:
Expand All @@ -123,6 +124,7 @@ func _draw_tiles() -> void:
tile_info.terrain_set, tile_info.terrain
)


func _apply_modifiers(modifiers: Array[Modifier]) -> void:
for modifier in modifiers:
if not (modifier is Modifier):
Expand Down
5 changes: 3 additions & 2 deletions addons/gaea/modifiers/fill.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://dhj5tue5b4xee"
path="res://.godot/imported/fill.svg-ec2be405a48fb20393b6f64386305662.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
5 changes: 3 additions & 2 deletions addons/gaea/modifiers/generate_borders.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://bi1ap5r85f6yh"
path="res://.godot/imported/generate_borders.svg-370d223e8b1e5807fdc98a385a72d72c.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
36 changes: 36 additions & 0 deletions addons/gaea/modifiers/noise_painter.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@tool
@icon("noise_painter.svg")
class_name NoisePainter
extends Modifier
## Replaces the tiles in the map with [param tile] based on a noise texture.
##
## Useful for placing ores or decorations.


@export var noise: FastNoiseLite = FastNoiseLite.new()
@export var random_noise_seed := true
@export var tile: TileInfo
## Any values in the noise texture that go above this threshold
## will be replaced with [param tile]. (-1.0 is black, 1.0 is white)
@export var threshold: float = 0.6
@export_group("Bounds")
## Leave any or both axis as [code]inf[/code] to not have any limits.
@export var max := Vector2(INF, INF)
## Leave any or both axis as [code]-inf[/code] to not have any limits.
@export var min := Vector2(-INF, -INF)


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

for tile_pos in grid.keys():
if _is_out_of_bounds(tile_pos):
continue
if noise.get_noise_2dv(tile_pos) > threshold:
grid[tile_pos] = tile
return grid


func _is_out_of_bounds(tile_pos: Vector2) -> bool:
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 change: 1 addition & 0 deletions addons/gaea/modifiers/noise_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/noise_painter.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b8v10j7odcypp"
path="res://.godot/imported/noise_painter.svg-96075148f66f2f08ed38499ed61359ae.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

[deps]

source_file="res://addons/gaea/modifiers/noise_painter.svg"
dest_files=["res://.godot/imported/noise_painter.svg-96075148f66f2f08ed38499ed61359ae.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
5 changes: 3 additions & 2 deletions addons/gaea/modifiers/smooth.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://7upd5olshig5"
path="res://.godot/imported/smooth.svg-aa9008b20913c477aa5034ce7d7061b9.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
5 changes: 3 additions & 2 deletions addons/gaea/modifiers/walls.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://iors6wiv6esb"
path="res://.godot/imported/walls.svg-82e0a16c1f7882576e195391b523ce5f.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
6 changes: 5 additions & 1 deletion docs/modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ An example without the Walls modifier looks like this:

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

### Noise Painter

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

### Remove Disconnected

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

_**TODO**: Better explanations._
110 changes: 105 additions & 5 deletions scenes/demos/heightmap/heightmap_demo.tscn

Large diffs are not rendered by default.

Binary file added 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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

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

[deps]

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

[params]

Expand Down
Binary file removed scenes/demos/walker/dungeon-tileset - Pixel_Poem.png
Binary file not shown.
Loading

0 comments on commit e42783c

Please sign in to comment.