载入中...
搜索中...
未找到
TextureRecipe.h
浏览该文件的文档.
1#pragma once
2
3#include "procgen/Params.h"
6
7#include <cstdint>
8#include <functional>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13namespace eve::image {
14class ImageData;
15}
16
17namespace eve::procgen {
18
21 std::function<image::ImageData *(const Params &params, std::string &error)>;
22
24public:
26
27 void registerRecipe(const std::string &id, TextureRecipeFn fn);
28 bool has(const std::string &id) const;
29 image::ImageData *generate(const std::string &id, const Params &params, std::string &error) const;
30 std::vector<std::string> list() const;
31
32 void registerBuiltins();
33
34private:
35 TextureRecipeRegistry() = default;
36 std::unordered_map<std::string, TextureRecipeFn> recipes_;
37 bool builtinsRegistered_ = false;
38};
39
41 int width = 64;
42 int height = 64;
43 uint32_t seed = 1;
44 float scale = 4.f;
45 int octaves = 4;
46 int colors = 6;
47 int pixelSize = 1;
48 bool seamless = true;
49 float warpAmp = 1.f;
50
51 static TextureGenContext fromParams(const Params &params);
52};
53
54void paintHeightToImage(image::ImageData &img, const std::vector<float> &height, int w, int h,
55 const ColorRamp &ramp, int bands, int pixelSize);
56
59 const std::function<float(float, float, const NoiseField &)> &fn,
60 std::vector<float> &height);
61
62image::ImageData *heightToNormalImage(const std::vector<float> &height, int w, int h,
63 float strength, bool seamless);
64
69struct PbrParams {
70 float roughnessLow = 0.45f; // roughness at the low end of displacement
71 float roughnessHigh = 0.85f; // roughness at the high end of displacement
72 float metallic = 0.f; // uniform metalness (0..1)
73 float normalStrength = 4.f; // normal-map height strength
74 float aoStrength = 1.f; // cavity/ambient-occlusion strength
75 float heightStrength = 1.f; // height-map displacement scale
76
77 static PbrParams fromParams(const Params &params);
78};
79
86 std::string id; // albedo recipe id, e.g. "tex.marble"
88 std::function<float(float, float, const NoiseField &)> height; // clamped to [0,1]
90};
91
93const std::vector<TextureRecipeDef> &builtinTextureDefs();
94
95} // namespace eve::procgen
float height
Definition Grass.cpp:235
int h
int w
std::string error
SettlementPipeline::Stage fn
Represents raw pixel data.
Definition ImageData.h:26
Generation parameters. Algorithm-specific keys live in values as strings (no overloads; typed setters...
Definition Params.h:13
bool has(const std::string &id) const
void registerRecipe(const std::string &id, TextureRecipeFn fn)
std::vector< std::string > list() const
image::ImageData * generate(const std::string &id, const Params &params, std::string &error) const
static TextureRecipeRegistry & instance()
const std::vector< TextureRecipeDef > & builtinTextureDefs()
All built-in texture definitions (albedo + PBR). Populated lazily.
void paintHeightToImage(image::ImageData &img, const std::vector< float > &height, int w, int h, const ColorRamp &ramp, int bands, int pixelSize)
image::ImageData * heightToNormalImage(const std::vector< float > &height, int w, int h, float strength, bool seamless)
void fillHeightField(const TextureGenContext &ctx, const std::function< float(float, float, const NoiseField &)> &fn, std::vector< float > &height)
Sample a height function over the full [w×h] grid into height (clamped to [0,1]).
std::function< image::ImageData *(const Params &params, std::string &error)> TextureRecipeFn
Recipe returns a new RGBA8 ImageData (caller owns), or nullptr on failure.
Piecewise-linear color ramp in t∈[0,1], with optional hard banding.
Definition ColorRamp.h:13
Deterministic value-noise helpers for pixel textures. When periodX/periodY > 0, lattice wraps for sea...
Definition NoiseField.h:11
PBR surface defaults for a generated material. Every map in a PBR set is derived from the same displa...
static PbrParams fromParams(const Params &params)
static TextureGenContext fromParams(const Params &params)
A procedural texture is fully described by an albedo ramp + a displacement field + PBR knobs....
std::function< float(float, float, const NoiseField &)> height