1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Rename perlin noise to value noise (#15858)

This commit is contained in:
Erich Schubert 2025-04-10 14:39:40 +02:00 committed by GitHub
parent 372e37faf2
commit 78293404c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 339 additions and 309 deletions

View file

@ -234,7 +234,7 @@ inline float triLinearInterpolation(
return linearInterpolation(u, v, z);
}
float noise2d_gradient(float x, float y, s32 seed, bool eased)
float noise2d_value(float x, float y, s32 seed, bool eased)
{
// Calculate the integer coordinates
int x0 = myfloor(x);
@ -252,7 +252,7 @@ float noise2d_gradient(float x, float y, s32 seed, bool eased)
}
float noise3d_gradient(float x, float y, float z, s32 seed, bool eased)
float noise3d_value(float x, float y, float z, s32 seed, bool eased)
{
// Calculate the integer coordinates
int x0 = myfloor(x);
@ -280,7 +280,7 @@ float noise3d_gradient(float x, float y, float z, s32 seed, bool eased)
}
float noise2d_perlin(float x, float y, s32 seed,
float noise2d_fractal(float x, float y, s32 seed,
int octaves, float persistence, bool eased)
{
float a = 0;
@ -288,7 +288,7 @@ float noise2d_perlin(float x, float y, s32 seed,
float g = 1.0;
for (int i = 0; i < octaves; i++)
{
a += g * noise2d_gradient(x * f, y * f, seed + i, eased);
a += g * noise2d_value(x * f, y * f, seed + i, eased);
f *= 2.0;
g *= persistence;
}
@ -305,10 +305,10 @@ float contour(float v)
}
///////////////////////// [ New noise ] ////////////////////////////
///////////////////////// [ Fractal value noise ] ////////////////////////////
float NoisePerlin2D(const NoiseParams *np, float x, float y, s32 seed)
float NoiseFractal2D(const NoiseParams *np, float x, float y, s32 seed)
{
float a = 0;
float f = 1.0;
@ -319,7 +319,7 @@ float NoisePerlin2D(const NoiseParams *np, float x, float y, s32 seed)
seed += np->seed;
for (size_t i = 0; i < np->octaves; i++) {
float noiseval = noise2d_gradient(x * f, y * f, seed + i,
float noiseval = noise2d_value(x * f, y * f, seed + i,
np->flags & (NOISE_FLAG_DEFAULTS | NOISE_FLAG_EASED));
if (np->flags & NOISE_FLAG_ABSVALUE)
@ -334,7 +334,7 @@ float NoisePerlin2D(const NoiseParams *np, float x, float y, s32 seed)
}
float NoisePerlin3D(const NoiseParams *np, float x, float y, float z, s32 seed)
float NoiseFractal3D(const NoiseParams *np, float x, float y, float z, s32 seed)
{
float a = 0;
float f = 1.0;
@ -346,7 +346,7 @@ float NoisePerlin3D(const NoiseParams *np, float x, float y, float z, s32 seed)
seed += np->seed;
for (size_t i = 0; i < np->octaves; i++) {
float noiseval = noise3d_gradient(x * f, y * f, z * f, seed + i,
float noiseval = noise3d_value(x * f, y * f, z * f, seed + i,
np->flags & NOISE_FLAG_EASED);
if (np->flags & NOISE_FLAG_ABSVALUE)
@ -375,7 +375,7 @@ Noise::Noise(const NoiseParams *np_, s32 seed, u32 sx, u32 sy, u32 sz)
Noise::~Noise()
{
delete[] gradient_buf;
delete[] value_buf;
delete[] persist_buf;
delete[] noise_buf;
delete[] result;
@ -394,15 +394,15 @@ void Noise::allocBuffers()
this->noise_buf = NULL;
resizeNoiseBuf(sz > 1);
delete[] gradient_buf;
delete[] value_buf;
delete[] persist_buf;
delete[] result;
try {
size_t bufsize = sx * sy * sz;
this->persist_buf = NULL;
this->gradient_buf = new float[bufsize];
this->result = new float[bufsize];
this->persist_buf = NULL;
this->value_buf = new float[bufsize];
this->result = new float[bufsize];
} catch (std::bad_alloc &e) {
throw InvalidNoiseParamsException();
}
@ -490,7 +490,7 @@ void Noise::resizeNoiseBuf(bool is3d)
* next octave.
*/
#define idx(x, y) ((y) * nlx + (x))
void Noise::gradientMap2D(
void Noise::valueMap2D(
float x, float y,
float step_x, float step_y,
s32 seed)
@ -527,7 +527,7 @@ void Noise::gradientMap2D(
u = orig_u;
noisex = 0;
for (i = 0; i != sx; i++) {
gradient_buf[index++] =
value_buf[index++] =
biLinearInterpolation(v00, v10, v01, v11, u, v, eased);
u += step_x;
@ -552,7 +552,7 @@ void Noise::gradientMap2D(
#define idx(x, y, z) ((z) * nly * nlx + (y) * nlx + (x))
void Noise::gradientMap3D(
void Noise::valueMap3D(
float x, float y, float z,
float step_x, float step_y, float step_z,
s32 seed)
@ -605,7 +605,7 @@ void Noise::gradientMap3D(
u = orig_u;
noisex = 0;
for (i = 0; i != sx; i++) {
gradient_buf[index++] = triLinearInterpolation(
value_buf[index++] = triLinearInterpolation(
v000, v100, v010, v110,
v001, v101, v011, v111,
u, v, w,
@ -643,7 +643,7 @@ void Noise::gradientMap3D(
#undef idx
float *Noise::perlinMap2D(float x, float y, float *persistence_map)
float *Noise::noiseMap2D(float x, float y, float *persistence_map)
{
float f = 1.0, g = 1.0;
size_t bufsize = sx * sy;
@ -661,7 +661,7 @@ float *Noise::perlinMap2D(float x, float y, float *persistence_map)
}
for (size_t oct = 0; oct < np.octaves; oct++) {
gradientMap2D(x * f, y * f,
valueMap2D(x * f, y * f,
f / np.spread.X, f / np.spread.Y,
seed + np.seed + oct);
@ -680,7 +680,7 @@ float *Noise::perlinMap2D(float x, float y, float *persistence_map)
}
float *Noise::perlinMap3D(float x, float y, float z, float *persistence_map)
float *Noise::noiseMap3D(float x, float y, float z, float *persistence_map)
{
float f = 1.0, g = 1.0;
size_t bufsize = sx * sy * sz;
@ -699,7 +699,7 @@ float *Noise::perlinMap3D(float x, float y, float z, float *persistence_map)
}
for (size_t oct = 0; oct < np.octaves; oct++) {
gradientMap3D(x * f, y * f, z * f,
valueMap3D(x * f, y * f, z * f,
f / np.spread.X, f / np.spread.Y, f / np.spread.Z,
seed + np.seed + oct);
@ -726,22 +726,22 @@ void Noise::updateResults(float g, float *gmap,
if (np.flags & NOISE_FLAG_ABSVALUE) {
if (persistence_map) {
for (size_t i = 0; i != bufsize; i++) {
result[i] += gmap[i] * std::fabs(gradient_buf[i]);
result[i] += gmap[i] * std::fabs(value_buf[i]);
gmap[i] *= persistence_map[i];
}
} else {
for (size_t i = 0; i != bufsize; i++)
result[i] += g * std::fabs(gradient_buf[i]);
result[i] += g * std::fabs(value_buf[i]);
}
} else {
if (persistence_map) {
for (size_t i = 0; i != bufsize; i++) {
result[i] += gmap[i] * gradient_buf[i];
result[i] += gmap[i] * value_buf[i];
gmap[i] *= persistence_map[i];
}
} else {
for (size_t i = 0; i != bufsize; i++)
result[i] += g * gradient_buf[i];
result[i] += g * value_buf[i];
}
}
}