-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathff_api_perlin_noise--get_perlin_octaves_v.0.1.lua
69 lines (60 loc) · 1.72 KB
/
ff_api_perlin_noise--get_perlin_octaves_v.0.1.lua
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
57
58
59
60
61
62
63
64
65
66
67
68
-- perlin noise - get_perlin_octaves(x, y, z,channel) v.0.1
function prepare()
-- constants
amp_c = 1.731628995
rough_c = 0.00001
min_c = 0.00001
-- input values
details = get_slider_input(DETAILS) * 25
noise_size = get_slider_input(SCALE)
roughness = rough_c +
(get_slider_input(ROUGHNESS) + 0.25) * (1.0 - rough_c)
set_perlin_noise_seed(get_intslider_input(SEED))
end;
function get_sample(x, y)
local r, g, b, a = get_sample_map(x, y, BACKGROUND)
local noise_r, noise_g, noise_b, noise_a = get_sample_map(x, y, NOISE)
local z = 0
local alpha = get_perlin_octaves(x, y, z, 1)
r, g, b, a = blend_normal(r, g, b, a, noise_r, noise_g, noise_b, noise_a, alpha)
return r, g, b, a
end;
function get_perlin_octaves(x, y, z,channel)
octaves_n = math.floor(details)
local remainder = details - octaves_n
if (remainder > min_c) then
octaves_n = octaves_n + 1
end
octaves = {}
local cell_size = (0.01 + noise_size * 0.99) * 1000
local scale = roughness
local octave_index
for octave_index = 1, octaves_n do
if (scale < rough_c) then
octaves_n = octave_index - 1
break
end
octaves[octave_index] = {cell_size, scale}
cell_size = cell_size * 0.5
scale = scale * roughness
end
if (remainder >= 0.001) then
octaves[octaves_n][2] = octaves[octaves_n][2] * remainder
end
norm = 0
for octave_index = 1, octaves_n do
norm = norm + octaves[octave_index][2] ^ 2
end
norm = 1 / math.sqrt(norm)
local alpha = 0
local octave_index
for octave_index = 1, octaves_n do
local size = octaves[octave_index][1]
local opacity = octaves[octave_index][2]
z = octave_index
alpha = alpha + opacity * (2 * get_perlin_noise(x, y, z, size) - 1)
end
alpha = (alpha * norm + amp_c) *
(0.5 / amp_c)
return alpha
end;