11extends Control
22
3+ # The OpenSimplexNoise object
34var noise = OpenSimplexNoise .new ()
5+ var noise_texture = NoiseTexture .new ()
46
7+ # Various noise parameters
58var noise_size = 500
69var min_noise = - 1
710var max_noise = 1
811
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+
916# Called when the node enters the scene tree for the first time.
1017func _ready ():
1118
@@ -19,20 +26,29 @@ func _ready():
1926 # Render the noise
2027 _refresh_noise_images ()
2128
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+
2234
2335func _refresh_noise_images ():
2436
25- # Get a new image
26- var image = noise .get_seamless_image (500 )
27- var image_texture = ImageTexture .new ()
28-
2937 # Adjust min/max for shader
3038 var _min = ((min_noise + 1 )/ 2 )
3139 var _max = ((max_noise + 1 )/ 2 )
3240 var _material = $ SeamlessNoiseTexture .material
3341 _material .set_shader_param ("min_value" , _min )
3442 _material .set_shader_param ("max_value" , _max )
3543
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+
3652 # Draw it
3753 image_texture .create_from_image (image )
3854 $ SeamlessNoiseTexture .texture = image_texture
0 commit comments