OpenSimplex2 1.0.184.3322b0d
The most fast implementation of the OpenSimplex noise (2D, 3D and 4D) in C
Loading...
Searching...
No Matches
OpenSimplex2F.c File Reference
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include "OpenSimplex2F.h"
Include dependency graph for OpenSimplex2F.c:

Data Structures

struct  Grad1
struct  Grad2
struct  Grad3
struct  Grad4
struct  Grad5
struct  LatticePoint2D
struct  LatticePoint3D
struct  LatticePoint4D
struct  LatticePoint5D
struct  OpenSimplex2F_context

Macros

#define PSIZE   (2048)
 K.jpg's OpenSimplex 2, faster variant.
#define PMASK   (2047)
#define B0000   0x00
#define B0001   0x01
#define B0010   0x02
#define B0011   0x03
#define B0100   0x04
#define B0101   0x05
#define B0110   0x06
#define B0111   0x07
#define B1000   0x08
#define B1001   0x09
#define B1010   0x0a
#define B1011   0x0b
#define B1100   0x0c
#define B1101   0x0d
#define B1110   0x0e
#define B1111   0x0f
#define B00000   0x00
#define B00001   0x01
#define B00010   0x02
#define B00011   0x03
#define B00100   0x04
#define B00101   0x05
#define B00110   0x06
#define B00111   0x07
#define B01000   0x08
#define B01001   0x09
#define B01010   0x0a
#define B01011   0x0b
#define B01100   0x0c
#define B01101   0x0d
#define B01110   0x0e
#define B01111   0x0f
#define B10000   0x10
#define B10001   0x11
#define B10010   0x12
#define B10011   0x13
#define B10100   0x14
#define B10101   0x15
#define B10110   0x16
#define B10111   0x17
#define B11000   0x18
#define B11001   0x19
#define B11010   0x1a
#define B11011   0x1b
#define B11100   0x1c
#define B11101   0x1d
#define B11110   0x1e
#define B11111   0x1f
#define ARRAYSIZE(x)

Functions

void OpenSimplex2F_shutdown (void)
void OpenSimplex2F_free (struct OpenSimplex2F_context *ctx)
int OpenSimplex2F (int64_t seed, struct OpenSimplex2F_context **ctx)
double OpenSimplex2F_noise1 (struct OpenSimplex2F_context *ctx, double x)
 1D Simplex noise - super fast implementation.
double OpenSimplex2F_noise1_fast (struct OpenSimplex2F_context *ctx, double x)
 1D Simplex noise - ultra fast implementation with pre-computed gradients.
double OpenSimplex2F_noise2 (struct OpenSimplex2F_context *ctx, double x, double y)
 2D Simplex noise, standard lattice orientation.
double OpenSimplex2F_noise2_XBeforeY (struct OpenSimplex2F_context *ctx, double x, double y)
 2D Simplex noise, with Y pointing down the main diagonal.
double OpenSimplex2F_noise3_Classic (struct OpenSimplex2F_context *ctx, double x, double y, double z)
 3D Re-oriented 4-point BCC noise, classic orientation.
double OpenSimplex2F_noise3_XYBeforeZ (struct OpenSimplex2F_context *ctx, double x, double y, double z)
 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X, Y).
double OpenSimplex2F_noise3_XZBeforeY (struct OpenSimplex2F_context *ctx, double x, double y, double z)
 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X, Z).
double OpenSimplex2F_noise4_Classic (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w)
 4D OpenSimplex2F noise, classic lattice orientation.
double OpenSimplex2F_noise4_XYBeforeZW (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w)
 4D OpenSimplex2F noise, with XY and ZW forming orthogonal triangular-based planes.
double OpenSimplex2F_noise4_XZBeforeYW (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w)
 4D OpenSimplex2F noise, with XZ and YW forming orthogonal triangular-based planes.
double OpenSimplex2F_noise4_XYZBeforeW (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w)
 4D OpenSimplex2F noise, with XYZ oriented like noise3_Classic, and W for an extra degree of freedom.
double OpenSimplex2F_noise5 (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, classic lattice orientation.
double OpenSimplex2F_noise5_XYBeforeZW (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with XY and ZW forming orthogonal triangular-based planes.
double OpenSimplex2F_noise5_XZBeforeYW (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with XZ and YW forming orthogonal triangular-based planes.
double OpenSimplex2F_noise5_XYZBeforeWV (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with XYZ oriented like noise5, and W and V for extra dimensions.
double OpenSimplex2F_noise5_XYBeforeZV (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with XY and V forming orthogonal triangular-based planes.
double OpenSimplex2F_noise5_XZBeforeYV (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with XZ and V forming orthogonal triangular-based planes.
double OpenSimplex2F_noise5_YZBeforeXW (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with YZ and W forming orthogonal triangular-based planes.
double OpenSimplex2F_noise5_YWBeforeXZV (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with YW and XZ forming orthogonal triangular-based planes.
double OpenSimplex2F_noise5_ZWBeforeXYV (struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v)
 5D OpenSimplex2F noise, with ZW and V forming orthogonal triangular-based planes.

Macro Definition Documentation

◆ ARRAYSIZE

#define ARRAYSIZE ( x)
Value:
(sizeof(x) / sizeof((x)[0]))

◆ B0000

#define B0000   0x00

◆ B00000

#define B00000   0x00

◆ B00001

#define B00001   0x01

◆ B0001

#define B0001   0x01

◆ B00010

#define B00010   0x02

◆ B00011

#define B00011   0x03

◆ B0010

#define B0010   0x02

◆ B00100

#define B00100   0x04

◆ B00101

#define B00101   0x05

◆ B0011

#define B0011   0x03

◆ B00110

#define B00110   0x06

◆ B00111

#define B00111   0x07

◆ B0100

#define B0100   0x04

◆ B01000

#define B01000   0x08

◆ B01001

#define B01001   0x09

◆ B0101

#define B0101   0x05

◆ B01010

#define B01010   0x0a

◆ B01011

#define B01011   0x0b

◆ B0110

#define B0110   0x06

◆ B01100

#define B01100   0x0c

◆ B01101

#define B01101   0x0d

◆ B0111

#define B0111   0x07

◆ B01110

#define B01110   0x0e

◆ B01111

#define B01111   0x0f

◆ B1000

#define B1000   0x08

◆ B10000

#define B10000   0x10

◆ B10001

#define B10001   0x11

◆ B1001

#define B1001   0x09

◆ B10010

#define B10010   0x12

◆ B10011

#define B10011   0x13

◆ B1010

#define B1010   0x0a

◆ B10100

#define B10100   0x14

◆ B10101

#define B10101   0x15

◆ B1011

#define B1011   0x0b

◆ B10110

#define B10110   0x16

◆ B10111

#define B10111   0x17

◆ B1100

#define B1100   0x0c

◆ B11000

#define B11000   0x18

◆ B11001

#define B11001   0x19

◆ B1101

#define B1101   0x0d

◆ B11010

#define B11010   0x1a

◆ B11011

#define B11011   0x1b

◆ B1110

#define B1110   0x0e

◆ B11100

#define B11100   0x1c

◆ B11101

#define B11101   0x1d

◆ B1111

#define B1111   0x0f

◆ B11110

#define B11110   0x1e

◆ B11111

#define B11111   0x1f

◆ PMASK

#define PMASK   (2047)

◆ PSIZE

#define PSIZE   (2048)

K.jpg's OpenSimplex 2, faster variant.

  • 2D is standard simplex implemented using a lookup table.
  • 3D is "Re-oriented 4-point BCC noise" which constructs a congruent BCC lattice in a much different way than usual.
  • 4D constructs the lattice as a union of five copies of its reciprocal. It successively finds the closest point on each.

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

Function Documentation

◆ OpenSimplex2F()

int OpenSimplex2F ( int64_t seed,
struct OpenSimplex2F_context ** ctx )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_free()

void OpenSimplex2F_free ( struct OpenSimplex2F_context * ctx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise1()

double OpenSimplex2F_noise1 ( struct OpenSimplex2F_context * ctx,
double x )

1D Simplex noise - super fast implementation.

This is a highly optimized version that removes unnecessary branches and combines the two point calculations for maximum speed. Returns values in the same range as 2D/3D/4D noise (~[-1, 1]).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise1_fast()

double OpenSimplex2F_noise1_fast ( struct OpenSimplex2F_context * ctx,
double x )

1D Simplex noise - ultra fast implementation with pre-computed gradients.

Performance: ~10-15% faster than OpenSimplex2F_noise1 due to reduced memory indirection. This version uses ctx->permGrad1 which is pre-populated to avoid the extra memory lookup through ctx->perm[idx]. Returns values in the same range as 2D/3D/4D noise (~[-1, 1]).

Performance: ~10-15% faster than OpenSimplex2F_noise1 due to reduced memory indirection. Returns values in the same range as 2D/3D/4D noise (~[-1, 1]).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise2()

double OpenSimplex2F_noise2 ( struct OpenSimplex2F_context * ctx,
double x,
double y )

2D Simplex noise, standard lattice orientation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise2_XBeforeY()

double OpenSimplex2F_noise2_XBeforeY ( struct OpenSimplex2F_context * ctx,
double x,
double y )

2D Simplex 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise3_Classic()

double OpenSimplex2F_noise3_Classic ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z )

3D Re-oriented 4-point BCC noise, classic orientation.

Proper substitute for 3D Simplex in light of Forbidden Formulae. Use noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise3_XYBeforeZ()

double OpenSimplex2F_noise3_XYBeforeZ ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z )

3D Re-oriented 4-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).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise3_XZBeforeY()

double OpenSimplex2F_noise3_XZBeforeY ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z )

3D Re-oriented 4-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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise4_Classic()

double OpenSimplex2F_noise4_Classic ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w )

4D OpenSimplex2F noise, classic lattice orientation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise4_XYBeforeZW()

double OpenSimplex2F_noise4_XYBeforeZW ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w )

4D OpenSimplex2F 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise4_XYZBeforeW()

double OpenSimplex2F_noise4_XYZBeforeW ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w )

4D OpenSimplex2F noise, with XYZ oriented like noise3_Classic, and W for an extra degree of freedom.

W repeats eventually. Recommended for time-varied animations which texture a 3D object (W=time)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise4_XZBeforeYW()

double OpenSimplex2F_noise4_XZBeforeYW ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w )

4D OpenSimplex2F noise, with XZ and YW forming orthogonal triangular-based planes.

Recommended for 3D terrain, where X and Z (or Y and W) are horizontal.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5()

double OpenSimplex2F_noise5 ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, classic lattice orientation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_XYBeforeZV()

double OpenSimplex2F_noise5_XYBeforeZV ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with XY and V forming orthogonal triangular-based planes.

Recommended for noise(x, y, sin(time), cos(time), T) trick where V is time.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_XYBeforeZW()

double OpenSimplex2F_noise5_XYBeforeZW ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with XY and ZW forming orthogonal triangular-based planes.

Recommended for volumetric noise where X and Y (or Z and W) are horizontal. Similar to noise4_XYBeforeZW pattern.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_XYZBeforeWV()

double OpenSimplex2F_noise5_XYZBeforeWV ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with XYZ oriented like noise5, and W and V for extra dimensions.

Recommended for time-varied animations which texture a 4D object (W=time, V=frame)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_XZBeforeYV()

double OpenSimplex2F_noise5_XZBeforeYV ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with XZ and V forming orthogonal triangular-based planes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_XZBeforeYW()

double OpenSimplex2F_noise5_XZBeforeYW ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with XZ and YW forming orthogonal triangular-based planes.

Recommended for volumetric noise where X and Z (or Y and W) are horizontal.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_YWBeforeXZV()

double OpenSimplex2F_noise5_YWBeforeXZV ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with YW and XZ forming orthogonal triangular-based planes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_YZBeforeXW()

double OpenSimplex2F_noise5_YZBeforeXW ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with YZ and W forming orthogonal triangular-based planes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_noise5_ZWBeforeXYV()

double OpenSimplex2F_noise5_ZWBeforeXYV ( struct OpenSimplex2F_context * ctx,
double x,
double y,
double z,
double w,
double v )

5D OpenSimplex2F noise, with ZW and V forming orthogonal triangular-based planes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenSimplex2F_shutdown()

void OpenSimplex2F_shutdown ( void )
Here is the call graph for this function:
Here is the caller graph for this function: