libnoise logo

A portable, open-source, coherent noise-generating library for C++


noise::module::Perlin Class Reference
[Generator Modules]

#include <perlin.h>

Inheritance diagram for noise::module::Perlin:

noise::module::Module List of all members.

Detailed Description

Noise module that outputs 3-dimensional Perlin noise.

moduleperlin.png

Perlin noise is the sum of several coherent-noise functions of ever-increasing frequencies and ever-decreasing amplitudes.

An important property of Perlin noise is that a small change in the input value will produce a small change in the output value, while a large change in the input value will produce a random change in the output value.

This noise module outputs Perlin-noise values that usually range from -1.0 to +1.0, but there are no guarantees that all output values will exist within that range.

For a better description of Perlin noise, see the links in the References and Acknowledgments section.

This noise module does not require any source modules.

Octaves

The number of octaves control the amount of detail of the Perlin noise. Adding more octaves increases the detail of the Perlin noise, but with the drawback of increasing the calculation time.

An octave is one of the coherent-noise functions in a series of coherent-noise functions that are added together to form Perlin noise.

An application may specify the frequency of the first octave by calling the SetFrequency() method.

An application may specify the number of octaves that generate Perlin noise by calling the SetOctaveCount() method.

These coherent-noise functions are called octaves because each octave has, by default, double the frequency of the previous octave. Musical tones have this property as well; a musical C tone that is one octave higher than the previous C tone has double its frequency.

Frequency

An application may specify the frequency of the first octave by calling the SetFrequency() method.

Persistence

The persistence value controls the roughness of the Perlin noise. Larger values produce rougher noise.

The persistence value determines how quickly the amplitudes diminish for successive octaves. The amplitude of the first octave is 1.0. The amplitude of each subsequent octave is equal to the product of the previous octave's amplitude and the persistence value. So a persistence value of 0.5 sets the amplitude of the first octave to 1.0; the second, 0.5; the third, 0.25; etc.

An application may specify the persistence value by calling the SetPersistence() method.

Lacunarity

The lacunarity specifies the frequency multipler between successive octaves.

The effect of modifying the lacunarity is subtle; you may need to play with the lacunarity value to determine the effects. For best results, set the lacunarity to a number between 1.5 and 3.5.

References & acknowledgments

The Noise Machine - From the master, Ken Perlin himself. This page contains a presentation that describes Perlin noise and some of its variants. He won an Oscar for creating the Perlin noise algorithm!

Perlin Noise - Hugo Elias's webpage contains a very good description of Perlin noise and describes its many applications. This page gave me the inspiration to create libnoise in the first place. Now that I know how to generate Perlin noise, I will never again use cheesy subdivision algorithms to create terrain (unless I absolutely need the speed.)

The Perlin noise math FAQ - A good page that describes Perlin noise in plain English with only a minor amount of math. During development of libnoise, I noticed that my coherent-noise function generated terrain with some "regularity" to the terrain features. This page describes a better coherent-noise function called gradient noise. This version of noise::module::Perlin uses gradient coherent noise to generate Perlin noise.


Public Member Functions

 Perlin ()
 Constructor.
double GetFrequency () const
 Returns the frequency of the first octave.
double GetLacunarity () const
 Returns the lacunarity of the Perlin noise.
noise::NoiseQuality GetNoiseQuality () const
 Returns the quality of the Perlin noise.
int GetOctaveCount () const
 Returns the number of octaves that generate the Perlin noise.
double GetPersistence () const
 Returns the persistence value of the Perlin noise.
int GetSeed () const
 Returns the seed value used by the Perlin-noise function.
virtual int GetSourceModuleCount () const
 Returns the number of source modules required by this noise module.
virtual double GetValue (double x, double y, double z) const
 Generates an output value given the coordinates of the specified input value.
void SetFrequency (double frequency)
 Sets the frequency of the first octave.
void SetLacunarity (double lacunarity)
 Sets the lacunarity of the Perlin noise.
void SetNoiseQuality (noise::NoiseQuality noiseQuality)
 Sets the quality of the Perlin noise.
void SetOctaveCount (int octaveCount)
 Sets the number of octaves that generate the Perlin noise.
void SetPersistence (double persistence)
 Sets the persistence value of the Perlin noise.
void SetSeed (int seed)
 Sets the seed value used by the Perlin-noise function.

Protected Attributes

double m_frequency
 Frequency of the first octave.
double m_lacunarity
 Frequency multiplier between successive octaves.
noise::NoiseQuality m_noiseQuality
 Quality of the Perlin noise.
int m_octaveCount
 Total number of octaves that generate the Perlin noise.
double m_persistence
 Persistence of the Perlin noise.
int m_seed
 Seed value used by the Perlin-noise function.

Constructor & Destructor Documentation

Perlin::Perlin  ) 
 

Constructor.

The default frequency is set to noise::module::DEFAULT_PERLIN_FREQUENCY.

The default lacunarity is set to noise::module::DEFAULT_PERLIN_LACUNARITY.

The default number of octaves is set to noise::module::DEFAULT_PERLIN_OCTAVE_COUNT.

The default persistence value is set to noise::module::DEFAULT_PERLIN_PERSISTENCE.

The default seed value is set to noise::module::DEFAULT_PERLIN_SEED.


Member Function Documentation

double noise::module::Perlin::GetFrequency  )  const [inline]
 

Returns the frequency of the first octave.

Returns:
The frequency of the first octave.

double noise::module::Perlin::GetLacunarity  )  const [inline]
 

Returns the lacunarity of the Perlin noise.

Returns:
The lacunarity of the Perlin noise.
The lacunarity is the frequency multiplier between successive octaves.

noise::NoiseQuality noise::module::Perlin::GetNoiseQuality  )  const [inline]
 

Returns the quality of the Perlin noise.

Returns:
The quality of the Perlin noise.
See noise::NoiseQuality for definitions of the various coherent-noise qualities.

int noise::module::Perlin::GetOctaveCount  )  const [inline]
 

Returns the number of octaves that generate the Perlin noise.

Returns:
The number of octaves that generate the Perlin noise.
The number of octaves controls the amount of detail in the Perlin noise.

double noise::module::Perlin::GetPersistence  )  const [inline]
 

Returns the persistence value of the Perlin noise.

Returns:
The persistence value of the Perlin noise.
The persistence value controls the roughness of the Perlin noise.

int noise::module::Perlin::GetSeed  )  const [inline]
 

Returns the seed value used by the Perlin-noise function.

Returns:
The seed value.

virtual int noise::module::Perlin::GetSourceModuleCount  )  const [inline, virtual]
 

Returns the number of source modules required by this noise module.

Returns:
The number of source modules required by this noise module.

Implements noise::module::Module.

double Perlin::GetValue double  x,
double  y,
double  z
const [virtual]
 

Generates an output value given the coordinates of the specified input value.

Parameters:
x The x coordinate of the input value.
y The y coordinate of the input value.
z The z coordinate of the input value.
Returns:
The output value.
Precondition:
All source modules required by this noise module have been passed to the SetSourceModule() method.
Before an application can call this method, it must first connect all required source modules via the SetSourceModule() method. If these source modules are not connected to this noise module, this method raises a debug assertion.

To determine the number of source modules required by this noise module, call the GetSourceModuleCount() method.

Implements noise::module::Module.

void noise::module::Perlin::SetFrequency double  frequency  )  [inline]
 

Sets the frequency of the first octave.

Parameters:
frequency The frequency of the first octave.

void noise::module::Perlin::SetLacunarity double  lacunarity  )  [inline]
 

Sets the lacunarity of the Perlin noise.

Parameters:
lacunarity The lacunarity of the Perlin noise.
The lacunarity is the frequency multiplier between successive octaves.

For best results, set the lacunarity to a number between 1.5 and 3.5.

void noise::module::Perlin::SetNoiseQuality noise::NoiseQuality  noiseQuality  )  [inline]
 

Sets the quality of the Perlin noise.

Parameters:
noiseQuality The quality of the Perlin noise.
See noise::NoiseQuality for definitions of the various coherent-noise qualities.

void noise::module::Perlin::SetOctaveCount int  octaveCount  )  [inline]
 

Sets the number of octaves that generate the Perlin noise.

Parameters:
octaveCount The number of octaves that generate the Perlin noise.
Precondition:
The number of octaves ranges from 1 to noise::module::PERLIN_MAX_OCTAVE.
Exceptions:
noise::ExceptionInvalidParam An invalid parameter was specified; see the preconditions for more information.
The number of octaves controls the amount of detail in the Perlin noise.

The larger the number of octaves, the more time required to calculate the Perlin-noise value.

void noise::module::Perlin::SetPersistence double  persistence  )  [inline]
 

Sets the persistence value of the Perlin noise.

Parameters:
persistence The persistence value of the Perlin noise.
The persistence value controls the roughness of the Perlin noise.

For best results, set the persistence to a number between 0.0 and 1.0.

void noise::module::Perlin::SetSeed int  seed  )  [inline]
 

Sets the seed value used by the Perlin-noise function.

Parameters:
seed The seed value.

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