noise_viewer.gd 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. extends Control
  2. ## The FastNoiseLite object.
  3. @onready var noise: FastNoiseLite = $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/FrequencySpinBox.value = noise.frequency
  12. $ParameterContainer/FractalOctavesSpinBox.value = noise.fractal_octaves
  13. $ParameterContainer/FractalGainSpinBox.value = noise.fractal_gain
  14. $ParameterContainer/FractalLacunaritySpinBox.value = noise.fractal_lacunarity
  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_parameter("min_value", _min)
  23. _material.set_shader_parameter("max_value", _max)
  24. func _on_documentation_button_pressed():
  25. OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_fastnoiselite.html")
  26. func _on_random_seed_button_pressed():
  27. $ParameterContainer/SeedSpinBox.value = floor(randf_range(-2147483648, 2147483648))
  28. func _on_seed_spin_box_value_changed(value):
  29. noise.seed = value
  30. func _on_frequency_spin_box_value_changed(value):
  31. noise.frequency = value
  32. func _on_fractal_octaves_spin_box_value_changed(value):
  33. noise.fractal_octaves = value
  34. func _on_fractal_gain_spin_box_value_changed(value):
  35. noise.fractal_gain = value
  36. func _on_fractal_lacunarity_spin_box_value_changed(value):
  37. noise.fractal_lacunarity = value
  38. func _on_min_clip_spin_box_value_changed(value):
  39. min_noise = value
  40. _refresh_shader_params()
  41. func _on_max_clip_spin_box_value_changed(value):
  42. max_noise = value
  43. _refresh_shader_params()