载入中...
搜索中...
未找到
Material.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Result.h"
7#include "graphics/Mesh.h"
9#include "graphics/Shader.h"
11#include "graphics/Texture.h"
12
13#include <map>
14#include <string>
15
16namespace eve::graphics {
17
18class Graphics;
19
22
36public:
37 static constexpr int kMaxPartsHint = 8;
38
40 Material() = default;
42 ~Material() = default;
43
44 Material(const Material&) = delete;
45 Material& operator=(const Material&) = delete;
46
48 void setShadingModel(const std::string& model);
50 std::string getShadingModel() const { return shadingModel_; }
51
56 [[nodiscard]] Result<void> setPbrSurface(const PbrSurface& surface);
59 auto s = pbr_;
60 s.unlit = shadingModel_ == "unlit";
61 return s;
62 }
64 bool hasPbrSurface() const { return pbrEnabled_; }
65
89 [[nodiscard]] Result<void> setFoliageTranslucency(float red, float green, float blue, float intensity,
90 float strength, float normalDistortion, float scattering,
91 float direct, float ambient, float shadow);
99 [[nodiscard]] Result<void> setFoliageWind(Texture* motionTexture, Texture* noiseTexture, float directionX,
100 float directionZ, float strength, float bending, float bendingSpeed,
101 float branch, float branchSpeed, float flutter, float flutterSpeed,
102 float fadeDistance, float bendFactor);
107 [[nodiscard]] Result<void> setFoliageWindTime(float seconds);
112 void setAlbedoTexture(Texture* texture) { pbr_.textures[0].texture = texture; }
117 Texture* getAlbedoTexture() const { return pbr_.textures[0].texture; }
118
123 void setNormalTexture(Texture* texture) { pbr_.textures[2].texture = texture; }
128 Texture* getNormalTexture() const { return pbr_.textures[2].texture; }
129
131 void setHeightTexture(Texture* texture) { height_ = texture; }
133 Texture* getHeightTexture() const { return height_; }
134
147 [[nodiscard]] eve::Result<void> setVirtualTexture(Texture* albedoAtlas, Texture* normalAtlas, Texture* pageTable,
148 int pageCountX, int pageCountY, int atlasSlotsX, int atlasSlotsY,
149 float borderFraction);
150
152 void clearVirtualTexture();
155 return virtualTextureEnabled_ ? MaterialVirtualTextureMode::AtlasPageTable
156 : MaterialVirtualTextureMode::Conventional;
157 }
158
163 void setShader(Shader* shader) { shader_ = shader; }
166 Shader* getShader() const { return shader_; }
167
169 void setTint(float r, float g, float b, float a = 1.f);
171 float getTintR() const { return r_; }
173 float getTintG() const { return g_; }
175 float getTintB() const { return b_; }
177 float getTintA() const { return a_; }
178
180 void setMetallic(float metallic);
182 float getMetallic() const { return metallic_; }
183
185 void setRoughness(float roughness);
187 float getRoughness() const { return roughness_; }
188
190 void setTexCellBomb(float cellScale, float strength, float rotAmount = 1.f);
192 float getTexCellBombScale() const { return texBombScale_; }
194 float getTexCellBombStrength() const { return texBombStrength_; }
196 float getTexCellBombRotation() const { return texBombRot_; }
197
199 void setParallax(float scale, float minLayers = 8.f, float maxLayers = 32.f);
201 float getParallaxScale() const { return parallaxScale_; }
203 float getParallaxMinLayers() const { return parallaxMinLayers_; }
205 float getParallaxMaxLayers() const { return parallaxMaxLayers_; }
206
208 void setReceiveLight(bool receive) { receiveLight_ = receive; }
210 bool getReceiveLight() const { return receiveLight_ && shadingModel_ != "unlit"; }
211
213 void setCastShadow(bool cast) { castShadow_ = cast; }
215 bool getCastShadow() const { return castShadow_; }
216
218 void setReceiveShadow(bool receive) { receiveShadow_ = receive; }
220 bool getReceiveShadow() const { return receiveShadow_; }
221
223 void setCastOcclusion(bool cast) { castOcclusion_ = cast; }
225 bool getCastOcclusion() const { return castOcclusion_; }
226
228 void setHair(bool hair);
230 bool getHair() const { return isHair_; }
231
233 bool hasParam(const std::string& name) const;
235 void setFloat(const std::string& name, float value);
237 float getFloat(const std::string& name) const;
238
243 [[nodiscard]] Result<void> bind(Graphics& gfx) const;
244
247 Shader* effectiveShader() const;
248
250 bool isTransparentHair() const;
251
253 void setSurfaceMode(const std::string& mode);
255 std::string getSurfaceMode() const;
257 SurfaceMode surfaceMode() const { return surfaceMode_; }
259 void setAlphaCutoff(float cutoff);
261 float getAlphaCutoff() const { return alphaCutoff_; }
263 void setBlendMode(const std::string& mode);
265 std::string getBlendMode() const;
267 BlendMode blendMode() const { return blendMode_; }
269 void setDepthWrite(bool enabled) { depthWrite_ = enabled; }
271 bool getDepthWrite() const { return depthWrite_; }
273 void setDoubleSided(bool enabled) { doubleSided_ = enabled; }
275 bool getDoubleSided() const { return doubleSided_; }
277 void setCameraFacing(bool enabled) { cameraFacing_ = enabled; }
279 bool getCameraFacing() const { return cameraFacing_; }
281 void setSortPriority(int priority) { sortPriority_ = priority; }
283 int getSortPriority() const { return sortPriority_; }
285 void setAlphaTechnique(const std::string& technique);
287 std::string getAlphaTechnique() const { return alphaTechnique_; }
288
289private:
290 PbrSurface pbr_;
291 bool pbrEnabled_ = false;
292 std::string shadingModel_ = "pbr";
293 Texture* height_ = nullptr;
294 Shader* shader_ = nullptr;
295 float r_ = 1.f, g_ = 1.f, b_ = 1.f, a_ = 1.f;
296 float metallic_ = 0.f;
297 float roughness_ = 0.45f;
298 float texBombScale_ = 4.f;
299 float texBombStrength_ = 0.f;
300 float texBombRot_ = 1.f;
301 float parallaxScale_ = 0.f;
302 float parallaxMinLayers_ = 8.f;
303 float parallaxMaxLayers_ = 32.f;
304 bool receiveLight_ = true;
305 bool castShadow_ = true;
306 bool receiveShadow_ = true;
307 bool castOcclusion_ = true;
308 bool isHair_ = false;
309 SurfaceMode surfaceMode_ = SurfaceMode::Opaque;
310 BlendMode blendMode_ = BlendMode::Alpha;
311 float alphaCutoff_ = 0.5f;
312 bool depthWrite_ = false;
313 bool doubleSided_ = false;
314 bool cameraFacing_ = false;
315 int sortPriority_ = 0;
316 std::string alphaTechnique_ = "cutoff";
317 bool virtualTextureEnabled_ = false;
318 int virtualPageCountX_ = 0;
319 int virtualPageCountY_ = 0;
320 int virtualAtlasSlotsX_ = 0;
321 int virtualAtlasSlotsY_ = 0;
322 float virtualBorderFraction_ = 0.f;
323 std::map<std::string, float> params_;
324};
325
330struct ModelPart {
331 std::string name;
332 Mesh* mesh = nullptr;
333 Material* material = nullptr;
336 bool hasSortPriority = false;
337};
338
339} // namespace eve::graphics
double value
const std::string & s
int priority
#define EVENGINE_API_BACKENDS
Definition Export.h:108
tensor::Graph g
Definition GpuGraph.cpp:7
double r
std::array< float, 3 > scale
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float roughness
float metallic
Shader * shader
bool hair
glm::mat4 model
Move-only, checked operation results for the common layer.
Vec scattering
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Packages shading method + surface parameters into one attachable asset.
Definition Material.h:35
void setNormalTexture(Texture *texture)
Set the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:123
void setAlbedoTexture(Texture *texture)
Set the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:112
float getParallaxScale() const
Returns the parallax scale.
Definition Material.h:201
std::string getAlphaTechnique() const
Returns the alpha technique.
Definition Material.h:287
bool hasPbrSurface() const
Whether full PBR texture/extension rendering is requested.
Definition Material.h:64
bool getHair() const
Returns the hair.
Definition Material.h:230
void setCastShadow(bool cast)
Sets the cast shadow.
Definition Material.h:213
void setCastOcclusion(bool cast)
Sets the cast occlusion.
Definition Material.h:223
void setHeightTexture(Texture *texture)
Sets the height texture.
Definition Material.h:131
float getMetallic() const
Returns the metallic.
Definition Material.h:182
~Material()=default
Material.
Texture * getAlbedoTexture() const
Get the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:117
float getTexCellBombRotation() const
Returns the tex cell bomb rotation.
Definition Material.h:196
float getTexCellBombStrength() const
Returns the tex cell bomb strength.
Definition Material.h:194
float getTintR() const
Returns the tint r.
Definition Material.h:171
void setReceiveShadow(bool receive)
Sets the receive shadow.
Definition Material.h:218
Material & operator=(const Material &)=delete
Material()=default
Material.
float getTexCellBombScale() const
Returns the tex cell bomb scale.
Definition Material.h:192
PbrSurface pbrSurface() const
Return an owning parameter snapshot; texture resources remain borrowed.
Definition Material.h:58
Texture * getNormalTexture() const
Get the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:128
float getRoughness() const
Returns the roughness.
Definition Material.h:187
float getParallaxMinLayers() const
Returns the parallax min layers.
Definition Material.h:203
float getAlphaCutoff() const
Returns the alpha cutoff.
Definition Material.h:261
bool getReceiveShadow() const
Returns the receive shadow.
Definition Material.h:220
void setCameraFacing(bool enabled)
Keep a bottom-anchored card facing the active camera around world Y during GPU-driven draws.
Definition Material.h:277
BlendMode blendMode() const
Blend mode.
Definition Material.h:267
int getSortPriority() const
Returns the sort priority.
Definition Material.h:283
bool getCameraFacing() const
Return whether GPU-driven card vertices use cylindrical camera-facing orientation.
Definition Material.h:279
MaterialVirtualTextureMode virtualTextureMode() const
Return the active virtual-texture sampling mode.
Definition Material.h:154
float getTintA() const
Returns the tint a.
Definition Material.h:177
bool getCastOcclusion() const
Returns the cast occlusion.
Definition Material.h:225
bool getDoubleSided() const
Returns the double sided.
Definition Material.h:275
void setReceiveLight(bool receive)
Sets the receive light.
Definition Material.h:208
bool getDepthWrite() const
Returns the depth write.
Definition Material.h:271
Shader * getShader() const
Return the borrowed shader, or nullptr when the built-in path is active. @lifetime The pointer remain...
Definition Material.h:166
void setDepthWrite(bool enabled)
Sets the depth write.
Definition Material.h:269
std::string getShadingModel() const
Returns the shading model.
Definition Material.h:50
float getTintB() const
Returns the tint b.
Definition Material.h:175
Material(const Material &)=delete
bool getCastShadow() const
Returns the cast shadow.
Definition Material.h:215
float getTintG() const
Returns the tint g.
Definition Material.h:173
bool getReceiveLight() const
Returns the receive light.
Definition Material.h:210
float getParallaxMaxLayers() const
Returns the parallax max layers.
Definition Material.h:205
SurfaceMode surfaceMode() const
Surface mode.
Definition Material.h:257
void setSortPriority(int priority)
Sets the sort priority.
Definition Material.h:281
Texture * getHeightTexture() const
Returns the height texture.
Definition Material.h:133
void setShader(Shader *shader)
Set an optional Mesh3D / hair shader; nullptr selects the built-in shading path.
Definition Material.h:163
void setDoubleSided(bool enabled)
Sets the double sided.
Definition Material.h:273
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:25
Custom GPU program.
Definition Shader.h:39
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
SurfaceMode
How a 3D surface contributes to depth and color passes.
Definition SurfaceMode.h:6
MaterialVirtualTextureMode
Selects conventional or atlas/page-table material sampling.
Definition Material.h:21
BlendMode
Render-neutral 2D blend mode shared by graphics-facing modules.
Definition RenderTypes.h:11
bool enabled
One mesh + material slot on a multi-part model (Assimp mesh / body region). When Material* is null,...
Definition Material.h:330
int sortPriority
Optional per-instance transparent ordering override.
Definition Material.h:335
Owning material parameter snapshot; texture pointers remain borrowed. Base color/metallic/roughness c...
Definition PbrSurface.h:218
glm::vec4 ambient