Adding OpenSimplexNoise Viewer demo

This commit is contained in:
Devin Pentecost
2019-05-04 23:50:24 -07:00
parent ceefc33fe4
commit 27727fdde5
7 changed files with 307 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
extends Control
var noise = OpenSimplexNoise.new()
var noise_size = 500
var min_noise = -1
var max_noise = 1
# Called when the node enters the scene tree for the first time.
func _ready():
#Set up noise with basic info
$ParameterContainer/SeedSpinBox.value = noise.seed
$ParameterContainer/LacunaritySpinBox.value = noise.lacunarity
$ParameterContainer/OctavesSpinBox.value = noise.octaves
$ParameterContainer/PeriodSpinBox.value = noise.period
$ParameterContainer/PersistenceSpinBox.value = noise.persistence
#Render the noise
_refresh_noise_images()
func _refresh_noise_images():
#Get a new image
var image = noise.get_seamless_image(500)
var image_texture = ImageTexture.new()
#Adjust min/max for shader
var _min = ((min_noise + 1)/2)
var _max = ((max_noise + 1)/2)
var _material = $SeamlessNoiseTexture.material
_material.set_shader_param("min_value", _min)
_material.set_shader_param("max_value", _max)
#Draw it
image_texture.create_from_image(image)
$SeamlessNoiseTexture.texture = image_texture
func _on_DocumentationButton_pressed():
OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_opensimplexnoise.html")
func _on_SeedSpinBox_value_changed(value):
#Update the noise seed
noise.seed = value
_refresh_noise_images()
func _on_LacunaritySpinBox_value_changed(value):
#Update noise
noise.lacunarity = value
_refresh_noise_images()
func _on_OctavesSpinBox_value_changed(value):
#Update noise
noise.octaves = value
_refresh_noise_images()
func _on_PeriodSpinBox_value_changed(value):
#Update noise
noise.period = value
_refresh_noise_images()
func _on_PersistenceSpinBox_value_changed(value):
#Update noise
noise.persistence = value
_refresh_noise_images()
func _on_MinClipSpinBox_value_changed(value):
#Just refresh
min_noise = value
_refresh_noise_images()
func _on_MaxClipSpinBox_value_changed(value):
#Just refresh
max_noise = value
_refresh_noise_images()

View File

@@ -0,0 +1,21 @@
shader_type canvas_item;
uniform float min_value = -1;
uniform float max_value = 1;
void fragment() {
//Get the color
vec4 color = texture(TEXTURE, UV);
//Compare the value
float gray = color.x;
if (gray < min_value){
color = vec4(0, 0, 0, 1);
}else if (gray > max_value) {
color = vec4(1, 1, 1, 1);
}
//Write back the color
COLOR = color;
}

View File

@@ -0,0 +1,8 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
[ext_resource path="res://OpenSimplexNoise_Viewer.shader" type="Shader" id=1]
[resource]
shader = ExtResource( 1 )
shader_param/min_value = -1.0
shader_param/max_value = 1.0

View File

@@ -0,0 +1,125 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://OpenSimplexNoise_Viewer.gd" type="Script" id=1]
[ext_resource path="res://OpenSimplexNoise_Viewer.tres" type="Material" id=2]
[node name="OpenSimplexNoise Viewer" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.42108
margin_top = -5.26315
margin_right = 8.42114
margin_bottom = -5.26318
script = ExtResource( 1 )
[node name="DocumentationButton" type="Button" parent="."]
anchor_left = 1.0
anchor_right = 1.0
margin_top = 20.0
margin_right = -20.0
grow_horizontal = 0
text = "API Documentation"
[node name="SeamlessNoiseTexture" type="TextureRect" parent="."]
material = ExtResource( 2 )
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = 30.0
margin_top = -20.0
margin_right = 70.0
margin_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="ParameterContainer" type="VBoxContainer" parent="."]
editor/display_folded = true
margin_left = 20.0
margin_top = 20.0
margin_right = 300.0
margin_bottom = 40.0
[node name="SeedSpinBox" type="SpinBox" parent="ParameterContainer"]
margin_right = 280.0
margin_bottom = 24.0
min_value = -1.53049e+009
max_value = 1.53049e+009
rounded = true
allow_greater = true
allow_lesser = true
prefix = "Seed:"
[node name="LacunaritySpinBox" type="SpinBox" parent="ParameterContainer"]
margin_top = 28.0
margin_right = 280.0
margin_bottom = 52.0
max_value = 1e+008
step = 0.01
allow_greater = true
prefix = "Lacunarity:"
[node name="PeriodSpinBox" type="SpinBox" parent="ParameterContainer"]
margin_top = 56.0
margin_right = 280.0
margin_bottom = 80.0
min_value = -1e+008
max_value = 1e+008
step = 0.01
allow_greater = true
prefix = "Period:"
[node name="PersistenceSpinBox" type="SpinBox" parent="ParameterContainer"]
margin_top = 84.0
margin_right = 280.0
margin_bottom = 108.0
max_value = 1e+008
step = 0.01
allow_greater = true
prefix = "Persistance:"
[node name="OctavesSpinBox" type="SpinBox" parent="ParameterContainer"]
margin_top = 112.0
margin_right = 280.0
margin_bottom = 136.0
min_value = 1.0
max_value = 10.0
value = 1.0
allow_greater = true
prefix = "Octaves:"
[node name="ClipContainer" type="VBoxContainer" parent="."]
anchor_top = 1.0
anchor_bottom = 1.0
margin_left = 20.0
margin_top = -72.0
margin_right = 300.0
margin_bottom = -20.0
grow_vertical = 0
[node name="MinClipSpinBox" type="SpinBox" parent="ClipContainer"]
margin_right = 280.0
margin_bottom = 24.0
min_value = -1.0
max_value = 1.0
step = 0.01
value = -1.0
prefix = "Min:"
[node name="MaxClipSpinBox" type="SpinBox" parent="ClipContainer"]
margin_top = 28.0
margin_right = 280.0
margin_bottom = 52.0
min_value = -1.0
max_value = 1.0
step = 0.01
value = 1.0
prefix = "Max:"
[connection signal="pressed" from="DocumentationButton" to="." method="_on_DocumentationButton_pressed"]
[connection signal="value_changed" from="ParameterContainer/SeedSpinBox" to="." method="_on_SeedSpinBox_value_changed"]
[connection signal="value_changed" from="ParameterContainer/LacunaritySpinBox" to="." method="_on_LacunaritySpinBox_value_changed"]
[connection signal="value_changed" from="ParameterContainer/PeriodSpinBox" to="." method="_on_PeriodSpinBox_value_changed"]
[connection signal="value_changed" from="ParameterContainer/PersistenceSpinBox" to="." method="_on_PersistenceSpinBox_value_changed"]
[connection signal="value_changed" from="ParameterContainer/OctavesSpinBox" to="." method="_on_OctavesSpinBox_value_changed"]
[connection signal="value_changed" from="ClipContainer/MinClipSpinBox" to="." method="_on_MinClipSpinBox_value_changed"]
[connection signal="value_changed" from="ClipContainer/MaxClipSpinBox" to="." method="_on_MaxClipSpinBox_value_changed"]

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@@ -0,0 +1,27 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="OpenSimplexNoise Viewer"
run/main_scene="res://OpenSimplexNoise_Viewer.tscn"
config/icon="res://icon.png"
[rendering]
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true
vram_compression/import_etc2=false
environment/default_environment="res://default_env.tres"