ZNoise is a fast and easy-to-use open-source C++ noise library.
This library is a very useful framework for people who want to generate procedural images, heightmaps and textures.
Author : Rémi Bèges (twitter)
Noise algorithms are density functions. For any given point in space, they will return a density value. This value is not random, noise algorithms are always deterministic. In other words, calling the function multiple times for the same point will always return the same value. However, computing the noise for different coordinates will yield different densities.
Perlin perlin;
for(int x = 0 ; x < image.width() ; x++)
for(int y = 0 ; y < image.height() ; y++)
{
// returned noise value is between -1 and 1
// Set noise scale with the last parameter
float value = perlin.Get({x , y},0.01f);
// Do whatever you want with it
// ex : generate a pixel intensity, use in a colormap ...
// ...
}
The following table details the implemented noises to date :
Noise | 2-D | 3-D (2D slice) | 4-D (2D slice) |
---|---|---|---|
Perlin | |||
Simplex | |||
Worley F1 | _ | _ | |
Worley F2 | _ | _ | _ |
Worley F3 | _ | _ | _ |
Worley F4 | _ | _ | _ |
Square | _ | _ | _ |
// Use Perlin as mixer source
Perlin perlin;
// Mixer
FBM fbm(perlin);
for(int x = 0 ; x < image.width() ; x++)
for(int y = 0 ; y < image.height() ; y++)
{
float value = fbm.Get({x , y},0.01f);
// ...
}
Multiple noise layers can be assembled automatically using Mixers. Three parameters are available to tune the noise output :
- Lacunarity
- Octave amount
- Hurst coefficient
The amount of octaves is simply the total number of noise layers blended together. Lacunarity controls the scale ratio between two successive layers. Hurst coefficient controls relates to the weight of each layer in the final blended image.
FBM | lacunarity = 2.5f | lacunarity = 3.5f | lacunarity = 4.5f |
---|---|---|---|
hurst = 0.2f | |||
hurst = 0.5f | |||
hurst = 0.8f |
HMF | lacunarity = 2.5f | lacunarity = 3.5f | lacunarity = 4.5f |
---|---|---|---|
hurst = 0.2f | |||
hurst = 0.5f | |||
hurst = 0.8f |
Znoise uses the Gradle build system. As a user, you don't need to install gradle. All you need is a gcc C++11 compiler (MinGW or TDM-GCC for instance).
On Windows, you also need to add the /bin subfolder (where you can find gcc.exe) to the PATH.
Then, run the following command in the root /Znoise folder:
gradlew build
gradlew installDebugMainExecutable
Run the examples
\build\install\mainExecutable\debug\main.bat
This will generate all the images in this readme. Images will be found in \build\install\examplesExecutable\debug\
ZNoise has at some point been developed for the https://github.com/DigitalPulseSoftware/NazaraEngine C++11 game engine.