Auburn / FastNoiseLite

Fast Portable Noise Library - C# C++ C Java HLSL GLSL JavaScript Rust Go

Home Page:http://auburn.github.io/FastNoiseLite/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow getting of multiple pixels in one call

jez9999 opened this issue · comments

commented

Right now, my C# code to get a 2000x2000 pixel image of noise looks like this:

var noiseWidth = 2000;
var noiseHeight = 2000;
var noise = new FastNoiseLite(rand.Next());
noise.SetNoiseType(FastNoiseLite.NoiseType.Perlin);
noise.SetFractalType(FastNoiseLite.FractalType.FBm);
noise.SetFrequency(0.001f);
float[,] noiseData = new float[noiseWidth, noiseHeight];
for (var y = 0; y < noiseHeight; y++) {
	for (var x = 0; x < noiseWidth; x++) {
		noiseData[x, y] = (noise.GetNoise(x, y) + 1) / 2f;
		// ^ bounded between -1 and 1; convert to being between 0 and 1
	}
}

GetNoise has to be called once per pixel, meaning it gets called 4 million times. This is unsurprisingly pretty slow, taking a few seconds on my laptop.

Is there no more optimized way to get a field of random data? Calling GetNoise once per pixel seems amazingly inefficient.

There isn't really a faster was to do this without using SIMD code. FastNoise2 makes use of SIMD to generate multiple noise points in parallel. There is a C# wrapper for FastNoise2