Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
OpenSimplex2S Class Reference

#include <OpenSimplex2S.hpp>

+ Collaboration diagram for OpenSimplex2S:

Classes

struct  Grad2
 
struct  Grad3
 
struct  Grad4
 
struct  Initializer
 
struct  LatticePoint2D
 
struct  LatticePoint3D
 
struct  LatticePoint4D
 

Public Member Functions

 OpenSimplex2S (long seed=0)
 
double noise2 (double x, double y)
 
double noise2_XBeforeY (double x, double y)
 
double noise3_Classic (double x, double y, double z)
 
double noise3_XYBeforeZ (double x, double y, double z)
 
double noise3_XZBeforeY (double x, double y, double z)
 
double noise4_Classic (double x, double y, double z, double w)
 
double noise4_XYBeforeZW (double x, double y, double z, double w)
 
double noise4_XZBeforeYW (double x, double y, double z, double w)
 
double noise4_XYZBeforeW (double x, double y, double z, double w)
 

Private Member Functions

double noise2_Base (double xs, double ys)
 
double noise3_BCC (double xr, double yr, double zr)
 
double noise4_Base (double xs, double ys, double zs, double ws)
 

Static Private Member Functions

static int fastFloor (double x)
 
static void initLatticePoints ()
 
static void initGradients ()
 

Private Attributes

short perm [PSIZE]
 
Grad2 permGrad2 [PSIZE]
 
Grad3 permGrad3 [PSIZE]
 
Grad4 permGrad4 [PSIZE]
 

Static Private Attributes

static const int PSIZE = 2048
 
static const int PMASK = 2047
 
static constexpr const double N2 = 0.05481866495625118
 
static constexpr const double N3 = 0.2781926117527186
 
static constexpr const double N4 = 0.11127401889945551
 
static Grad2 GRADIENTS_2D [PSIZE] {}
 
static Grad3 GRADIENTS_3D [PSIZE] {}
 
static Grad4 GRADIENTS_4D [PSIZE] {}
 
static LatticePoint2D LOOKUP_2D [8 *4] {}
 
static LatticePoint3D LOOKUP_3D [8] {}
 
static LatticePoint4D LOOKUP_4D [256][20] {}
 
static unsigned char LOOKUP_4D_SIZE [256] {}
 
static Initializer initializer {}
 

Detailed Description

Ported from https://github.com/KdotJPG/OpenSimplex2/blob/master/java/OpenSimplex2S.java Probably not best implementation of static initialization. Also changed some code to use fixed c-style arrays, to avoid using of std library.

K.jpg's OpenSimplex 2, smooth variant ("SuperSimplex")

  • 2D is standard simplex, modified to support larger kernels. Implemented using a lookup table.
  • 3D is "Re-oriented 8-point BCC noise" which constructs a congruent BCC lattice in a much different way than usual.
  • 4D uses a naïve pregenerated lookup table, and averages out to the expected performance.

Multiple versions of each function are provided. See the documentation above each, for more info.

Definition at line 30 of file OpenSimplex2S.hpp.

Constructor & Destructor Documentation

◆ OpenSimplex2S()

OpenSimplex2S::OpenSimplex2S ( long  seed = 0)
explicit

Definition at line 40 of file OpenSimplex2S.cpp.

Member Function Documentation

◆ fastFloor()

int OpenSimplex2S::fastFloor ( double  x)
staticprivate

Definition at line 367 of file OpenSimplex2S.cpp.

◆ initGradients()

void OpenSimplex2S::initGradients ( )
staticprivate

Definition at line 827 of file OpenSimplex2S.cpp.

◆ initLatticePoints()

void OpenSimplex2S::initLatticePoints ( )
staticprivate

Definition at line 411 of file OpenSimplex2S.cpp.

◆ noise2()

double OpenSimplex2S::noise2 ( double  x,
double  y 
)

2D SuperSimplex noise, standard lattice orientation.

Definition at line 63 of file OpenSimplex2S.cpp.

References noise2_Base().

◆ noise2_Base()

double OpenSimplex2S::noise2_Base ( double  xs,
double  ys 
)
private

2D SuperSimplex noise base. Lookup table implementation inspired by DigitalShadow.

Definition at line 91 of file OpenSimplex2S.cpp.

Referenced by noise2(), and noise2_XBeforeY().

◆ noise2_XBeforeY()

double OpenSimplex2S::noise2_XBeforeY ( double  x,
double  y 
)

2D SuperSimplex noise, with Y pointing down the main diagonal. Might be better for a 2D sandbox style game, where Y is vertical. Probably slightly less optimal for heightmaps or continent maps.

Definition at line 78 of file OpenSimplex2S.cpp.

References noise2_Base().

◆ noise3_BCC()

double OpenSimplex2S::noise3_BCC ( double  xr,
double  yr,
double  zr 
)
private

Generate overlapping cubic lattices for 3D Re-oriented BCC noise. Lookup table implementation inspired by DigitalShadow. It was actually faster to narrow down the points in the loop itself, than to build up the index with enough info to isolate 8 points.

Definition at line 205 of file OpenSimplex2S.cpp.

Referenced by noise3_Classic(), noise3_XYBeforeZ(), and noise3_XZBeforeY().

◆ noise3_Classic()

double OpenSimplex2S::noise3_Classic ( double  x,
double  y,
double  z 
)

3D Re-oriented 8-point BCC noise, classic orientation Proper substitute for what 3D SuperSimplex would be, in light of Forbidden Formulae. Use noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate.

Definition at line 139 of file OpenSimplex2S.cpp.

References noise3_BCC().

◆ noise3_XYBeforeZ()

double OpenSimplex2S::noise3_XYBeforeZ ( double  x,
double  y,
double  z 
)

3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Y). Recommended for 3D terrain and time-varied animations. The Z coordinate should always be the "different" coordinate in your use case. If Y is vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use noise3_XZBeforeY. If Z is vertical in world coordinates, call noise3_XYBeforeZ(x, y, Z). For a time varied animation, call noise3_XYBeforeZ(x, y, T).

Definition at line 161 of file OpenSimplex2S.cpp.

References noise3_BCC().

◆ noise3_XZBeforeY()

double OpenSimplex2S::noise3_XZBeforeY ( double  x,
double  y,
double  z 
)

3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Z). Recommended for 3D terrain and time-varied animations. The Y coordinate should always be the "different" coordinate in your use case. If Y is vertical in world coordinates, call noise3_XZBeforeY(x, Y, z). If Z is vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use noise3_XYBeforeZ. For a time varied animation, call noise3_XZBeforeY(x, T, y) or use noise3_XYBeforeZ.

Definition at line 184 of file OpenSimplex2S.cpp.

References noise3_BCC().

◆ noise4_Base()

double OpenSimplex2S::noise4_Base ( double  xs,
double  ys,
double  zs,
double  ws 
)
private

4D SuperSimplex noise base. Using ultra-simple 4x4x4x4 lookup partitioning. This isn't as elegant or SIMD/GPU/etc. portable as other approaches, but it does compete performance-wise with optimized OpenSimplex1.

Definition at line 319 of file OpenSimplex2S.cpp.

Referenced by noise4_Classic(), noise4_XYBeforeZW(), noise4_XYZBeforeW(), and noise4_XZBeforeYW().

◆ noise4_Classic()

double OpenSimplex2S::noise4_Classic ( double  x,
double  y,
double  z,
double  w 
)

4D SuperSimplex noise, classic lattice orientation.

Definition at line 250 of file OpenSimplex2S.cpp.

References noise4_Base().

◆ noise4_XYBeforeZW()

double OpenSimplex2S::noise4_XYBeforeZW ( double  x,
double  y,
double  z,
double  w 
)

4D SuperSimplex noise, with XY and ZW forming orthogonal triangular-based planes. Recommended for 3D terrain, where X and Y (or Z and W) are horizontal. Recommended for noise(x, y, sin(time), cos(time)) trick.

Definition at line 267 of file OpenSimplex2S.cpp.

References noise4_Base().

◆ noise4_XYZBeforeW()

double OpenSimplex2S::noise4_XYZBeforeW ( double  x,
double  y,
double  z,
double  w 
)

4D SuperSimplex noise, with XYZ oriented like noise3_Classic, and W for an extra degree of freedom. Recommended for time-varied animations which texture a 3D object (W=time)

Definition at line 300 of file OpenSimplex2S.cpp.

References noise4_Base().

◆ noise4_XZBeforeYW()

double OpenSimplex2S::noise4_XZBeforeYW ( double  x,
double  y,
double  z,
double  w 
)

4D SuperSimplex noise, with XZ and YW forming orthogonal triangular-based planes. Recommended for 3D terrain, where X and Z (or Y and W) are horizontal.

Definition at line 283 of file OpenSimplex2S.cpp.

References noise4_Base().

Member Data Documentation

◆ GRADIENTS_2D

OpenSimplex2S::Grad2 OpenSimplex2S::GRADIENTS_2D {}
staticprivate

K.jpg's OpenSimplex 2, smooth variant ("SuperSimplex")

  • 2D is standard simplex, modified to support larger kernels. Implemented using a lookup table.
  • 3D is "Re-oriented 8-point BCC noise" which constructs a congruent BCC lattice in a much different way than usual.
  • 4D uses a naïve pregenerated lookup table, and averages out to the expected performance.

Multiple versions of each function are provided. See the documentation above each, for more info.

Definition at line 23 of file OpenSimplex2S.hpp.

◆ GRADIENTS_3D

OpenSimplex2S::Grad3 OpenSimplex2S::GRADIENTS_3D {}
staticprivate

Definition at line 24 of file OpenSimplex2S.hpp.

◆ GRADIENTS_4D

OpenSimplex2S::Grad4 OpenSimplex2S::GRADIENTS_4D {}
staticprivate

Definition at line 25 of file OpenSimplex2S.hpp.

◆ initializer

OpenSimplex2S::Initializer OpenSimplex2S::initializer {}
staticprivate

Definition at line 38 of file OpenSimplex2S.hpp.

◆ LOOKUP_2D

OpenSimplex2S::LatticePoint2D OpenSimplex2S::LOOKUP_2D {}
staticprivate

Definition at line 27 of file OpenSimplex2S.hpp.

◆ LOOKUP_3D

OpenSimplex2S::LatticePoint3D OpenSimplex2S::LOOKUP_3D {}
staticprivate

Definition at line 28 of file OpenSimplex2S.hpp.

◆ LOOKUP_4D

OpenSimplex2S::LatticePoint4D OpenSimplex2S::LOOKUP_4D {}
staticprivate

Definition at line 29 of file OpenSimplex2S.hpp.

◆ LOOKUP_4D_SIZE

unsigned char OpenSimplex2S::LOOKUP_4D_SIZE {}
staticprivate

Definition at line 30 of file OpenSimplex2S.hpp.

◆ N2

constexpr const double OpenSimplex2S::N2 = 0.05481866495625118
staticconstexprprivate

Definition at line 96 of file OpenSimplex2S.hpp.

◆ N3

constexpr const double OpenSimplex2S::N3 = 0.2781926117527186
staticconstexprprivate

Definition at line 97 of file OpenSimplex2S.hpp.

◆ N4

constexpr const double OpenSimplex2S::N4 = 0.11127401889945551
staticconstexprprivate

Definition at line 98 of file OpenSimplex2S.hpp.

◆ perm

short OpenSimplex2S::perm[PSIZE]
private

Definition at line 109 of file OpenSimplex2S.hpp.

◆ permGrad2

Grad2 OpenSimplex2S::permGrad2[PSIZE]
private

Definition at line 110 of file OpenSimplex2S.hpp.

◆ permGrad3

Grad3 OpenSimplex2S::permGrad3[PSIZE]
private

Definition at line 111 of file OpenSimplex2S.hpp.

◆ permGrad4

Grad4 OpenSimplex2S::permGrad4[PSIZE]
private

Definition at line 112 of file OpenSimplex2S.hpp.

◆ PMASK

const int OpenSimplex2S::PMASK = 2047
staticprivate

Definition at line 94 of file OpenSimplex2S.hpp.

◆ PSIZE

const int OpenSimplex2S::PSIZE = 2048
staticprivate

Definition at line 93 of file OpenSimplex2S.hpp.


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