procedurals
Procedural generation building blocks
Loading...
Searching...
No Matches
procedurals

Procedural generation building blocks. More...

Classes

class  PoissonDisk
 
class  TinyKeepDev
 
class  WaveFunctionCollapse
 

Functions

uint64_t mix64 (uint64_t x) noexcept
 
float normaliseHash (uint64_t x) noexcept
 
float random0D (uint64_t seed=0) noexcept
 
float random1D (int x, uint64_t seed=0) noexcept
 
float random2D (int x, int y, uint64_t seed=0) noexcept
 
float random3D (int x, int y, int z, uint64_t seed=0) noexcept
 
float random4D (int x, int y, int z, int w, uint64_t seed=0) noexcept
 
uint64_t SplitSeed (uint64_t seed, uint64_t channel) noexcept
 
float noise2D (float x, float y, uint64_t seed=0) noexcept
 2D deterministic value noise in [-1, 1].
 
float fbm2D (float x, float y, int octaves=5, uint64_t seed=0, float gain=0.5f, float lacunarity=2.0f) noexcept
 Fractal Brownian Motion (fBm)
 
float warp2D (float x, float y, uint64_t seed=0, float strength=2.0f) noexcept
 
float ridge2D (float x, float y, int octaves=5, float gain=0.5f, float lacunarity=2.0f, uint64_t seed=0) noexcept
 Ridged Fractal Noise (inverted fBm)
 
float rarity2D (float x, float y, float rarity=0.01f, uint64_t seed=0)
 
float worley2D (float x, float y, uint64_t seed=0) noexcept
 
void initPerm (uint8_t *perm, uint64_t seed)
 
float grad (int hash, float x, float y)
 
float simplex2D (float xin, float yin, uint64_t seed=0)
 
float Lerp (float a, float b, float t) noexcept
 
float Clamp (float x, float minVal, float maxVal) noexcept
 
float EaseIn (float t) noexcept
 
float EaseOut (float t) noexcept
 
float EaseInOut (float t) noexcept
 
float InterpolateEaseInOut (float a, float b, float t) noexcept
 
template<int Levels = 10>
float Quantize (float v)
 Quantize a float value into discrete levels, useful for stylized effects.
 
void visualizer2D (const std::string &filename, int width, int height, float scale, const std::function< float(float, float)> &noiseFunc)
 
void visualizer2D (const std::string &filename, const std::vector< std::vector< float > > &map)
 

Variables

constexpr double PHI = 1.6180339887498949
 phi, inv_phi, golden_ratio
 
constexpr double INV_PHI = 1.0 / PHI
 
constexpr uint64_t UINT64_MAX_CONST = ~0ULL
 
constexpr double DOUBLE_MAX = static_cast<double>(UINT64_MAX_CONST)
 
constexpr uint64_t GOLDEN_64 = static_cast<uint64_t>(INV_PHI * DOUBLE_MAX)
 
constexpr uint64_t MAGIC1 = GOLDEN_64 ^ 0xAAAAAAAAAAAAAAAAULL
 Magic Multipliers.
 
constexpr uint64_t MAGIC2 = GOLDEN_64 ^ 0x5555555555555555ULL
 
constexpr uint64_t MAGIC3 = GOLDEN_64 ^ 0x3333333333333333ULL
 
constexpr uint64_t MAGIC4 = GOLDEN_64 ^ 0xCCCCCCCCCCCCCCCCULL
 

Detailed Description

Procedural generation building blocks.

Noise, Poisson disk sampling, smoothing, and a TinyKeep-style dungeon generator. Deterministic : same seed, same output.

Function Documentation

◆ Clamp()

float Clamp ( float  x,
float  minVal,
float  maxVal 
)
inlinenoexcept

◆ EaseIn()

float EaseIn ( float  t)
inlinenoexcept

◆ EaseInOut()

float EaseInOut ( float  t)
inlinenoexcept

◆ EaseOut()

float EaseOut ( float  t)
inlinenoexcept

◆ fbm2D()

float fbm2D ( float  x,
float  y,
int  octaves = 5,
uint64_t  seed = 0,
float  gain = 0.5f,
float  lacunarity = 2.0f 
)
inlinenoexcept

Fractal Brownian Motion (fBm)

Adds multiple octaves of noise to create fractal-like complexity. Each octave increases frequency and decreases amplitude.

◆ grad()

float grad ( int  hash,
float  x,
float  y 
)
inline

◆ initPerm()

void initPerm ( uint8_t *  perm,
uint64_t  seed 
)
inline

◆ InterpolateEaseInOut()

float InterpolateEaseInOut ( float  a,
float  b,
float  t 
)
inlinenoexcept

◆ Lerp()

float Lerp ( float  a,
float  b,
float  t 
)
inlinenoexcept

◆ mix64()

uint64_t mix64 ( uint64_t  x)
inlinenoexcept

◆ noise2D()

float noise2D ( float  x,
float  y,
uint64_t  seed = 0 
)
noexcept

2D deterministic value noise in [-1, 1].

Computes smooth pseudo-random noise from (x, y) and an optional seed. Values at the four surrounding grid points are hashed and smoothly interpolated using an ease-in-out curve.

Parameters
xX coordinate (can be fractional)
yY coordinate (can be fractional)
seedOptional seed for reproducibility
Returns
float Noise value in [-1, 1]

◆ normaliseHash()

float normaliseHash ( uint64_t  x)
inlinenoexcept

◆ Quantize()

template<int Levels = 10>
float Quantize ( float  v)
inline

Quantize a float value into discrete levels, useful for stylized effects.

Template Parameters
Levels
Parameters
v
Returns
float

◆ random0D()

float random0D ( uint64_t  seed = 0)
inlinenoexcept

◆ random1D()

float random1D ( int  x,
uint64_t  seed = 0 
)
inlinenoexcept

◆ random2D()

float random2D ( int  x,
int  y,
uint64_t  seed = 0 
)
inlinenoexcept

◆ random3D()

float random3D ( int  x,
int  y,
int  z,
uint64_t  seed = 0 
)
inlinenoexcept

◆ random4D()

float random4D ( int  x,
int  y,
int  z,
int  w,
uint64_t  seed = 0 
)
inlinenoexcept

◆ rarity2D()

float rarity2D ( float  x,
float  y,
float  rarity = 0.01f,
uint64_t  seed = 0 
)
inline

◆ ridge2D()

float ridge2D ( float  x,
float  y,
int  octaves = 5,
float  gain = 0.5f,
float  lacunarity = 2.0f,
uint64_t  seed = 0 
)
inlinenoexcept

Ridged Fractal Noise (inverted fBm)

Turns smooth valleys into sharp ridges and peaks. Useful for mountain heightmaps or cracked stone surfaces.

◆ simplex2D()

float simplex2D ( float  xin,
float  yin,
uint64_t  seed = 0 
)
inline

◆ SplitSeed()

uint64_t SplitSeed ( uint64_t  seed,
uint64_t  channel 
)
inlinenoexcept

◆ visualizer2D() [1/2]

void visualizer2D ( const std::string &  filename,
const std::vector< std::vector< float > > &  map 
)
inline

◆ visualizer2D() [2/2]

void visualizer2D ( const std::string &  filename,
int  width,
int  height,
float  scale,
const std::function< float(float, float)> &  noiseFunc 
)
inline

◆ warp2D()

float warp2D ( float  x,
float  y,
uint64_t  seed = 0,
float  strength = 2.0f 
)
inlinenoexcept

◆ worley2D()

float worley2D ( float  x,
float  y,
uint64_t  seed = 0 
)
inlinenoexcept

Variable Documentation

◆ DOUBLE_MAX

constexpr double DOUBLE_MAX = static_cast<double>(UINT64_MAX_CONST)
constexpr

◆ GOLDEN_64

constexpr uint64_t GOLDEN_64 = static_cast<uint64_t>(INV_PHI * DOUBLE_MAX)
constexpr

◆ INV_PHI

constexpr double INV_PHI = 1.0 / PHI
constexpr

◆ MAGIC1

constexpr uint64_t MAGIC1 = GOLDEN_64 ^ 0xAAAAAAAAAAAAAAAAULL
constexpr

Magic Multipliers.

◆ MAGIC2

constexpr uint64_t MAGIC2 = GOLDEN_64 ^ 0x5555555555555555ULL
constexpr

◆ MAGIC3

constexpr uint64_t MAGIC3 = GOLDEN_64 ^ 0x3333333333333333ULL
constexpr

◆ MAGIC4

constexpr uint64_t MAGIC4 = GOLDEN_64 ^ 0xCCCCCCCCCCCCCCCCULL
constexpr

◆ PHI

constexpr double PHI = 1.6180339887498949
constexpr

phi, inv_phi, golden_ratio

◆ UINT64_MAX_CONST

constexpr uint64_t UINT64_MAX_CONST = ~0ULL
constexpr