载入中...
搜索中...
未找到
TerrainSampler.h
浏览该文件的文档.
1#pragma once
2
3#include "procgen/Params.h"
5
6#include <cstdint>
7#include <functional>
8
9namespace eve::procgen {
10
28public:
29 TerrainSampler() = default;
30
31 float sample(float x, float y) const;
33 float sampleTile(int tileX, int tileY) const;
34 std::function<float(float, float)> asFunction() const;
35
36 void setSeed(uint32_t seed);
37 uint32_t getSeed() const;
39 void setScale(float scale);
40 float getScale() const;
41 void setFrequency(float frequency);
42 float getFrequency() const;
44 void setWavelength(float wavelength);
45 float getWavelength() const;
46 void setOctaves(int octaves);
47 int getOctaves() const;
48 void setLacunarity(float lacunarity);
49 float getLacunarity() const;
50 void setGain(float gain);
51 float getGain() const;
52 void setRidge(float ridge);
53 float getRidge() const;
54 void setWarp(float warp);
55 float getWarp() const;
56 void setExponent(float exponent);
57 float getExponent() const;
58 void setContinent(float continent);
59 float getContinent() const;
60 void setIsland(float island);
61 float getIsland() const;
63 void setCoastSoftness(float softness);
64 float getCoastSoftness() const;
65 void setWorldSize(int width, int height);
66 int getWorldWidth() const;
67 int getWorldHeight() const;
68 void setBase(float base);
69 float getBase() const;
70 void setAmplitude(float amplitude);
71 float getAmplitude() const;
72 void setClamp(bool enabled, float minHeight, float maxHeight);
73 bool isClamped() const;
74 float getClampMin() const;
75 float getClampMax() const;
76
77 static TerrainSampler fromParams(const Params &params);
78
79private:
80 NoiseField field_;
81 float frequency_ = 1.f / 32.f;
82 int octaves_ = 5;
83 float lacunarity_ = 2.f;
84 float gain_ = 0.5f;
85 float ridge_ = 0.35f;
86 float warp_ = 0.35f;
87 float exponent_ = 2.f;
88 float continent_ = 0.55f;
89 float island_ = 0.38f;
90 float coastSoft_ = 0.12f;
91 int worldW_ = 0;
92 int worldH_ = 0;
93 float base_ = 0.f;
94 float amplitude_ = 1.f;
95 bool clamp_ = true;
96 float clampMin_ = 0.f;
97 float clampMax_ = 1.f;
98};
99
101 float waterMax = 0.25f;
102 float sandMax = 0.35f;
103 float grassMax = 0.65f;
104 float dirtMax = 0.80f;
105 float stoneMax = 0.92f;
106
107 uint32_t semanticAt(float height) const;
108 static TerrainBands fromParams(const Params &params);
109};
110
111} // namespace eve::procgen
uint32_t seed
int y
Definition Grass.cpp:135
float height
Definition Grass.cpp:235
int x
Definition Grass.cpp:135
int width
bool enabled
float scale
Definition TreeMesh.cpp:122
Generation parameters. Algorithm-specific keys live in values as strings (no overloads; typed setters...
Definition Params.h:13
Deterministic terrain height sampling (Red Blob Games / Perlin fBm recipe).
float sample(float x, float y) const
float sampleTile(int tileX, int tileY) const
Height at the center of map tile (tileX, tileY).
void setLacunarity(float lacunarity)
void setFrequency(float frequency)
void setContinent(float continent)
void setClamp(bool enabled, float minHeight, float maxHeight)
void setAmplitude(float amplitude)
void setScale(float scale)
Cycles per world unit (alias of frequency). Default 1/32.
void setCoastSoftness(float softness)
Shore width of the land mask smoothstep. Smaller = cleaner, harder coast.
void setWorldSize(int width, int height)
void setExponent(float exponent)
static TerrainSampler fromParams(const Params &params)
std::function< float(float, float)> asFunction() const
void setWavelength(float wavelength)
Distance per large oscillation. Sets frequency = 1/wavelength.
Deterministic value-noise helpers for pixel textures. When periodX/periodY > 0, lattice wraps for sea...
Definition NoiseField.h:11
uint32_t semanticAt(float height) const
static TerrainBands fromParams(const Params &params)