载入中...
搜索中...
未找到
BuiltinHeightmap.cpp
浏览该文件的文档.
2#include "procgen/Semantic.h"
4
5#include <string>
6
7namespace eve::procgen {
8namespace {
9
10bool genTerrainHeightmap(const Params &params, Grid2D &out, std::string &error) {
11 const int w = params.getWidth();
12 const int h = params.getHeight();
13 if (w < 1 || h < 1) {
14 error = "terrain.heightmap: width/height must be positive";
15 return false;
16 }
17 const TerrainSampler sampler = TerrainSampler::fromParams(params);
18 const TerrainBands bands = TerrainBands::fromParams(params);
19
20 const Heightmap hm = Heightmap::generate(sampler, w, h);
21 if (!hm.toGrid(out, bands)) {
22 error = "terrain.heightmap: failed to classify heightmap";
23 return false;
24 }
25
26 out.setMeta("algorithm", "terrain.heightmap");
27 out.setMeta("scale", std::to_string(sampler.getScale()));
28 out.setMeta("octaves", std::to_string(sampler.getOctaves()));
29 return true;
30}
31
32} // namespace
33
35 auto descriptor = GeneratorDescriptor::grid("terrain.heightmap", "Terrain Heightmap", "Terrain", 1, 1);
36 descriptor.params.push_back(ParamDescriptor::floating("scale", "Noise Scale", 1.f / 32.f, 0.0001f, 1.f,
37 0.001f));
38 descriptor.params.push_back(ParamDescriptor::integer("octaves", "Octaves", 5, 1, 16));
39 descriptor.params.push_back(ParamDescriptor::floating("lacunarity", "Lacunarity", 2.f, 1.f, 8.f, 0.05f));
40 descriptor.params.push_back(ParamDescriptor::floating("gain", "Gain", 0.5f, 0.f, 1.f, 0.01f));
41 descriptor.params.push_back(ParamDescriptor::floating("ridge", "Ridge", 0.35f, 0.f, 1.f, 0.01f));
42 descriptor.params.push_back(ParamDescriptor::floating("warp", "Warp", 0.35f, 0.f, 4.f, 0.01f));
43 descriptor.params.push_back(ParamDescriptor::floating("exponent", "Exponent", 2.f, 0.1f, 8.f, 0.05f));
44 descriptor.params.push_back(ParamDescriptor::floating("continent", "Continent", 0.55f, 0.f, 1.f, 0.01f));
45 descriptor.params.push_back(ParamDescriptor::floating("island", "Island", 0.38f, 0.f, 1.f, 0.01f));
46 descriptor.params.push_back(ParamDescriptor::floating("coast", "Coast Softness", 0.12f, 0.f, 1.f, 0.01f));
47 descriptor.params.push_back(ParamDescriptor::floating("base", "Base Height", 0.f, -10.f, 10.f, 0.01f));
48 descriptor.params.push_back(ParamDescriptor::floating("amplitude", "Amplitude", 1.f, 0.f, 1000.f, 0.1f));
49 descriptor.params.push_back(ParamDescriptor::boolean("clamp", "Clamp Height", true));
50 descriptor.params.push_back(ParamDescriptor::floating("heightMin", "Minimum Height", 0.f, -1000.f, 1000.f,
51 0.1f));
52 descriptor.params.push_back(ParamDescriptor::floating("heightMax", "Maximum Height", 1.f, -1000.f, 1000.f,
53 0.1f));
54 registry.registerAlgorithm(std::move(descriptor), genTerrainHeightmap);
55}
56
57} // namespace eve::procgen
float w
Definition AnimClip.cpp:738
std::string descriptor
vk::UniqueSampler sampler
int h
std::string error
Definition Package.cpp:60
Registry for executable generators and their reflection metadata.
void registerAlgorithm(const std::string &id, GeneratorFn fn)
Register an algorithm without metadata for backward compatibility.
static Heightmap generate(const TerrainSampler &sampler, int width, int height)
Materialize a Heightmap by sampling sampler at every pixel center.
Definition Heightmap.cpp:69
static TerrainSampler fromParams(const Params &params)
From params.
std::vector< ParamSpec > params
void registerTerrainHeightmapAlgorithm(GeneratorRegistry &registry)
static ParamDescriptor boolean(std::string key, std::string label, bool defaultValue)
Construct a Boolean descriptor stored as zero or one in Params.
static ParamDescriptor floating(std::string key, std::string label, float defaultValue, float minimum, float maximum, float step)
Construct a bounded floating-point descriptor.
static ParamDescriptor integer(std::string key, std::string label, int defaultValue, int minimum, int maximum, int step=1)
Construct a bounded integer descriptor.
static RecipeDescriptor grid(std::string id, std::string displayName, std::string category, int minimumWidth, int minimumHeight, int maximumWidth=4096, int maximumHeight=4096)
Create a schema with common seed, width and height parameters.
static TerrainBands fromParams(const Params &params)
From params.