Adding example NoiseTexture usage, as an example
Set the use_noise_texture flag to true to use it instead.
This commit is contained in:
parent
27727fdde5
commit
19c4d7311f
Binary file not shown.
|
@ -1,11 +1,18 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
#The OpenSimplexNoise object
|
||||||
var noise = OpenSimplexNoise.new()
|
var noise = OpenSimplexNoise.new()
|
||||||
|
var noise_texture = NoiseTexture.new()
|
||||||
|
|
||||||
|
#Various noise parameters
|
||||||
var noise_size = 500
|
var noise_size = 500
|
||||||
var min_noise = -1
|
var min_noise = -1
|
||||||
var max_noise = 1
|
var max_noise = 1
|
||||||
|
|
||||||
|
#Are we using a NoiseTexture instead?
|
||||||
|
#Noise textures automatically grab and apply the noise data to an ImageTexture, instead of manually
|
||||||
|
const use_noise_texture = false
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
|
@ -19,13 +26,14 @@ func _ready():
|
||||||
#Render the noise
|
#Render the noise
|
||||||
_refresh_noise_images()
|
_refresh_noise_images()
|
||||||
|
|
||||||
|
#Do we need to set up a noise texture?
|
||||||
|
if use_noise_texture:
|
||||||
|
noise_texture.noise = noise
|
||||||
|
$SeamlessNoiseTexture.texture = noise_texture
|
||||||
|
|
||||||
|
|
||||||
func _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
|
#Adjust min/max for shader
|
||||||
var _min = ((min_noise + 1)/2)
|
var _min = ((min_noise + 1)/2)
|
||||||
var _max = ((max_noise + 1)/2)
|
var _max = ((max_noise + 1)/2)
|
||||||
|
@ -33,6 +41,14 @@ func _refresh_noise_images():
|
||||||
_material.set_shader_param("min_value", _min)
|
_material.set_shader_param("min_value", _min)
|
||||||
_material.set_shader_param("max_value", _max)
|
_material.set_shader_param("max_value", _max)
|
||||||
|
|
||||||
|
#Are we using noise textures instead?
|
||||||
|
if use_noise_texture:
|
||||||
|
return
|
||||||
|
|
||||||
|
#Get a new image if we aren't using a NoiseTexture
|
||||||
|
var image = noise.get_seamless_image(500)
|
||||||
|
var image_texture = ImageTexture.new()
|
||||||
|
|
||||||
#Draw it
|
#Draw it
|
||||||
image_texture.create_from_image(image)
|
image_texture.create_from_image(image)
|
||||||
$SeamlessNoiseTexture.texture = image_texture
|
$SeamlessNoiseTexture.texture = image_texture
|
||||||
|
|
|
@ -24,4 +24,3 @@ config/icon="res://icon.png"
|
||||||
quality/driver/driver_name="GLES2"
|
quality/driver/driver_name="GLES2"
|
||||||
vram_compression/import_etc=true
|
vram_compression/import_etc=true
|
||||||
vram_compression/import_etc2=false
|
vram_compression/import_etc2=false
|
||||||
environment/default_environment="res://default_env.tres"
|
|
||||||
|
|
Loading…
Reference in New Issue