[FastNoiseLite] Added, replaced FastNoise.
parent
3b13b36fd4
commit
e62b94beab
|
@ -147,6 +147,11 @@ include_directories(external/lua/src)
|
|||
#------------------------------------------------------------------------------
|
||||
add_subdirectory(external/sol2)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# - FastNoiseLite
|
||||
#------------------------------------------------------------------------------
|
||||
include_directories(SYSTEM external/FastNoiseLite)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Subdirectories
|
||||
#------------------------------------------------------------------------------
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,312 +0,0 @@
|
|||
// FastNoise.h
|
||||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright(c) 2017 Jordan Peck
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files(the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The developer's email is jorzixdan.me2@gzixmail.com (for great email, take
|
||||
// off every 'zix'.)
|
||||
//
|
||||
|
||||
// VERSION: 0.4.1
|
||||
|
||||
#ifndef FASTNOISE_H
|
||||
#define FASTNOISE_H
|
||||
|
||||
// Uncomment the line below to use doubles throughout FastNoise instead of floats
|
||||
// OpenMiner needs it!
|
||||
#define FN_USE_DOUBLES
|
||||
|
||||
#define FN_CELLULAR_INDEX_MAX 3
|
||||
|
||||
#ifdef FN_USE_DOUBLES
|
||||
typedef double FN_DECIMAL;
|
||||
#else
|
||||
typedef float FN_DECIMAL;
|
||||
#endif
|
||||
|
||||
class FastNoise
|
||||
{
|
||||
public:
|
||||
explicit FastNoise(int seed = 1337) { SetSeed(seed); CalculateFractalBounding(); }
|
||||
|
||||
enum NoiseType { Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, Cellular, WhiteNoise, Cubic, CubicFractal };
|
||||
enum Interp { Linear, Hermite, Quintic };
|
||||
enum FractalType { FBM, Billow, RigidMulti };
|
||||
enum CellularDistanceFunction { Euclidean, Manhattan, Natural };
|
||||
enum CellularReturnType { CellValue, NoiseLookup, Distance, Distance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div };
|
||||
|
||||
// Sets seed used for all noise types
|
||||
// Default: 1337
|
||||
void SetSeed(int seed);
|
||||
|
||||
// Returns seed used for all noise types
|
||||
int GetSeed() const { return m_seed; }
|
||||
|
||||
// Sets frequency for all noise types
|
||||
// Default: 0.01
|
||||
void SetFrequency(FN_DECIMAL frequency) { m_frequency = frequency; }
|
||||
|
||||
// Returns frequency used for all noise types
|
||||
FN_DECIMAL GetFrequency() const { return m_frequency; }
|
||||
|
||||
// Changes the interpolation method used to smooth between noise values
|
||||
// Possible interpolation methods (lowest to highest quality) :
|
||||
// - Linear
|
||||
// - Hermite
|
||||
// - Quintic
|
||||
// Used in Value, Perlin Noise and Position Warping
|
||||
// Default: Quintic
|
||||
void SetInterp(Interp interp) { m_interp = interp; }
|
||||
|
||||
// Returns interpolation method used for supported noise types
|
||||
Interp GetInterp() const { return m_interp; }
|
||||
|
||||
// Sets noise return type of GetNoise(...)
|
||||
// Default: Simplex
|
||||
void SetNoiseType(NoiseType noiseType) { m_noiseType = noiseType; }
|
||||
|
||||
// Returns the noise type used by GetNoise
|
||||
NoiseType GetNoiseType() const { return m_noiseType; }
|
||||
|
||||
// Sets octave count for all fractal noise types
|
||||
// Default: 3
|
||||
void SetFractalOctaves(int octaves) { m_octaves = octaves; CalculateFractalBounding(); }
|
||||
|
||||
// Returns octave count for all fractal noise types
|
||||
int GetFractalOctaves() const { return m_octaves; }
|
||||
|
||||
// Sets octave lacunarity for all fractal noise types
|
||||
// Default: 2.0
|
||||
void SetFractalLacunarity(FN_DECIMAL lacunarity) { m_lacunarity = lacunarity; }
|
||||
|
||||
// Returns octave lacunarity for all fractal noise types
|
||||
FN_DECIMAL GetFractalLacunarity() const { return m_lacunarity; }
|
||||
|
||||
// Sets octave gain for all fractal noise types
|
||||
// Default: 0.5
|
||||
void SetFractalGain(FN_DECIMAL gain) { m_gain = gain; CalculateFractalBounding(); }
|
||||
|
||||
// Returns octave gain for all fractal noise types
|
||||
FN_DECIMAL GetFractalGain() const { return m_gain; }
|
||||
|
||||
// Sets method for combining octaves in all fractal noise types
|
||||
// Default: FBM
|
||||
void SetFractalType(FractalType fractalType) { m_fractalType = fractalType; }
|
||||
|
||||
// Returns method for combining octaves in all fractal noise types
|
||||
FractalType GetFractalType() const { return m_fractalType; }
|
||||
|
||||
|
||||
// Sets distance function used in cellular noise calculations
|
||||
// Default: Euclidean
|
||||
void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { m_cellularDistanceFunction = cellularDistanceFunction; }
|
||||
|
||||
// Returns the distance function used in cellular noise calculations
|
||||
CellularDistanceFunction GetCellularDistanceFunction() const { return m_cellularDistanceFunction; }
|
||||
|
||||
// Sets return type from cellular noise calculations
|
||||
// Note: NoiseLookup requires another FastNoise object be set with SetCellularNoiseLookup() to function
|
||||
// Default: CellValue
|
||||
void SetCellularReturnType(CellularReturnType cellularReturnType) { m_cellularReturnType = cellularReturnType; }
|
||||
|
||||
// Returns the return type from cellular noise calculations
|
||||
CellularReturnType GetCellularReturnType() const { return m_cellularReturnType; }
|
||||
|
||||
// Noise used to calculate a cell value if cellular return type is NoiseLookup
|
||||
// The lookup value is acquired through GetNoise() so ensure you SetNoiseType() on the noise lookup, value, Perlin or simplex is recommended
|
||||
void SetCellularNoiseLookup(FastNoise* noise) { m_cellularNoiseLookup = noise; }
|
||||
|
||||
// Returns the noise used to calculate a cell value if the cellular return type is NoiseLookup
|
||||
FastNoise* GetCellularNoiseLookup() const { return m_cellularNoiseLookup; }
|
||||
|
||||
// Sets the 2 distance indices used for distance2 return types
|
||||
// Default: 0, 1
|
||||
// Note: index0 should be lower than index1
|
||||
// Both indices must be >= 0, index1 must be < 4
|
||||
void SetCellularDistance2Indices(int cellularDistanceIndex0, int cellularDistanceIndex1);
|
||||
|
||||
// Returns the 2 distance indices used for distance2 return types
|
||||
void GetCellularDistance2Indices(int& cellularDistanceIndex0, int& cellularDistanceIndex1) const;
|
||||
|
||||
// Sets the maximum distance a cellular point can move from its grid position
|
||||
// Setting this high will make artifacts more common
|
||||
// Default: 0.45
|
||||
void SetCellularJitter(FN_DECIMAL cellularJitter) { m_cellularJitter = cellularJitter; }
|
||||
|
||||
// Returns the maximum distance a cellular point can move from its grid position
|
||||
FN_DECIMAL GetCellularJitter() const { return m_cellularJitter; }
|
||||
|
||||
// Sets the maximum warp distance from original location when using GradientPerturb{Fractal}(...)
|
||||
// Default: 1.0
|
||||
void SetGradientPerturbAmp(FN_DECIMAL gradientPerturbAmp) { m_gradientPerturbAmp = gradientPerturbAmp; }
|
||||
|
||||
// Returns the maximum warp distance from original location when using GradientPerturb{Fractal}(...)
|
||||
FN_DECIMAL GetGradientPerturbAmp() const { return m_gradientPerturbAmp; }
|
||||
|
||||
//2D
|
||||
FN_DECIMAL GetValue(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL GetValueFractal(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL GetPerlin(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL GetPerlinFractal(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL GetSimplexFractal(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL GetCellular(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL GetWhiteNoiseInt(int x, int y) const;
|
||||
|
||||
FN_DECIMAL GetCubic(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL GetCubicFractal(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL GetNoise(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
void GradientPerturb(FN_DECIMAL& x, FN_DECIMAL& y) const;
|
||||
void GradientPerturbFractal(FN_DECIMAL& x, FN_DECIMAL& y) const;
|
||||
|
||||
//3D
|
||||
FN_DECIMAL GetValue(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL GetValueFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL GetPerlin(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL GetPerlinFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL GetSimplexFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL GetCellular(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL GetWhiteNoiseInt(int x, int y, int z) const;
|
||||
|
||||
FN_DECIMAL GetCubic(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL GetCubicFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL GetNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
void GradientPerturb(FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
|
||||
void GradientPerturbFractal(FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
|
||||
|
||||
//4D
|
||||
FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
|
||||
|
||||
FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
|
||||
FN_DECIMAL GetWhiteNoiseInt(int x, int y, int z, int w) const;
|
||||
|
||||
private:
|
||||
unsigned char m_perm[512];
|
||||
unsigned char m_perm12[512];
|
||||
|
||||
int m_seed = 1337;
|
||||
FN_DECIMAL m_frequency = FN_DECIMAL(0.01);
|
||||
Interp m_interp = Quintic;
|
||||
NoiseType m_noiseType = Simplex;
|
||||
|
||||
int m_octaves = 3;
|
||||
FN_DECIMAL m_lacunarity = FN_DECIMAL(2);
|
||||
FN_DECIMAL m_gain = FN_DECIMAL(0.5);
|
||||
FractalType m_fractalType = FBM;
|
||||
FN_DECIMAL m_fractalBounding;
|
||||
|
||||
CellularDistanceFunction m_cellularDistanceFunction = Euclidean;
|
||||
CellularReturnType m_cellularReturnType = CellValue;
|
||||
FastNoise* m_cellularNoiseLookup = nullptr;
|
||||
int m_cellularDistanceIndex0 = 0;
|
||||
int m_cellularDistanceIndex1 = 1;
|
||||
FN_DECIMAL m_cellularJitter = FN_DECIMAL(0.45);
|
||||
|
||||
FN_DECIMAL m_gradientPerturbAmp = FN_DECIMAL(1);
|
||||
|
||||
void CalculateFractalBounding();
|
||||
|
||||
//2D
|
||||
FN_DECIMAL SingleValueFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleValueFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleValueFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleValue(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL SinglePerlinFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SinglePerlinFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SinglePerlinFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SinglePerlin(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL SingleSimplexFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleSimplexFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleSimplexFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleSimplexFractalBlend(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL SingleCubicFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleCubicFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleCubicFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleCubic(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
FN_DECIMAL SingleCellular(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
FN_DECIMAL SingleCellular2Edge(FN_DECIMAL x, FN_DECIMAL y) const;
|
||||
|
||||
void SingleGradientPerturb(unsigned char offset, FN_DECIMAL warpAmp, FN_DECIMAL frequency, FN_DECIMAL& x, FN_DECIMAL& y) const;
|
||||
|
||||
//3D
|
||||
FN_DECIMAL SingleValueFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleValueFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleValueFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleValue(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL SinglePerlinFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SinglePerlinFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SinglePerlinFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SinglePerlin(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL SingleSimplexFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleSimplexFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleSimplexFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL SingleCubicFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleCubicFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleCubicFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleCubic(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
FN_DECIMAL SingleCellular(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
FN_DECIMAL SingleCellular2Edge(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
|
||||
|
||||
void SingleGradientPerturb(unsigned char offset, FN_DECIMAL warpAmp, FN_DECIMAL frequency, FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
|
||||
|
||||
//4D
|
||||
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
|
||||
|
||||
inline unsigned char Index2D_12(unsigned char offset, int x, int y) const;
|
||||
inline unsigned char Index3D_12(unsigned char offset, int x, int y, int z) const;
|
||||
inline unsigned char Index4D_32(unsigned char offset, int x, int y, int z, int w) const;
|
||||
inline unsigned char Index2D_256(unsigned char offset, int x, int y) const;
|
||||
inline unsigned char Index3D_256(unsigned char offset, int x, int y, int z) const;
|
||||
inline unsigned char Index4D_256(unsigned char offset, int x, int y, int z, int w) const;
|
||||
|
||||
inline FN_DECIMAL ValCoord2DFast(unsigned char offset, int x, int y) const;
|
||||
inline FN_DECIMAL ValCoord3DFast(unsigned char offset, int x, int y, int z) const;
|
||||
inline FN_DECIMAL GradCoord2D(unsigned char offset, int x, int y, FN_DECIMAL xd, FN_DECIMAL yd) const;
|
||||
inline FN_DECIMAL GradCoord3D(unsigned char offset, int x, int y, int z, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd) const;
|
||||
inline FN_DECIMAL GradCoord4D(unsigned char offset, int x, int y, int z, int w, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd, FN_DECIMAL wd) const;
|
||||
};
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -30,10 +30,10 @@
|
|||
void HeightmapChunk::generate() {
|
||||
for(int y = 0 ; y < CHUNK_DEPTH ; y++) {
|
||||
for(int x = 0 ; x < CHUNK_WIDTH ; x++) {
|
||||
double n1 = m_heightmap.noise1.GetNoise(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
double n2 = m_heightmap.noise2.GetNoise(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
double n3 = m_heightmap.noise3.GetNoise(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
double n4 = m_heightmap.noise4.GetNoise(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
double n1 = m_heightmap.noise1.GetNoise<double>(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
double n2 = m_heightmap.noise2.GetNoise<double>(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
double n3 = m_heightmap.noise3.GetNoise<double>(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
double n4 = m_heightmap.noise4.GetNoise<double>(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
|
||||
m_map[x + y * CHUNK_WIDTH] = s32((n1 + (n2 * n3 * (n4 * 2 - 1))) * 64 + 64);
|
||||
}
|
||||
}
|
||||
|
@ -48,22 +48,25 @@ void HeightmapChunk::setLandHeight(s8 x, s8 y, s32 height) {
|
|||
}
|
||||
|
||||
Heightmap::Heightmap(s32 seed) {
|
||||
noise1.SetNoiseType(FastNoise::NoiseType::SimplexFractal);
|
||||
noise1.SetFrequency(1 / 256.0f);
|
||||
noise1.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||
noise1.SetFractalType(FastNoiseLite::FractalType_FBm);
|
||||
noise1.SetFractalOctaves(4);
|
||||
noise1.SetFrequency(1 / 256.0f);
|
||||
|
||||
noise2.SetNoiseType(FastNoise::NoiseType::SimplexFractal);
|
||||
noise2.SetFrequency(1 / 256.0f);
|
||||
noise2.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||
noise2.SetFractalType(FastNoiseLite::FractalType_FBm);
|
||||
noise2.SetFractalOctaves(4);
|
||||
noise2.SetFrequency(1 / 256.0f);
|
||||
|
||||
noise3.SetNoiseType(FastNoise::NoiseType::SimplexFractal);
|
||||
noise3.SetFrequency(1 / 256.0f);
|
||||
noise3.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||
noise3.SetFractalType(FastNoiseLite::FractalType_FBm);
|
||||
noise3.SetFractalOctaves(4);
|
||||
noise3.SetFrequency(1 / 256.0f);
|
||||
|
||||
noise4.SetNoiseType(FastNoise::NoiseType::SimplexFractal);
|
||||
noise4.SetFractalType(FastNoise::FractalType::Billow);
|
||||
noise4.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||
// noise4.SetFractalType(FastNoiseLite::FractalType_FBm);
|
||||
// noise4.SetFractalOctaves(1);
|
||||
noise4.SetFrequency(1 / 1024.0f);
|
||||
noise4.SetFractalOctaves(1);
|
||||
|
||||
setSeed(seed);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <gk/core/Vector2.hpp>
|
||||
|
||||
#include "EngineConfig.hpp"
|
||||
#include "FastNoise.hpp"
|
||||
#include "FastNoiseLite.hpp"
|
||||
|
||||
class Heightmap;
|
||||
|
||||
|
@ -70,10 +70,10 @@ class Heightmap {
|
|||
|
||||
void setSeed(s32 seed);
|
||||
|
||||
FastNoise noise1;
|
||||
FastNoise noise2;
|
||||
FastNoise noise3;
|
||||
FastNoise noise4;
|
||||
FastNoiseLite noise1;
|
||||
FastNoiseLite noise2;
|
||||
FastNoiseLite noise3;
|
||||
FastNoiseLite noise4;
|
||||
|
||||
private:
|
||||
std::unordered_map<gk::Vector2i, HeightmapChunk> m_chunks;
|
||||
|
|
|
@ -33,14 +33,15 @@ TerrainBiomeSampler::TerrainBiomeSampler(const Dimension &dimension, s32 seed) :
|
|||
for (u8 i = 0; i < biomeParamCount; i++) {
|
||||
m_paramNoises.emplace_back();
|
||||
|
||||
m_paramNoises.back().SetNoiseType(FastNoise::NoiseType::SimplexFractal);
|
||||
m_paramNoises.back().SetFrequency(1 / 800.0f);
|
||||
m_paramNoises.back().SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||
m_paramNoises.back().SetFractalType(FastNoiseLite::FractalType_FBm);
|
||||
m_paramNoises.back().SetFractalOctaves(5);
|
||||
m_paramNoises.back().SetFrequency(1 / 800.0f);
|
||||
m_paramNoises.back().SetSeed(seed + i);
|
||||
}
|
||||
}
|
||||
|
||||
u16 TerrainBiomeSampler::getBiomeIndexAt(s32 x, s32 y) const {
|
||||
u16 TerrainBiomeSampler::getBiomeIndexAt(s32 x, s32 y) {
|
||||
// TODO with a lot of biomes, perhaps we want an R-Tree or similar, instead of a long loop.
|
||||
// Should also finish solving for analytic blending, or find completely separate solution such as isotropically-modified genlayer
|
||||
// If we continue with temp/precip/etc params, need to write a weighted lloyd smoother so biomes becone fairly represented.
|
||||
|
@ -54,7 +55,7 @@ u16 TerrainBiomeSampler::getBiomeIndexAt(s32 x, s32 y) const {
|
|||
|
||||
double deviation = 0;
|
||||
for (int i = 0; i < biomeParamCount; i++) {
|
||||
double dp = m_paramNoises[i].GetNoise(x, y) - biome.getParams()[i];
|
||||
double dp = m_paramNoises[i].GetNoise<double>(x, y) - biome.getParams()[i];
|
||||
deviation += dp * dp;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include <gk/core/IntTypes.hpp>
|
||||
|
||||
#include "FastNoise.hpp"
|
||||
#include "FastNoiseLite.hpp"
|
||||
|
||||
class Dimension;
|
||||
|
||||
|
@ -39,7 +39,7 @@ class TerrainBiomeSampler {
|
|||
public:
|
||||
TerrainBiomeSampler(const Dimension &dimension, s32 seed);
|
||||
|
||||
u16 getBiomeIndexAt(s32 x, s32 y) const;
|
||||
u16 getBiomeIndexAt(s32 x, s32 y);
|
||||
|
||||
// std::vector<WeightedIndex> getWeightedBiomeIndicesAt(double x, double y);
|
||||
|
||||
|
@ -49,7 +49,7 @@ class TerrainBiomeSampler {
|
|||
|
||||
const Dimension &m_dimension;
|
||||
|
||||
std::vector<FastNoise> m_paramNoises;
|
||||
std::vector<FastNoiseLite> m_paramNoises;
|
||||
};
|
||||
|
||||
#endif // TERRAINBIOMESAMPLER_HPP_
|
||||
|
|
|
@ -31,22 +31,24 @@
|
|||
#include "World.hpp"
|
||||
|
||||
#include <glm/gtc/noise.hpp>
|
||||
#include "FastNoise.hpp"
|
||||
#include "FastNoiseLite.hpp"
|
||||
|
||||
TerrainGenerator::TerrainGenerator(Heightmap &heightmap, const Dimension &dimension, s32 seed)
|
||||
: m_biomeSampler(dimension, seed), m_heightmap(heightmap)
|
||||
{
|
||||
m_caveNoise.SetFrequency(1.0 / 128.0);
|
||||
m_caveNoise.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||
m_caveNoise.SetFractalType(FastNoiseLite::FractalType::FractalType_FBm);
|
||||
m_caveNoise.SetFractalOctaves(2);
|
||||
m_caveNoise.SetFrequency(1.0 / 128.0);
|
||||
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
void TerrainGenerator::generate(ServerChunk &chunk) const {
|
||||
void TerrainGenerator::generate(ServerChunk &chunk) {
|
||||
fastNoiseGeneration(chunk);
|
||||
}
|
||||
|
||||
void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const {
|
||||
void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) {
|
||||
HeightmapChunk &heightmap = m_heightmap.getOrCreateChunk(chunk.x(), chunk.y());
|
||||
|
||||
Random_t rand;
|
||||
|
@ -285,14 +287,14 @@ inline void TerrainGenerator::generateCavesOld(ServerChunk &chunk, s8 x, s8 y, s
|
|||
}
|
||||
}
|
||||
|
||||
inline void TerrainGenerator::generateCaves(ServerChunk &chunk, int x, int y, int z) const {
|
||||
inline void TerrainGenerator::generateCaves(ServerChunk &chunk, int x, int y, int z) {
|
||||
int rx = x + chunk.x() * CHUNK_WIDTH;
|
||||
int ry = y + chunk.y() * CHUNK_DEPTH;
|
||||
int rz = z + chunk.z() * CHUNK_HEIGHT;
|
||||
|
||||
// Density map (not textured image)
|
||||
double n1 = m_caveNoise.GetSimplexFractal(rx, ry, rz);
|
||||
double n2 = m_caveNoise.GetSimplexFractal(rx, ry + 88.0, rz);
|
||||
double n1 = m_caveNoise.GetNoise<double>(rx, ry, rz);
|
||||
double n2 = m_caveNoise.GetNoise<double>(rx, ry + 88.0, rz);
|
||||
double finalNoise = n1 * n1 + n2 * n2;
|
||||
|
||||
if (finalNoise < 0.02) {
|
||||
|
|
|
@ -46,12 +46,12 @@ class TerrainGenerator {
|
|||
public:
|
||||
TerrainGenerator(Heightmap &heightmap, const Dimension &dimension, s32 seed);
|
||||
|
||||
void generate(ServerChunk &chunk) const;
|
||||
void generate(ServerChunk &chunk);
|
||||
|
||||
void setSeed(s32 seed) { m_caveNoise.SetSeed(seed); }
|
||||
|
||||
private:
|
||||
void fastNoiseGeneration(ServerChunk &chunk) const;
|
||||
void fastNoiseGeneration(ServerChunk &chunk);
|
||||
|
||||
bool tryPlaceTree(ServerChunk &chunk, int x, int y, int z, const Biome &biome, Random_t &rand) const;
|
||||
bool tryPlaceFlora(ServerChunk &chunk, int x, int y, int z, const Biome &biome, Random_t &rand) const;
|
||||
|
@ -59,7 +59,7 @@ class TerrainGenerator {
|
|||
|
||||
void generateOres(ServerChunk &chunk, int x, int y, int z, const Biome &biome, Random_t &rand) const;
|
||||
void generateCavesOld(ServerChunk &chunk, s8 x, s8 y, s8 z, int h, HeightmapChunk &heightmap) const;
|
||||
void generateCaves(ServerChunk &chunk, int x, int y, int z) const;
|
||||
void generateCaves(ServerChunk &chunk, int x, int y, int z);
|
||||
|
||||
void randomWalkOrePlace(ServerChunk &chunk, int x, int y, int z, Random_t &rand, u16 oreBlock, u16 deepBlock, int size) const;
|
||||
void oreFloodFill(ServerChunk &chunk, int x, int y, int z, u16 toReplace, u16 replaceWith, int depth, Random_t &rand) const;
|
||||
|
@ -71,7 +71,7 @@ class TerrainGenerator {
|
|||
|
||||
Heightmap &m_heightmap;
|
||||
|
||||
FastNoise m_caveNoise;
|
||||
FastNoiseLite m_caveNoise;
|
||||
};
|
||||
|
||||
#endif // TERRAINGENERATOR_HPP_
|
||||
|
|
Loading…
Reference in New Issue