Skip to content

Commit 27727fd

Browse files
Adding OpenSimplexNoise Viewer demo
1 parent ceefc33 commit 27727fd

File tree

7 files changed

+307
-0
lines changed

7 files changed

+307
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
extends Control
2+
3+
var noise = OpenSimplexNoise.new()
4+
5+
var noise_size = 500
6+
var min_noise = -1
7+
var max_noise = 1
8+
9+
# Called when the node enters the scene tree for the first time.
10+
func _ready():
11+
12+
#Set up noise with basic info
13+
$ParameterContainer/SeedSpinBox.value = noise.seed
14+
$ParameterContainer/LacunaritySpinBox.value = noise.lacunarity
15+
$ParameterContainer/OctavesSpinBox.value = noise.octaves
16+
$ParameterContainer/PeriodSpinBox.value = noise.period
17+
$ParameterContainer/PersistenceSpinBox.value = noise.persistence
18+
19+
#Render the noise
20+
_refresh_noise_images()
21+
22+
23+
func _refresh_noise_images():
24+
25+
#Get a new image
26+
var image = noise.get_seamless_image(500)
27+
var image_texture = ImageTexture.new()
28+
29+
#Adjust min/max for shader
30+
var _min = ((min_noise + 1)/2)
31+
var _max = ((max_noise + 1)/2)
32+
var _material = $SeamlessNoiseTexture.material
33+
_material.set_shader_param("min_value", _min)
34+
_material.set_shader_param("max_value", _max)
35+
36+
#Draw it
37+
image_texture.create_from_image(image)
38+
$SeamlessNoiseTexture.texture = image_texture
39+
40+
41+
func _on_DocumentationButton_pressed():
42+
OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_opensimplexnoise.html")
43+
44+
45+
func _on_SeedSpinBox_value_changed(value):
46+
47+
#Update the noise seed
48+
noise.seed = value
49+
_refresh_noise_images()
50+
51+
52+
func _on_LacunaritySpinBox_value_changed(value):
53+
54+
#Update noise
55+
noise.lacunarity = value
56+
_refresh_noise_images()
57+
58+
59+
func _on_OctavesSpinBox_value_changed(value):
60+
61+
#Update noise
62+
noise.octaves = value
63+
_refresh_noise_images()
64+
65+
66+
func _on_PeriodSpinBox_value_changed(value):
67+
68+
#Update noise
69+
noise.period = value
70+
_refresh_noise_images()
71+
72+
73+
func _on_PersistenceSpinBox_value_changed(value):
74+
75+
#Update noise
76+
noise.persistence = value
77+
_refresh_noise_images()
78+
79+
80+
func _on_MinClipSpinBox_value_changed(value):
81+
82+
#Just refresh
83+
min_noise = value
84+
_refresh_noise_images()
85+
86+
87+
func _on_MaxClipSpinBox_value_changed(value):
88+
89+
#Just refresh
90+
max_noise = value
91+
_refresh_noise_images()
92+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
shader_type canvas_item;
2+
3+
uniform float min_value = -1;
4+
uniform float max_value = 1;
5+
6+
void fragment() {
7+
8+
//Get the color
9+
vec4 color = texture(TEXTURE, UV);
10+
11+
//Compare the value
12+
float gray = color.x;
13+
if (gray < min_value){
14+
color = vec4(0, 0, 0, 1);
15+
}else if (gray > max_value) {
16+
color = vec4(1, 1, 1, 1);
17+
}
18+
19+
//Write back the color
20+
COLOR = color;
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
2+
3+
[ext_resource path="res://OpenSimplexNoise_Viewer.shader" type="Shader" id=1]
4+
5+
[resource]
6+
shader = ExtResource( 1 )
7+
shader_param/min_value = -1.0
8+
shader_param/max_value = 1.0
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://OpenSimplexNoise_Viewer.gd" type="Script" id=1]
4+
[ext_resource path="res://OpenSimplexNoise_Viewer.tres" type="Material" id=2]
5+
6+
[node name="OpenSimplexNoise Viewer" type="Control"]
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
margin_left = 8.42108
10+
margin_top = -5.26315
11+
margin_right = 8.42114
12+
margin_bottom = -5.26318
13+
script = ExtResource( 1 )
14+
15+
[node name="DocumentationButton" type="Button" parent="."]
16+
anchor_left = 1.0
17+
anchor_right = 1.0
18+
margin_top = 20.0
19+
margin_right = -20.0
20+
grow_horizontal = 0
21+
text = "API Documentation"
22+
23+
[node name="SeamlessNoiseTexture" type="TextureRect" parent="."]
24+
material = ExtResource( 2 )
25+
anchor_left = 0.5
26+
anchor_top = 0.5
27+
anchor_right = 0.5
28+
anchor_bottom = 0.5
29+
margin_left = 30.0
30+
margin_top = -20.0
31+
margin_right = 70.0
32+
margin_bottom = 20.0
33+
grow_horizontal = 2
34+
grow_vertical = 2
35+
36+
[node name="ParameterContainer" type="VBoxContainer" parent="."]
37+
editor/display_folded = true
38+
margin_left = 20.0
39+
margin_top = 20.0
40+
margin_right = 300.0
41+
margin_bottom = 40.0
42+
43+
[node name="SeedSpinBox" type="SpinBox" parent="ParameterContainer"]
44+
margin_right = 280.0
45+
margin_bottom = 24.0
46+
min_value = -1.53049e+009
47+
max_value = 1.53049e+009
48+
rounded = true
49+
allow_greater = true
50+
allow_lesser = true
51+
prefix = "Seed:"
52+
53+
[node name="LacunaritySpinBox" type="SpinBox" parent="ParameterContainer"]
54+
margin_top = 28.0
55+
margin_right = 280.0
56+
margin_bottom = 52.0
57+
max_value = 1e+008
58+
step = 0.01
59+
allow_greater = true
60+
prefix = "Lacunarity:"
61+
62+
[node name="PeriodSpinBox" type="SpinBox" parent="ParameterContainer"]
63+
margin_top = 56.0
64+
margin_right = 280.0
65+
margin_bottom = 80.0
66+
min_value = -1e+008
67+
max_value = 1e+008
68+
step = 0.01
69+
allow_greater = true
70+
prefix = "Period:"
71+
72+
[node name="PersistenceSpinBox" type="SpinBox" parent="ParameterContainer"]
73+
margin_top = 84.0
74+
margin_right = 280.0
75+
margin_bottom = 108.0
76+
max_value = 1e+008
77+
step = 0.01
78+
allow_greater = true
79+
prefix = "Persistance:"
80+
81+
[node name="OctavesSpinBox" type="SpinBox" parent="ParameterContainer"]
82+
margin_top = 112.0
83+
margin_right = 280.0
84+
margin_bottom = 136.0
85+
min_value = 1.0
86+
max_value = 10.0
87+
value = 1.0
88+
allow_greater = true
89+
prefix = "Octaves:"
90+
91+
[node name="ClipContainer" type="VBoxContainer" parent="."]
92+
anchor_top = 1.0
93+
anchor_bottom = 1.0
94+
margin_left = 20.0
95+
margin_top = -72.0
96+
margin_right = 300.0
97+
margin_bottom = -20.0
98+
grow_vertical = 0
99+
100+
[node name="MinClipSpinBox" type="SpinBox" parent="ClipContainer"]
101+
margin_right = 280.0
102+
margin_bottom = 24.0
103+
min_value = -1.0
104+
max_value = 1.0
105+
step = 0.01
106+
value = -1.0
107+
prefix = "Min:"
108+
109+
[node name="MaxClipSpinBox" type="SpinBox" parent="ClipContainer"]
110+
margin_top = 28.0
111+
margin_right = 280.0
112+
margin_bottom = 52.0
113+
min_value = -1.0
114+
max_value = 1.0
115+
step = 0.01
116+
value = 1.0
117+
prefix = "Max:"
118+
[connection signal="pressed" from="DocumentationButton" to="." method="_on_DocumentationButton_pressed"]
119+
[connection signal="value_changed" from="ParameterContainer/SeedSpinBox" to="." method="_on_SeedSpinBox_value_changed"]
120+
[connection signal="value_changed" from="ParameterContainer/LacunaritySpinBox" to="." method="_on_LacunaritySpinBox_value_changed"]
121+
[connection signal="value_changed" from="ParameterContainer/PeriodSpinBox" to="." method="_on_PeriodSpinBox_value_changed"]
122+
[connection signal="value_changed" from="ParameterContainer/PersistenceSpinBox" to="." method="_on_PersistenceSpinBox_value_changed"]
123+
[connection signal="value_changed" from="ParameterContainer/OctavesSpinBox" to="." method="_on_OctavesSpinBox_value_changed"]
124+
[connection signal="value_changed" from="ClipContainer/MinClipSpinBox" to="." method="_on_MinClipSpinBox_value_changed"]
125+
[connection signal="value_changed" from="ClipContainer/MaxClipSpinBox" to="." method="_on_MaxClipSpinBox_value_changed"]

misc/opensimplexnoise/icon.png

5.31 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://icon.png"
13+
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=true
34+
svg/scale=1.0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=4
10+
11+
_global_script_classes=[ ]
12+
_global_script_class_icons={
13+
14+
}
15+
16+
[application]
17+
18+
config/name="OpenSimplexNoise Viewer"
19+
run/main_scene="res://OpenSimplexNoise_Viewer.tscn"
20+
config/icon="res://icon.png"
21+
22+
[rendering]
23+
24+
quality/driver/driver_name="GLES2"
25+
vram_compression/import_etc=true
26+
vram_compression/import_etc2=false
27+
environment/default_environment="res://default_env.tres"

0 commit comments

Comments
 (0)