Updated open-simplex to have const noise functions
"open-simplex-noise-in-c" now updated to master and "opensimplex" module refactored accordingly
(cherry picked from commit 7e2b88a7eb
)
This commit is contained in:
parent
796ab24540
commit
d5ea412848
|
@ -64,7 +64,7 @@ void OpenSimplexNoise::set_seed(int p_seed) {
|
|||
emit_changed();
|
||||
}
|
||||
|
||||
int OpenSimplexNoise::get_seed() {
|
||||
int OpenSimplexNoise::get_seed() const {
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ void OpenSimplexNoise::set_lacunarity(float p_lacunarity) {
|
|||
emit_changed();
|
||||
}
|
||||
|
||||
Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) {
|
||||
Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) const {
|
||||
|
||||
PoolVector<uint8_t> data;
|
||||
data.resize(p_width * p_height * 4);
|
||||
|
@ -119,7 +119,7 @@ Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) {
|
|||
return image;
|
||||
}
|
||||
|
||||
Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) {
|
||||
Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) const {
|
||||
|
||||
PoolVector<uint8_t> data;
|
||||
data.resize(p_size * p_size * 4);
|
||||
|
@ -191,12 +191,12 @@ void OpenSimplexNoise::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "lacunarity", PROPERTY_HINT_RANGE, "0.1,4.0,0.01"), "set_lacunarity", "get_lacunarity");
|
||||
}
|
||||
|
||||
float OpenSimplexNoise::get_noise_1d(float x) {
|
||||
float OpenSimplexNoise::get_noise_1d(float x) const {
|
||||
|
||||
return get_noise_2d(x, 1.0);
|
||||
}
|
||||
|
||||
float OpenSimplexNoise::get_noise_2d(float x, float y) {
|
||||
float OpenSimplexNoise::get_noise_2d(float x, float y) const {
|
||||
|
||||
x /= period;
|
||||
y /= period;
|
||||
|
@ -217,7 +217,7 @@ float OpenSimplexNoise::get_noise_2d(float x, float y) {
|
|||
return sum / max;
|
||||
}
|
||||
|
||||
float OpenSimplexNoise::get_noise_3d(float x, float y, float z) {
|
||||
float OpenSimplexNoise::get_noise_3d(float x, float y, float z) const {
|
||||
|
||||
x /= period;
|
||||
y /= period;
|
||||
|
@ -240,7 +240,7 @@ float OpenSimplexNoise::get_noise_3d(float x, float y, float z) {
|
|||
return sum / max;
|
||||
}
|
||||
|
||||
float OpenSimplexNoise::get_noise_4d(float x, float y, float z, float w) {
|
||||
float OpenSimplexNoise::get_noise_4d(float x, float y, float z, float w) const {
|
||||
|
||||
x /= period;
|
||||
y /= period;
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
void _init_seeds();
|
||||
|
||||
void set_seed(int seed);
|
||||
int get_seed();
|
||||
int get_seed() const;
|
||||
|
||||
void set_octaves(int p_octaves);
|
||||
int get_octaves() const { return octaves; }
|
||||
|
@ -75,22 +75,22 @@ public:
|
|||
void set_lacunarity(float p_lacunarity);
|
||||
float get_lacunarity() const { return lacunarity; }
|
||||
|
||||
Ref<Image> get_image(int p_width, int p_height);
|
||||
Ref<Image> get_seamless_image(int p_size);
|
||||
Ref<Image> get_image(int p_width, int p_height) const;
|
||||
Ref<Image> get_seamless_image(int p_size) const;
|
||||
|
||||
float get_noise_1d(float x);
|
||||
float get_noise_2d(float x, float y);
|
||||
float get_noise_3d(float x, float y, float z);
|
||||
float get_noise_4d(float x, float y, float z, float w);
|
||||
float get_noise_1d(float x) const;
|
||||
float get_noise_2d(float x, float y) const;
|
||||
float get_noise_3d(float x, float y, float z) const;
|
||||
float get_noise_4d(float x, float y, float z, float w) const;
|
||||
|
||||
_FORCE_INLINE_ float _get_octave_noise_2d(int octave, float x, float y) { return open_simplex_noise2(&(contexts[octave]), x, y); }
|
||||
_FORCE_INLINE_ float _get_octave_noise_3d(int octave, float x, float y, float z) { return open_simplex_noise3(&(contexts[octave]), x, y, z); }
|
||||
_FORCE_INLINE_ float _get_octave_noise_4d(int octave, float x, float y, float z, float w) { return open_simplex_noise4(&(contexts[octave]), x, y, z, w); }
|
||||
_FORCE_INLINE_ float _get_octave_noise_2d(int octave, float x, float y) const { return open_simplex_noise2(&(contexts[octave]), x, y); }
|
||||
_FORCE_INLINE_ float _get_octave_noise_3d(int octave, float x, float y, float z) const { return open_simplex_noise3(&(contexts[octave]), x, y, z); }
|
||||
_FORCE_INLINE_ float _get_octave_noise_4d(int octave, float x, float y, float z, float w) const { return open_simplex_noise4(&(contexts[octave]), x, y, z, w); }
|
||||
|
||||
// Convenience
|
||||
|
||||
_FORCE_INLINE_ float get_noise_2dv(Vector2 v) { return get_noise_2d(v.x, v.y); }
|
||||
_FORCE_INLINE_ float get_noise_3dv(Vector3 v) { return get_noise_3d(v.x, v.y, v.z); }
|
||||
_FORCE_INLINE_ float get_noise_2dv(const Vector2 &v) const { return get_noise_2d(v.x, v.y); }
|
||||
_FORCE_INLINE_ float get_noise_3dv(const Vector3 &v) const { return get_noise_3d(v.x, v.y, v.z); }
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
|
|
@ -314,7 +314,7 @@ Collection of single-file libraries used in Godot components.
|
|||
* License: Apache 2.0
|
||||
- `open-simplex-noise.{c,h}`
|
||||
* Upstream: https://github.com/smcameron/open-simplex-noise-in-c
|
||||
* Version: git (0fef0dbedd76f767da7e3c894822729d0f07e54d, 2020) + custom changes
|
||||
* Version: git (826f1dd1724e6fb3ff45f58e48c0fbae864c3403, 2020) + custom changes
|
||||
* License: Unlicense
|
||||
- `pcg.{cpp,h}`
|
||||
* Upstream: http://www.pcg-random.org
|
||||
|
|
|
@ -100,27 +100,27 @@ static const signed char gradients4D[] = {
|
|||
-3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,
|
||||
};
|
||||
|
||||
static double extrapolate2(struct osn_context *ctx, int xsb, int ysb, double dx, double dy)
|
||||
static double extrapolate2(const struct osn_context *ctx, int xsb, int ysb, double dx, double dy)
|
||||
{
|
||||
int16_t *perm = ctx->perm;
|
||||
const int16_t *perm = ctx->perm;
|
||||
int index = perm[(perm[xsb & 0xFF] + ysb) & 0xFF] & 0x0E;
|
||||
return gradients2D[index] * dx
|
||||
+ gradients2D[index + 1] * dy;
|
||||
}
|
||||
|
||||
static double extrapolate3(struct osn_context *ctx, int xsb, int ysb, int zsb, double dx, double dy, double dz)
|
||||
static double extrapolate3(const struct osn_context *ctx, int xsb, int ysb, int zsb, double dx, double dy, double dz)
|
||||
{
|
||||
int16_t *perm = ctx->perm;
|
||||
int16_t *permGradIndex3D = ctx->permGradIndex3D;
|
||||
const int16_t *perm = ctx->perm;
|
||||
const int16_t *permGradIndex3D = ctx->permGradIndex3D;
|
||||
int index = permGradIndex3D[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF];
|
||||
return gradients3D[index] * dx
|
||||
+ gradients3D[index + 1] * dy
|
||||
+ gradients3D[index + 2] * dz;
|
||||
}
|
||||
|
||||
static double extrapolate4(struct osn_context *ctx, int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw)
|
||||
static double extrapolate4(const struct osn_context *ctx, int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw)
|
||||
{
|
||||
int16_t *perm = ctx->perm;
|
||||
const int16_t *perm = ctx->perm;
|
||||
int index = perm[(perm[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF] + wsb) & 0xFF] & 0xFC;
|
||||
return gradients4D[index] * dx
|
||||
+ gradients4D[index + 1] * dy
|
||||
|
@ -227,7 +227,7 @@ void open_simplex_noise_free(struct osn_context *ctx)
|
|||
// -- GODOT end --
|
||||
|
||||
/* 2D OpenSimplex (Simplectic) Noise. */
|
||||
double open_simplex_noise2(struct osn_context *ctx, double x, double y)
|
||||
double open_simplex_noise2(const struct osn_context *ctx, double x, double y)
|
||||
{
|
||||
|
||||
/* Place input coordinates onto grid. */
|
||||
|
@ -355,7 +355,7 @@ double open_simplex_noise2(struct osn_context *ctx, double x, double y)
|
|||
/*
|
||||
* 3D OpenSimplex (Simplectic) Noise
|
||||
*/
|
||||
double open_simplex_noise3(struct osn_context *ctx, double x, double y, double z)
|
||||
double open_simplex_noise3(const struct osn_context *ctx, double x, double y, double z)
|
||||
{
|
||||
|
||||
/* Place input coordinates on simplectic honeycomb. */
|
||||
|
@ -928,7 +928,7 @@ double open_simplex_noise3(struct osn_context *ctx, double x, double y, double z
|
|||
/*
|
||||
* 4D OpenSimplex (Simplectic) Noise.
|
||||
*/
|
||||
double open_simplex_noise4(struct osn_context *ctx, double x, double y, double z, double w)
|
||||
double open_simplex_noise4(const struct osn_context *ctx, double x, double y, double z, double w)
|
||||
{
|
||||
double uins;
|
||||
double dx1, dy1, dz1, dw1;
|
||||
|
|
|
@ -47,9 +47,9 @@ int open_simplex_noise(int64_t seed, struct osn_context *ctx);
|
|||
//int open_simplex_noise_init_perm(struct osn_context *ctx, int16_t p[], int nelements);
|
||||
// -- GODOT end --
|
||||
void open_simplex_noise_free(struct osn_context *ctx);
|
||||
double open_simplex_noise2(struct osn_context *ctx, double x, double y);
|
||||
double open_simplex_noise3(struct osn_context *ctx, double x, double y, double z);
|
||||
double open_simplex_noise4(struct osn_context *ctx, double x, double y, double z, double w);
|
||||
double open_simplex_noise2(const struct osn_context *ctx, double x, double y);
|
||||
double open_simplex_noise3(const struct osn_context *ctx, double x, double y, double z);
|
||||
double open_simplex_noise4(const struct osn_context *ctx, double x, double y, double z, double w);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue