Skip to content

Commit 5fb8143

Browse files
authored
Merge pull request #642 from nathanfranke/opensimplexnoise-improvements
Simplify and improve OpenSimplexNoise viewer
2 parents 9ea1837 + c3c4fdf commit 5fb8143

File tree

2 files changed

+73
-80
lines changed

2 files changed

+73
-80
lines changed
Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,68 @@
11
extends Control
22

33
# The OpenSimplexNoise object.
4-
var noise = OpenSimplexNoise.new()
5-
var noise_texture = NoiseTexture.new()
4+
onready var noise: OpenSimplexNoise = $SeamlessNoiseTexture.texture.noise
65

76
# Various noise parameters.
87
var min_noise = -1
98
var max_noise = 1
109

11-
# Are we using a NoiseTexture instead?
12-
# Noise textures automatically grab and apply the noise data to an ImageTexture, instead of manually.
13-
const use_noise_texture = false
14-
1510
# Called when the node enters the scene tree for the first time.
1611
func _ready():
1712
# Set up noise with basic info.
1813
$ParameterContainer/SeedSpinBox.value = noise.seed
1914
$ParameterContainer/LacunaritySpinBox.value = noise.lacunarity
20-
$ParameterContainer/OctavesSpinBox.value = noise.octaves
2115
$ParameterContainer/PeriodSpinBox.value = noise.period
2216
$ParameterContainer/PersistenceSpinBox.value = noise.persistence
17+
$ParameterContainer/OctavesSpinBox.value = noise.octaves
2318

2419
# Render the noise.
25-
_refresh_noise_images()
20+
_refresh_shader_params()
2621

27-
# Do we need to set up a noise texture?
28-
if use_noise_texture:
29-
noise_texture.noise = noise
30-
$SeamlessNoiseTexture.texture = noise_texture
3122

32-
33-
func _refresh_noise_images():
23+
func _refresh_shader_params():
3424
# Adjust min/max for shader.
3525
var _min = (min_noise + 1) / 2
3626
var _max = (max_noise + 1) / 2
3727
var _material = $SeamlessNoiseTexture.material
3828
_material.set_shader_param("min_value", _min)
3929
_material.set_shader_param("max_value", _max)
4030

41-
# Are we using noise textures instead?
42-
if use_noise_texture:
43-
return
44-
45-
# Get a new image if we aren't using a NoiseTexture.
46-
var image = noise.get_seamless_image(500)
47-
var image_texture = ImageTexture.new()
48-
49-
# Draw it.
50-
image_texture.create_from_image(image)
51-
$SeamlessNoiseTexture.texture = image_texture
52-
5331

5432
func _on_DocumentationButton_pressed():
5533
#warning-ignore:return_value_discarded
5634
OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_opensimplexnoise.html")
5735

5836

37+
func _on_RandomSeedButton_pressed():
38+
$ParameterContainer/SeedSpinBox.value = floor(rand_range(-2147483648, 2147483648))
39+
40+
5941
func _on_SeedSpinBox_value_changed(value):
6042
noise.seed = value
61-
_refresh_noise_images()
6243

6344

6445
func _on_LacunaritySpinBox_value_changed(value):
6546
noise.lacunarity = value
66-
_refresh_noise_images()
67-
68-
69-
func _on_OctavesSpinBox_value_changed(value):
70-
noise.octaves = value
71-
_refresh_noise_images()
7247

7348

7449
func _on_PeriodSpinBox_value_changed(value):
7550
noise.period = value
76-
_refresh_noise_images()
7751

7852

7953
func _on_PersistenceSpinBox_value_changed(value):
8054
noise.persistence = value
81-
_refresh_noise_images()
55+
56+
57+
func _on_OctavesSpinBox_value_changed(value):
58+
noise.octaves = value
8259

8360

8461
func _on_MinClipSpinBox_value_changed(value):
8562
min_noise = value
86-
_refresh_noise_images()
63+
_refresh_shader_params()
8764

8865

8966
func _on_MaxClipSpinBox_value_changed(value):
9067
max_noise = value
91-
_refresh_noise_images()
68+
_refresh_shader_params()

misc/opensimplexnoise/OpenSimplexNoise_Viewer.tscn

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,82 @@
1-
[gd_scene load_steps=3 format=2]
1+
[gd_scene load_steps=5 format=2]
22

33
[ext_resource path="res://OpenSimplexNoise_Viewer.gd" type="Script" id=1]
44
[ext_resource path="res://OpenSimplexNoise_Viewer.tres" type="Material" id=2]
55

6+
[sub_resource type="OpenSimplexNoise" id=1]
7+
8+
[sub_resource type="NoiseTexture" id=2]
9+
noise = SubResource( 1 )
10+
611
[node name="OpenSimplexNoise Viewer" type="Control"]
712
anchor_right = 1.0
813
anchor_bottom = 1.0
9-
margin_left = 8.42108
10-
margin_top = -5.26315
11-
margin_right = 8.42114
12-
margin_bottom = -5.26318
14+
margin_left = 24.0
15+
margin_top = 24.0
16+
margin_right = -24.0
17+
margin_bottom = -24.0
1318
script = ExtResource( 1 )
1419
__meta__ = {
1520
"_edit_use_anchors_": false
1621
}
1722

18-
[node name="DocumentationButton" type="Button" parent="."]
19-
anchor_left = 1.0
20-
anchor_right = 1.0
21-
margin_left = -170.0
22-
margin_top = 30.0
23-
margin_right = -33.0
24-
margin_bottom = 50.0
25-
grow_horizontal = 0
26-
text = "API Documentation"
27-
__meta__ = {
28-
"_edit_use_anchors_": false
29-
}
30-
3123
[node name="SeamlessNoiseTexture" type="TextureRect" parent="."]
3224
material = ExtResource( 2 )
3325
anchor_left = 0.5
3426
anchor_top = 0.5
3527
anchor_right = 0.5
3628
anchor_bottom = 0.5
37-
margin_left = 40.0
38-
margin_top = -20.0
39-
margin_right = 80.0
40-
margin_bottom = 20.0
29+
margin_left = -196.0
30+
margin_top = -256.0
31+
margin_right = 316.0
32+
margin_bottom = 256.0
4133
grow_horizontal = 2
4234
grow_vertical = 2
35+
texture = SubResource( 2 )
36+
__meta__ = {
37+
"_edit_use_anchors_": false
38+
}
39+
40+
[node name="ButtonsContainer" type="VBoxContainer" parent="."]
41+
anchor_left = 1.0
42+
anchor_right = 1.0
43+
margin_left = -137.0
44+
margin_bottom = 44.0
45+
__meta__ = {
46+
"_edit_use_anchors_": false
47+
}
48+
49+
[node name="DocumentationButton" type="Button" parent="ButtonsContainer"]
50+
margin_right = 137.0
51+
margin_bottom = 20.0
52+
grow_horizontal = 0
53+
text = "API Documentation"
54+
__meta__ = {
55+
"_edit_use_anchors_": false
56+
}
57+
58+
[node name="RandomSeedButton" type="Button" parent="ButtonsContainer"]
59+
margin_top = 24.0
60+
margin_right = 137.0
61+
margin_bottom = 44.0
62+
grow_horizontal = 0
63+
text = "Random Seed"
4364
__meta__ = {
4465
"_edit_use_anchors_": false
4566
}
4667

4768
[node name="ParameterContainer" type="VBoxContainer" parent="."]
48-
margin_left = 20.0
49-
margin_top = 30.0
50-
margin_right = 300.0
51-
margin_bottom = 166.0
69+
margin_right = 280.0
70+
margin_bottom = 136.0
5271
__meta__ = {
5372
"_edit_use_anchors_": false
5473
}
5574

5675
[node name="SeedSpinBox" type="SpinBox" parent="ParameterContainer"]
5776
margin_right = 280.0
5877
margin_bottom = 24.0
59-
min_value = -1.53049e+09
60-
max_value = 1.53049e+09
61-
rounded = true
78+
min_value = -2.14748e+09
79+
max_value = 2.14748e+09
6280
allow_greater = true
6381
allow_lesser = true
6482
prefix = "Seed:"
@@ -67,27 +85,24 @@ prefix = "Seed:"
6785
margin_top = 28.0
6886
margin_right = 280.0
6987
margin_bottom = 52.0
70-
max_value = 1e+08
71-
step = 0.01
88+
step = 0.1
7289
allow_greater = true
7390
prefix = "Lacunarity:"
7491

7592
[node name="PeriodSpinBox" type="SpinBox" parent="ParameterContainer"]
7693
margin_top = 56.0
7794
margin_right = 280.0
7895
margin_bottom = 80.0
79-
min_value = -1e+08
80-
max_value = 1e+08
81-
step = 0.01
96+
min_value = -100000.0
97+
max_value = 100000.0
8298
allow_greater = true
8399
prefix = "Period:"
84100

85101
[node name="PersistenceSpinBox" type="SpinBox" parent="ParameterContainer"]
86102
margin_top = 84.0
87103
margin_right = 280.0
88104
margin_bottom = 108.0
89-
max_value = 1e+08
90-
step = 0.01
105+
max_value = 1000.0
91106
allow_greater = true
92107
prefix = "Persistance:"
93108

@@ -96,19 +111,19 @@ margin_top = 112.0
96111
margin_right = 280.0
97112
margin_bottom = 136.0
98113
min_value = 1.0
99-
max_value = 10.0
114+
max_value = 9.0
100115
value = 1.0
101-
allow_greater = true
102116
prefix = "Octaves:"
103117

104118
[node name="ClipContainer" type="VBoxContainer" parent="."]
105119
anchor_top = 1.0
106120
anchor_bottom = 1.0
107-
margin_left = 20.0
108-
margin_top = -72.0
109-
margin_right = 300.0
110-
margin_bottom = -20.0
121+
margin_top = -52.0
122+
margin_right = 280.0
111123
grow_vertical = 0
124+
__meta__ = {
125+
"_edit_use_anchors_": false
126+
}
112127

113128
[node name="MinClipSpinBox" type="SpinBox" parent="ClipContainer"]
114129
margin_right = 280.0
@@ -129,7 +144,8 @@ step = 0.01
129144
value = 1.0
130145
prefix = "Max:"
131146

132-
[connection signal="pressed" from="DocumentationButton" to="." method="_on_DocumentationButton_pressed"]
147+
[connection signal="pressed" from="ButtonsContainer/DocumentationButton" to="." method="_on_DocumentationButton_pressed"]
148+
[connection signal="pressed" from="ButtonsContainer/RandomSeedButton" to="." method="_on_RandomSeedButton_pressed"]
133149
[connection signal="value_changed" from="ParameterContainer/SeedSpinBox" to="." method="_on_SeedSpinBox_value_changed"]
134150
[connection signal="value_changed" from="ParameterContainer/LacunaritySpinBox" to="." method="_on_LacunaritySpinBox_value_changed"]
135151
[connection signal="value_changed" from="ParameterContainer/PeriodSpinBox" to="." method="_on_PeriodSpinBox_value_changed"]

0 commit comments

Comments
 (0)