|
1 | 1 | extends Control |
2 | 2 |
|
3 | | -#The OpenSimplexNoise object |
| 3 | +# The OpenSimplexNoise object. |
4 | 4 | var noise = OpenSimplexNoise.new() |
5 | 5 | var noise_texture = NoiseTexture.new() |
6 | 6 |
|
7 | | -#Various noise parameters |
8 | | -var noise_size = 500 |
| 7 | +# Various noise parameters. |
9 | 8 | var min_noise = -1 |
10 | 9 | var max_noise = 1 |
11 | 10 |
|
12 | | -#Are we using a NoiseTexture instead? |
13 | | -#Noise textures automatically grab and apply the noise data to an ImageTexture, instead of manually |
| 11 | +# Are we using a NoiseTexture instead? |
| 12 | +# Noise textures automatically grab and apply the noise data to an ImageTexture, instead of manually. |
14 | 13 | const use_noise_texture = false |
15 | 14 |
|
16 | 15 | # Called when the node enters the scene tree for the first time. |
17 | 16 | func _ready(): |
18 | | - |
19 | | - #Set up noise with basic info |
| 17 | + # Set up noise with basic info. |
20 | 18 | $ParameterContainer/SeedSpinBox.value = noise.seed |
21 | 19 | $ParameterContainer/LacunaritySpinBox.value = noise.lacunarity |
22 | 20 | $ParameterContainer/OctavesSpinBox.value = noise.octaves |
23 | 21 | $ParameterContainer/PeriodSpinBox.value = noise.period |
24 | 22 | $ParameterContainer/PersistenceSpinBox.value = noise.persistence |
25 | 23 |
|
26 | | - #Render the noise |
| 24 | + # Render the noise. |
27 | 25 | _refresh_noise_images() |
28 | 26 |
|
29 | | - #Do we need to set up a noise texture? |
| 27 | + # Do we need to set up a noise texture? |
30 | 28 | if use_noise_texture: |
31 | 29 | noise_texture.noise = noise |
32 | 30 | $SeamlessNoiseTexture.texture = noise_texture |
33 | 31 |
|
34 | 32 |
|
35 | 33 | func _refresh_noise_images(): |
36 | | - |
37 | | - #Adjust min/max for shader |
| 34 | + # Adjust min/max for shader. |
38 | 35 | var _min = ((min_noise + 1)/2) |
39 | 36 | var _max = ((max_noise + 1)/2) |
40 | 37 | var _material = $SeamlessNoiseTexture.material |
41 | 38 | _material.set_shader_param("min_value", _min) |
42 | 39 | _material.set_shader_param("max_value", _max) |
43 | 40 |
|
44 | | - #Are we using noise textures instead? |
| 41 | + # Are we using noise textures instead? |
45 | 42 | if use_noise_texture: |
46 | 43 | return |
47 | 44 |
|
48 | | - #Get a new image if we aren't using a NoiseTexture |
| 45 | + # Get a new image if we aren't using a NoiseTexture. |
49 | 46 | var image = noise.get_seamless_image(500) |
50 | 47 | var image_texture = ImageTexture.new() |
51 | 48 |
|
52 | | - #Draw it |
| 49 | + # Draw it. |
53 | 50 | image_texture.create_from_image(image) |
54 | 51 | $SeamlessNoiseTexture.texture = image_texture |
55 | 52 |
|
56 | 53 |
|
57 | 54 | func _on_DocumentationButton_pressed(): |
| 55 | + #warning-ignore:return_value_discarded |
58 | 56 | OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_opensimplexnoise.html") |
59 | 57 |
|
60 | 58 |
|
61 | 59 | func _on_SeedSpinBox_value_changed(value): |
62 | | - |
63 | | - #Update the noise seed |
64 | 60 | noise.seed = value |
65 | 61 | _refresh_noise_images() |
66 | 62 |
|
67 | 63 |
|
68 | 64 | func _on_LacunaritySpinBox_value_changed(value): |
69 | | - |
70 | | - #Update noise |
71 | 65 | noise.lacunarity = value |
72 | 66 | _refresh_noise_images() |
73 | 67 |
|
74 | 68 |
|
75 | 69 | func _on_OctavesSpinBox_value_changed(value): |
76 | | - |
77 | | - #Update noise |
78 | 70 | noise.octaves = value |
79 | 71 | _refresh_noise_images() |
80 | 72 |
|
81 | 73 |
|
82 | 74 | func _on_PeriodSpinBox_value_changed(value): |
83 | | - |
84 | | - #Update noise |
85 | 75 | noise.period = value |
86 | 76 | _refresh_noise_images() |
87 | 77 |
|
88 | 78 |
|
89 | 79 | func _on_PersistenceSpinBox_value_changed(value): |
90 | | - |
91 | | - #Update noise |
92 | 80 | noise.persistence = value |
93 | 81 | _refresh_noise_images() |
94 | 82 |
|
95 | 83 |
|
96 | 84 | func _on_MinClipSpinBox_value_changed(value): |
97 | | - |
98 | | - #Just refresh |
99 | 85 | min_noise = value |
100 | 86 | _refresh_noise_images() |
101 | 87 |
|
102 | 88 |
|
103 | 89 | func _on_MaxClipSpinBox_value_changed(value): |
104 | | - |
105 | | - #Just refresh |
106 | 90 | max_noise = value |
107 | 91 | _refresh_noise_images() |
108 | | - |
0 commit comments