Skip to content
Jordan Peck edited this page May 28, 2016 · 12 revisions

Usage

Copy FastNoise.h and FastNoise.cpp into your project

#include "FastNoise.h"

Getting Started

Using FastNoise to create a 2D heightmap

FastNoise myNoise; // Create a FastNoise object
myNoise.SetNoiseType(FastNoise::SimplexFractal); // Set the desired noise type

float heightMap[32][32]; // 2D heightmap to create terrain

for (int x = 0; x < 32; x++)
{
    for (int y = 0; y < 32; y++)
    {
        heightMap[x][y] = myNoise.GetNoise(x,y);
    }
}

Notes

  • All outputs are approximately bounded from -1.0 to 1.0, except for distance functions on cellular noise
  • All noise settings are initialised to sensible values so all noise types will function correctly without any setup

Noise Settings

General

int GetSeed()

Returns seed


void SetSeed(int seed)

Used in all noise generation


void SetFrequency(float frequency)

Used in all noise generation except White Noise


void SetInterp(Interp interp)

Used in Value and Gradient Noise

Possible interpolation methods:

  • InterpLinear
  • InterpHermite
  • InterpQuintic

void SetNoiseType(NoiseType noiseType)

Sets the type of noise returned by GetNoise()

Possible noise types:

  • Value
  • ValueFractal
  • Gradient
  • GradientFractal
  • Simplex
  • SimplexFractal
  • Cellular
  • CellularHQ
  • WhiteNoise

Fractal

void SetFractalOctaves(unsigned int octaves)

Used in all fractal noise generation


void SetFractalLacunarity(float lacunarity)

Used in all fractal noise generation


void SetFractalGain(float gain)

Used in all fractal noise generation


void SetFractalType(FractalType fractalType)

Used in all fractal noise generation

Possible fractal types:

  • FBM
  • Billow
  • RigidMulti

Cellular

void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction)

The distance function used to calculate the cell for a given point

Possible distance functions:

  • Euclidean
  • Manhattan
  • Natural

(Natural is a blend of Euclidean and Manhattan to give curved cell boundaries)


void SetCellularReturnType(CellularReturnType cellularReturnType)

What value does the function return from its calculations

Possible return types:

  • CellValue
  • NoiseLookup
  • Distance2Center
  • Distance2CenterXValue
  • Distance2CenterSq
  • Distance2CenterSqXValue
  • Distance2Edge
  • Distance2EdgeXValue
  • Distance2EdgeSq
  • Distance2EdgeSqXValue

Distance2 functions return distance from given point to the center/edge of its cell, they are always positive and unbounded

XValue means the output will be multiplied by the cell value

NoiseLookup requires another FastNoise object be set with SetCellularNoiseLookup() to function


void SetCellularNoiseLookup(FastNoise* noise)

Noise used to calculate a cell value if cellular return type is NoiseLookup

The lookup value is acquired through GetNoise() so ensure you SetNoiseType() on the noise lookup, value, gradient or simplex is recommended

Noise Generation

float GetNoise(float x, float y{, float z})

Returns the noise type as set by SetNoiseType()


float GetValue(float x, float y{, float z})

float GetValueFractal(float x, float y{, float z})

float GetGradient(float x, float y{, float z})

float GetGradientFractal(float x, float y{, float z})

float GetSimplex(float x, float y{, float z}{, float w})

float GetSimplexFractal(float x, float y{, float z})

float GetCellular(float x, float y{, float z})

float GetCellularHQ(float x, float y{, float z})

float GetWhiteNoise(float x, float y{, float z}{, float w})

float GetWhiteNoiseInt(int x, int y{, int z}{, int w})

Clone this wiki locally