OpenSimplexNoise_Viewer.gd 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. extends Control
  2. # The OpenSimplexNoise object.
  3. onready var noise: OpenSimplexNoise = $SeamlessNoiseTexture.texture.noise
  4. # Various noise parameters.
  5. var min_noise = -1
  6. var max_noise = 1
  7. # Called when the node enters the scene tree for the first time.
  8. func _ready():
  9. # Set up noise with basic info.
  10. $ParameterContainer/SeedSpinBox.value = noise.seed
  11. $ParameterContainer/LacunaritySpinBox.value = noise.lacunarity
  12. $ParameterContainer/PeriodSpinBox.value = noise.period
  13. $ParameterContainer/PersistenceSpinBox.value = noise.persistence
  14. $ParameterContainer/OctavesSpinBox.value = noise.octaves
  15. # Render the noise.
  16. _refresh_shader_params()
  17. func _refresh_shader_params():
  18. # Adjust min/max for shader.
  19. var _min = (min_noise + 1) / 2
  20. var _max = (max_noise + 1) / 2
  21. var _material = $SeamlessNoiseTexture.material
  22. _material.set_shader_param("min_value", _min)
  23. _material.set_shader_param("max_value", _max)
  24. func _on_DocumentationButton_pressed():
  25. #warning-ignore:return_value_discarded
  26. OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_opensimplexnoise.html")
  27. func _on_RandomSeedButton_pressed():
  28. $ParameterContainer/SeedSpinBox.value = floor(rand_range(-2147483648, 2147483648))
  29. func _on_SeedSpinBox_value_changed(value):
  30. noise.seed = value
  31. func _on_LacunaritySpinBox_value_changed(value):
  32. noise.lacunarity = value
  33. func _on_PeriodSpinBox_value_changed(value):
  34. noise.period = value
  35. func _on_PersistenceSpinBox_value_changed(value):
  36. noise.persistence = value
  37. func _on_OctavesSpinBox_value_changed(value):
  38. noise.octaves = value
  39. func _on_MinClipSpinBox_value_changed(value):
  40. min_noise = value
  41. _refresh_shader_params()
  42. func _on_MaxClipSpinBox_value_changed(value):
  43. max_noise = value
  44. _refresh_shader_params()