Tiled 2D Amortized Noise
A Program to Generate Infinite Grayscale Noise Textures with Amortized Noise
 All Classes Files Functions Variables Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CFiniteAmortizedNoise2D Class Reference

The finite amortized 2D noise class. More...

#include <FiniteAmortizedNoise2D.h>

Public Member Functions

 CFiniteAmortizedNoise2D (const unsigned n)
 Constructor.
 
 ~CFiniteAmortizedNoise2D ()
 Destructor.
 
float generate (int x, int y, const int m0, const int m1, const int n, float **cell)
 Generate a cell of 2D amortized noise.
 

Private Member Functions

void initPerlinNoiseTables ()
 Initialize Perlin noise tables.
 
float getRandomUnitFloat ()
 Random float in range [-1, 1].
 
unsigned int h (const unsigned int x)
 1D hash function.
 
unsigned int h (const unsigned int x, const unsigned int y)
 2D hash function.
 
void FillUp (float *t, const float s, const int n)
 Fill amortized noise table bottom up.
 
void FillDn (float *t, const float s, const int n)
 Fill amortized noise table top down.
 
void initEdgeTables (const int x, const int y, const int n)
 Initialize the amortized noise tables.
 
void initSplineTable (const int n)
 Initialize the spline table.
 
float getNoise (const int i, const int j)
 Get one point of amortized noise.
 
void getNoise (const int n, const int i0, const int j0, float **cell)
 Get 1 octave of amortized noise into cell.
 
void addNoise (const int n, const int i0, const int j0, const float scale, float **cell)
 Add 1 octave of amortized noise into cell.
 

Private Attributes

float g2 [B][2]
 Perlin gradient table.
 
int p [B]
 Perlin permutation table.
 
float * uax
 X coordinate of u used to compute a.
 
float * vax
 X coordinate of v used to compute a.
 
float * ubx
 X coordinate of u used to compute b.
 
float * vbx
 X coordinate of v used to compute b.
 
float * uay
 Y coordinate of u used to compute a.
 
float * vay
 Y coordinate of v used to compute a.
 
float * uby
 Y coordinate of u used to compute b.
 
float * vby
 Y coordinate of v used to compute b.
 
float * spline
 Spline table.
 

Detailed Description

The 2D amortized noise class implements the 2D amortized noise algorithm using Perlin's finite hash table.

Constructor & Destructor Documentation

CFiniteAmortizedNoise2D::CFiniteAmortizedNoise2D ( const unsigned  n)

Constructor.

Parameters
nCell size.

Member Function Documentation

void CFiniteAmortizedNoise2D::addNoise ( const int  n,
const int  i0,
const int  j0,
const float  scale,
float **  cell 
)
private

Add a single octave of noise into a subcell. This differs from CInfiniteAmortizedNoise2D::getNoise in that it adds the noise to the cell instead of copying it there.

Parameters
nGranularity.
i0x offset of this subcell in cell.
j0y offset of this subcell in cell.
scaleNoise is to be rescaled by this factor.
cellNoise cell.
void CFiniteAmortizedNoise2D::FillDn ( float *  t,
const float  s,
const int  n 
)
private

Fill amortized noise table top down.

Parameters
tAmortized noise table.
sInitial value.
nGranularity.
void CFiniteAmortizedNoise2D::FillUp ( float *  t,
const float  s,
const int  n 
)
private

Fill amortized noise table bottom up.

Parameters
tAmortized noise table.
sInitial value.
nGranularity.
float CFiniteAmortizedNoise2D::generate ( int  x,
int  y,
const int  m0,
const int  m1,
const int  n,
float **  cell 
)

Generate a cell of 1/f amortized noise with persistence 0.5 and lacunarity 2.0.

Parameters
xx coordinate of top left corner of cell.
yy coordinate of top left corner of cell.
m0First octave.
m1Last octave.
nGranularity.
cellCell to put generated noise into.
Returns
Multiply noise by this to get into the range -1..1
float CFiniteAmortizedNoise2D::getNoise ( const int  i,
const int  j 
)
private

Compute a single point of a single octave of Perlin noise. This is similar to Perlin's noise2 function except that it substitutes table lookups for floating point multiplication.

Parameters
ix coordinate of point.
jy coordinate of point.
Returns
Noise value at (i, j).
void CFiniteAmortizedNoise2D::getNoise ( const int  n,
const int  i0,
const int  j0,
float **  cell 
)
private

Get a single octave of noise into a subcell. This differs from CInfiniteAmortizedNoise2D::addNoise in that it copies the noise to the cell instead of adding it in.

Parameters
nGranularity.
i0x offset of this subcell in cell.
j0y offset of this subcell in cell.
cellNoise cell.
float CFiniteAmortizedNoise2D::getRandomUnitFloat ( )
private

Get a random unit floating point number.

Returns
Random floating point number >=-1 and <=1.
unsigned int CFiniteAmortizedNoise2D::h ( const unsigned int  x)
private

A 1D hash function. Hash one dimension into a single unsigned int.

Parameters
xvalue to be hashed.
Returns
Hash of x.
unsigned int CFiniteAmortizedNoise2D::h ( const unsigned int  x,
const unsigned int  y 
)
private

A 2D hash function. Hash two dimensions into a single unsigned int.

Parameters
xX coordinate of value to be hashed.
yY coordinate of value to be hashed.
Returns
Hash of (x, y).
void CFiniteAmortizedNoise2D::initEdgeTables ( const int  x0,
const int  y0,
const int  n 
)
private

Initialize the amortized noise tables.

Parameters
x0x coordinate of top left corner of cell.
y0y coordinate of top left corner of cell.
nGranularity.
void CFiniteAmortizedNoise2D::initPerlinNoiseTables ( )
private

Initialize the Perlin noise tables. Loads p with a random permutation and g2 with a randomly chosen selection of unit gradients.

void CFiniteAmortizedNoise2D::initSplineTable ( const int  n)
private

Initialize the spline table.

Parameters
nGranularity.

The documentation for this class was generated from the following files: