Skip to content

Getting started using FastNoise2

Auburn edited this page Jun 24, 2024 · 3 revisions

There are 2 ways to use FastNoise2, creating a node tree structure in code or importing a serialised node tree created using the NoiseTool.

Create node tree in code

This is creating a Simplex Fractal FBm with 5 octaves from code

auto fnSimplex = FastNoise::New<FastNoise::Simplex>();
auto fnFractal = FastNoise::New<FastNoise::FractalFBm>();

fnFractal->SetSource( fnSimplex );
fnFractal->SetOctaveCount( 5 );
...

Load node tree from NoiseTool

Here is the same Simplex Fractal FBm with 5 octaves but using serialised data from the NoiseTool

FastNoise::SmartNode<> fnGenerator = FastNoise::NewFromEncodedNodeTree( "DQAFAAAAAAAAQAgAAAAAAD8AAAAAAA==" );
...

This is the node graph for the above from the NoiseTool (right clicking a node title will give the option to Copy Encoded Node Tree)

image

Generate Noise!

After setup of a FastNoise2 node from the previous steps here is an example of using it to generate a 16x16x16 volume of noise

...
// Create an array of floats to store the noise output in
std::vector<float> noiseOutput(16 * 16 * 16);

// Generate a 16 x 16 x 16 area of noise
fnGenerator->GenUniformGrid3D(noiseOutput.data(), 0, 0, 0, 16, 16, 16, 0.2f, 1337);
int index = 0;

for (int z = 0; z < 16; z++)
{
    for (int y = 0; y < 16; y++)
    {
        for (int x = 0; x < 16; x++)
        {
            ProcessVoxelData(x, y, z, noiseOutput[index++]);			
        }			
    }
}

Make sure you call the Gen function on the root node in your node tree.

For example if you have a fractal node with a simplex source node (as in the above code) you want to call the Gen function on the fractal node. Calling it on the simplex node would result simplex noise output with no fractal.