Skip to content

Commit b9bca13

Browse files
authored
Merge pull request #326 from DevinPentecost/opensimplexnoise
Adding OpenSimplexNoise Viewer demo
2 parents ceefc33 + 19c4d73 commit b9bca13

File tree

8 files changed

+322
-0
lines changed

8 files changed

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

0 commit comments

Comments
 (0)