noise_viewer.gd 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. extends Control
  2. ## The FastNoiseLite object.
  3. @onready var noise: FastNoiseLite = $SeamlessNoiseTexture.texture.noise
  4. # Various noise parameters.
  5. var min_noise := -1.0
  6. var max_noise := 1.0
  7. func _ready() -> void:
  8. # Set up noise with basic info.
  9. $ParameterContainer/SeedSpinBox.value = noise.seed
  10. $ParameterContainer/FrequencySpinBox.value = noise.frequency
  11. $ParameterContainer/FractalOctavesSpinBox.value = noise.fractal_octaves
  12. $ParameterContainer/FractalGainSpinBox.value = noise.fractal_gain
  13. $ParameterContainer/FractalLacunaritySpinBox.value = noise.fractal_lacunarity
  14. # Render the noise.
  15. _refresh_shader_params()
  16. func _refresh_shader_params() -> void:
  17. # Adjust min/max for shader.
  18. @warning_ignore("integer_division")
  19. var _min := (min_noise + 1) / 2
  20. @warning_ignore("integer_division")
  21. var _max := (max_noise + 1) / 2
  22. var _material: ShaderMaterial = $SeamlessNoiseTexture.material
  23. _material.set_shader_parameter("min_value", _min)
  24. _material.set_shader_parameter("max_value", _max)
  25. func _on_documentation_button_pressed() -> void:
  26. OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_fastnoiselite.html")
  27. func _on_random_seed_button_pressed() -> void:
  28. $ParameterContainer/SeedSpinBox.value = floor(randf_range(-2147483648, 2147483648))
  29. func _on_seed_spin_box_value_changed(value: float) -> void:
  30. noise.seed = int(value)
  31. func _on_frequency_spin_box_value_changed(value: float) -> void:
  32. noise.frequency = value
  33. func _on_fractal_octaves_spin_box_value_changed(value: float) -> void:
  34. noise.fractal_octaves = int(value)
  35. func _on_fractal_gain_spin_box_value_changed(value: float) -> void:
  36. noise.fractal_gain = value
  37. func _on_fractal_lacunarity_spin_box_value_changed(value: float) -> void:
  38. noise.fractal_lacunarity = value
  39. func _on_min_clip_spin_box_value_changed(value: float) -> void:
  40. min_noise = value
  41. _refresh_shader_params()
  42. func _on_max_clip_spin_box_value_changed(value: float) -> void:
  43. max_noise = value
  44. _refresh_shader_params()