载入中...
搜索中...
未找到
TextureRecipe.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "procgen/Params.h"
9
10#include <cstdint>
11#include <functional>
12#include <memory>
13#include <string>
14#include <unordered_map>
15#include <vector>
16
17namespace eve::image {
18class ImageData;
19}
20
21namespace eve::procgen {
22
24using TextureRecipeFn = std::function<std::unique_ptr<image::ImageData>(const Params &params, std::string &error)>;
25
28public:
30 static TextureRecipeRegistry &instance();
31
33 void registerRecipe(const std::string &id, TextureRecipeFn fn);
35 void registerRecipe(RecipeDescriptor descriptor, TextureRecipeFn fn);
37 bool has(const std::string &id) const;
46 [[nodiscard]] std::unique_ptr<image::ImageData> generate(const std::string &id, const Params &params,
47 std::string &error) const;
49 std::vector<std::string> list() const;
51 const RecipeDescriptor *descriptor(const std::string &id) const;
53 bool applyDefaults(const std::string &id, Params &params) const;
54
56 void registerBuiltins();
57
58private:
59 struct Entry {
62 };
63 TextureRecipeRegistry() = default;
64 std::unordered_map<std::string, Entry> recipes_;
65 bool builtinsRegistered_ = false;
66};
67
70 int width = 64;
71 int height = 64;
72 uint32_t seed = 1;
73 float scale = 4.f;
74 int octaves = 4;
75 int colors = 6;
76 int pixelSize = 1;
77 bool seamless = true;
78 float warpAmp = 1.f;
79
82};
83
85void paintHeightToImage(image::ImageData &img, const std::vector<float> &height, int w, int h,
86 const ColorRamp &ramp, int bands, int pixelSize);
87
91 const std::function<float(float, float, const NoiseField &)> &fn,
92 std::vector<float> &height);
93
98[[nodiscard]] std::unique_ptr<image::ImageData> heightToNormalImage(const std::vector<float> &height, int w, int h,
99 float strength, bool seamless);
100
105struct PbrParams {
106 float roughnessLow = 0.45f; // roughness at the low end of displacement
107 float roughnessHigh = 0.85f; // roughness at the high end of displacement
108 float metallic = 0.f; // uniform metalness (0..1)
109 float normalStrength = 4.f; // normal-map height strength
110 float aoStrength = 1.f; // cavity/ambient-occlusion strength
111 float heightStrength = 1.f; // height-map displacement scale
112
114 static PbrParams fromParams(const Params &params);
115};
116
123 std::string id; // albedo recipe id, e.g. "tex.marble"
126 std::function<float(float, float, const NoiseField &)> height; // clamped to [0,1]
128};
129
131const std::vector<TextureRecipeDef> &builtinTextureDefs();
132
135
136} // namespace eve::procgen
float w
Definition AnimClip.cpp:738
std::string descriptor
bool seamless
#define EVENGINE_API_DOMAINS
Definition Export.h:110
int pixelSize
int h
std::uint32_t height
std::string error
Definition Package.cpp:60
Represents raw pixel data.
Definition ImageData.h:38
Owning, typed generation parameters.
Definition Params.h:27
EVENGINE_API_DOMAINS public API.
std::vector< ParamSpec > params
std::function< std::unique_ptr< image::ImageData >(const Params &params, std::string &error)> TextureRecipeFn
Recipe returns a newly owned RGBA8 image, or null on failure.
RecipeDescriptor makeTextureRecipeDescriptor(const TextureRecipeDef &definition)
Build editable metadata for a texture definition.
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)
Paint height to image.
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::unique_ptr< image::ImageData > heightToNormalImage(const std::vector< float > &height, int w, int h, float strength, bool seamless)
Builds a normal-map image and transfers its unique ownership to the caller.
SettlementPipeline::Stage fn
Piecewise-linear color ramp in t∈[0,1], with optional hard banding.
Definition ColorRamp.h:16
Deterministic value-noise helpers for pixel textures. When periodX/periodY > 0, lattice wraps for sea...
Definition NoiseField.h:13
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)
From params.
Complete metadata and parameter schema shared by every procgen recipe family.
Definition ParamSchema.h:52
TextureGenContext public API.
static TextureGenContext fromParams(const Params &params)
From params.
A procedural texture is fully described by an albedo ramp + a displacement field + PBR knobs....
std::function< float(float, float, const NoiseField &)> height
Float.