Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PerlinNoise Class Reference

Generate 3D perlin noise and multi-layered noise. More...

#include <PerlinNoise.hpp>

Public Member Functions

 PerlinNoise ()
 
void generate (Image &image, uint channel, float scale, float z, const glm::vec3 &offset=glm::vec3(0.0f))
 
void generatePeriodic (Image &image, uint channel, float scale, float z, const glm::vec3 &offset=glm::vec3(0.0f))
 
void generateLayers (Image &image, uint channel, int octaves, float gain, float lacunarity, float scale, const glm::vec3 &offset=glm::vec3(0.0f))
 
void reseed ()
 

Private Member Functions

float dotGrad (const glm::ivec3 &ip, const glm::vec3 &dp)
 
float perlin (const glm::vec3 &p, const glm::ivec3 &w=glm::ivec3(kHashTableSize-1))
 

Private Attributes

std::array< int, 2 *kHashTableSize_hashes
 Permutation table.
 
Image _directions
 random unit sphere directions.
 

Static Private Attributes

static const int kHashTableSize = 256
 Number of hashes used for the generation, limit the periodicity.
 

Detailed Description

Generate 3D perlin noise and multi-layered noise.

Constructor & Destructor Documentation

◆ PerlinNoise()

PerlinNoise::PerlinNoise ( )

Constructor. Initialize the randomness table.

Member Function Documentation

◆ dotGrad()

float PerlinNoise::dotGrad ( const glm::ivec3 &  ip,
const glm::vec3 &  dp 
)
private

Compute the dot product between a direction vector and the gradient at a (ix, iy, iz) location on the grid.

Parameters
ipthe grid vertex location
dpthe direction vector
Returns
the dot product

◆ generate()

void PerlinNoise::generate ( Image image,
uint  channel,
float  scale,
float  z,
const glm::vec3 &  offset = glm::vec3(0.0f) 
)

Fill a component of an image with Perlin noise in [-1,1].

Parameters
imageimage to fill with preset dimensions
channelthe channel of the image to fill
scalethe frequency, in pixels
zthe depth (in pixels) at which the 3D Perlin noise should be sampled
offsetthe origin in sampled noise space

◆ generateLayers()

void PerlinNoise::generateLayers ( Image image,
uint  channel,
int  octaves,
float  gain,
float  lacunarity,
float  scale,
const glm::vec3 &  offset = glm::vec3(0.0f) 
)

Fill a component of an image with multi-layered Perlin noise (FBM).

Parameters
imageimage to fill with preset dimensions
channelthe channel of the image to fill
octavesnumber of layers
gainthe amplitude ratio between a layer and the previous one
lacunaritythe frequency ratio between a layer and the previous one
scalethe base frequency, in pixels
offsetthe origin in sampled noise space

◆ generatePeriodic()

void PerlinNoise::generatePeriodic ( Image image,
uint  channel,
float  scale,
float  z,
const glm::vec3 &  offset = glm::vec3(0.0f) 
)

Fill a component of an image with tiling Perlin noise in [-1,1].

Parameters
imageimage to fill with preset dimensions
channelthe channel of the image to fill
scalethe frequency, in pixels
zthe depth (in pixels) at which the 3D Perlin noise should be sampled
offsetthe origin in sampled noise space
Note
The scale might internally be adjusted to ensure periodicity.

◆ perlin()

float PerlinNoise::perlin ( const glm::vec3 &  p,
const glm::ivec3 &  w = glm::ivec3(kHashTableSize-1) 
)
private

Evaluate Perlin noise for a given location in noise space.

Parameters
plocation
wthe tiling period to apply on each axis
Returns
the noise value in [-1, 1]

◆ reseed()

void PerlinNoise::reseed ( )

Regenerate the randomness table with new values.


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