-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld_island_algo.odin
More file actions
56 lines (47 loc) · 1.59 KB
/
Copy pathworld_island_algo.odin
File metadata and controls
56 lines (47 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package terrain
import "core:math"
/*
Will fade out the height of the tiles towards target_height, based on distance to the edge.
-> target_height: the height to fade to
-> fade_distance: how far in the fade should start, bigger number == smoother fade
-> fade_amount: the height multiplier to use when at the edge of the map
Eg. if your fade_distance is "5" and fade_amount is "0.35" the fading curve would look like:
|==========|===================|
| Distance | Height Multiplier |
|==========|===================|
| 5 | 1.0 |
|----------|-------------------|
| 4 | 0.87 |
|----------|-------------------|
| 3 | 0.74 |
|----------|-------------------|
| 2 | 0.61 |
|----------|-------------------|
| 1 | 0.47999.. |
|----------|-------------------|
| 0 | 0.34999.. |
|----------|-------------------|
*/
noise_map_to_island :: proc(
hm: [][]f32,
target_height: f32,
fade_distance: int,
fade_amount: f32 = 0.2,
) {
height := len(hm)
width := len(hm[0])
for y in 0 ..< height {
for x in 0 ..< width {
if hm[y][x] <= target_height {
continue
}
dist := distance_to_edge(width, height, x, y)
if dist >= fade_distance {
continue
}
hm[y][x] *=
(fade_amount +
((1.0 - fade_amount) * inverse_lerp(0, f32(fade_distance), f32(dist))))
}
}
}