Repository navigation
Expand file tree
/
Copy pathOpenSimplex2F.h
More file actions
191 lines (160 loc) · 7.42 KB
/
Copy pathOpenSimplex2F.h
File metadata and controls
191 lines (160 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Copyright (C) 2019-2020 KdotJPG (original work, previous license:
* CC0 1.0 Universal, public domain dedication).
*
* Copyright (C) 2026 QuasarApp Group DOO
* Licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0),
* see the accompanying LICENSE file.
*/
#ifndef OpenSimplex2F_h__
#define OpenSimplex2F_h__
/**
* 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.
*
* Ported from Java to C by Stephen M. Cameron
*
*/
#if ((__GNUC_STDC_INLINE__) || (__STDC_VERSION__ >= 199901L))
#include <stdint.h>
#define INLINE inline
#elif (defined (_MSC_VER) || defined (__GNUC_GNU_INLINE__))
#include <stdint.h>
#define INLINE __inline
#else
/* ANSI C doesn't have inline or stdint.h. */
#define INLINE
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct Grad5;
struct LatticePoint5D;
struct OpenSimplex2F_context;
/* Allocate and initialize OpenSimplex2F context */
int OpenSimplex2F(int64_t seed, struct OpenSimplex2F_context **ctx);
/* Free OpenSimplex2F context */
void OpenSimplex2F_free(struct OpenSimplex2F_context * ctx);
/* Free singleton lattice point data */
void OpenSimplex2F_shutdown(void);
/**
* 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]).
*/
double OpenSimplex2F_noise1(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.
* Returns values in the same range as 2D/3D/4D noise (~[-1, 1]).
*/
double OpenSimplex2F_noise1_fast(struct OpenSimplex2F_context *ctx, double x);
/**
* 2D Simplex noise, standard lattice orientation.
*/
double OpenSimplex2F_noise2(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.
*/
double OpenSimplex2F_noise2_XBeforeY(struct OpenSimplex2F_context *ctx, double x, double y);
/**
* 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.
*/
double OpenSimplex2F_noise3_Classic(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).
*/
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, 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.
*/
double OpenSimplex2F_noise3_XZBeforeY(struct OpenSimplex2F_context *ctx, double x, double y, double z);
/**
* 4D OpenSimplex2F noise, classic lattice orientation.
*/
double OpenSimplex2F_noise4_Classic(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.
*/
double OpenSimplex2F_noise4_XYBeforeZW(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.
*/
double OpenSimplex2F_noise4_XZBeforeYW(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)
*/
double OpenSimplex2F_noise4_XYZBeforeW(struct OpenSimplex2F_context *ctx, double x, double y, double z, double w);
/**
* 5D OpenSimplex2F noise, classic lattice orientation.
*/
double OpenSimplex2F_noise5(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.
*/
double OpenSimplex2F_noise5_XYBeforeZW(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.
*/
double OpenSimplex2F_noise5_XZBeforeYW(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)
*/
double OpenSimplex2F_noise5_XYZBeforeWV(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.
*/
double OpenSimplex2F_noise5_XYBeforeZV(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_XZBeforeYV(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_YZBeforeXW(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_YWBeforeXZV(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.
*/
double OpenSimplex2F_noise5_ZWBeforeXYV(struct OpenSimplex2F_context *ctx, double x, double y, double z, double w, double v);
#ifdef __cplusplus
}
#endif
#endif