Why does FastNoiseLite give me different results for get_noise_2d() and get_image()?

Godot Version

v4.1.2.stable.official [399c9dc39]


Firstly, what exactly does the “normalize” parameter do in FNL’s get_image() function? I expected it to adjust the result range from [-1.0 : 1.0] to [0.0 : 1.0] based on the documentation, but when I tested it the normalized version looked darker. I don’t understand why.

Secondly, when I used FNL’s get_noise_2d() function the result looked very dark. I assumed that it was giving me results from -1.0 to 1.0, so I “normalized” it manually. The result looked better, but when I compared it to the get_image() function results, my normalized version matched the non-normalized result from get_image().

Here is my code:

func test_get_noise_2d(normalize: bool):
	var noise = FastNoiseLite.new()
	noise.noise_type = FastNoiseLite.TYPE_PERLIN
	var img = Image.new()
	img = Image.create(256, 256, true, Image.FORMAT_RGB8)
	var noise_value
	for x in range(256):
		for y in range(256):
			if normalize:
				noise_value = (noise.get_noise_2d(x, y) + 1.0) / 2.0
				noise_value = noise.get_noise_2d(x, y)
			var col = lerp(Color.BLACK, Color.WHITE, noise_value)
			img.set_pixel(x, y, col)
	$Sprite2D.material.set_shader_parameter("texture_param", ImageTexture.create_from_image(img))
func test_get_image(normalize: bool):
	var noise = FastNoiseLite.new()
	noise.noise_type = FastNoiseLite.TYPE_PERLIN
	var img = noise.get_image(256, 256, false, false, normalize)
	$Sprite2D.material.set_shader_parameter("texture_param", ImageTexture.create_from_image(img))

@export var inspector_noise: Texture2D
func test_inspector_noise():
	$Sprite2D.material.set_shader_parameter("texture_param", inspector_noise)

And here are the results:

So what exactly is the normalize parameter doing? And how do I get the get_noise_2d() (top left) results to match the “normalized” get_Image() (bottom right) results?

I imagine that there’s different standards for value ranges that images can have. The inspector does a courtesy of converting to 0-1 range, while the original image is probably -1 1 range. Not sure tho.