载入中...
搜索中...
未找到
Material.h
浏览该文件的文档.
1#pragma once
2
3#include "graphics/Mesh.h"
4#include "graphics/Shader.h"
5#include "graphics/Texture.h"
6
7#include <map>
8#include <string>
9
10namespace eve::graphics {
11
12class Graphics;
13
26class Material {
27public:
28 static constexpr int kMaxPartsHint = 8;
29
30 Material() = default;
31 ~Material() = default;
32
33 Material(const Material &) = delete;
34 Material &operator=(const Material &) = delete;
35
37 void setShadingModel(const std::string &model);
38 std::string getShadingModel() const { return shadingModel_; }
39
40 void setAlbedoTexture(Texture *texture) { albedo_ = texture; }
41 Texture *getAlbedoTexture() const { return albedo_; }
42
43 void setNormalTexture(Texture *texture) { normal_ = texture; }
44 Texture *getNormalTexture() const { return normal_; }
45
46 void setHeightTexture(Texture *texture) { height_ = texture; }
47 Texture *getHeightTexture() const { return height_; }
48
50 void setShader(Shader *shader) { shader_ = shader; }
51 Shader *getShader() const { return shader_; }
52
53 void setTint(float r, float g, float b, float a = 1.f);
54 float getTintR() const { return r_; }
55 float getTintG() const { return g_; }
56 float getTintB() const { return b_; }
57 float getTintA() const { return a_; }
58
59 void setMetallic(float metallic);
60 float getMetallic() const { return metallic_; }
61
62 void setRoughness(float roughness);
63 float getRoughness() const { return roughness_; }
64
65 void setTexCellBomb(float cellScale, float strength, float rotAmount = 1.f);
66 float getTexCellBombScale() const { return texBombScale_; }
67 float getTexCellBombStrength() const { return texBombStrength_; }
68 float getTexCellBombRotation() const { return texBombRot_; }
69
70 void setParallax(float scale, float minLayers = 8.f, float maxLayers = 32.f);
71 float getParallaxScale() const { return parallaxScale_; }
72 float getParallaxMinLayers() const { return parallaxMinLayers_; }
73 float getParallaxMaxLayers() const { return parallaxMaxLayers_; }
74
75 void setReceiveLight(bool receive) { receiveLight_ = receive; }
76 bool getReceiveLight() const { return receiveLight_; }
77
78 void setCastShadow(bool cast) { castShadow_ = cast; }
79 bool getCastShadow() const { return castShadow_; }
80
81 void setReceiveShadow(bool receive) { receiveShadow_ = receive; }
82 bool getReceiveShadow() const { return receiveShadow_; }
83
84 void setCastOcclusion(bool cast) { castOcclusion_ = cast; }
85 bool getCastOcclusion() const { return castOcclusion_; }
86
87 void setHair(bool hair);
88 bool getHair() const { return isHair_; }
89
91 bool hasParam(const std::string &name) const;
92 void setFloat(const std::string &name, float value);
93 float getFloat(const std::string &name) const;
94
99 void bind(Graphics &gfx) const;
100
102 Shader *effectiveShader() const;
103
105 bool isTransparentHair() const;
106
107private:
108 std::string shadingModel_ = "pbr";
109 Texture *albedo_ = nullptr;
110 Texture *normal_ = nullptr;
111 Texture *height_ = nullptr;
112 Shader *shader_ = nullptr;
113 float r_ = 1.f, g_ = 1.f, b_ = 1.f, a_ = 1.f;
114 float metallic_ = 0.f;
115 float roughness_ = 0.45f;
116 float texBombScale_ = 4.f;
117 float texBombStrength_ = 0.f;
118 float texBombRot_ = 1.f;
119 float parallaxScale_ = 0.f;
120 float parallaxMinLayers_ = 8.f;
121 float parallaxMaxLayers_ = 32.f;
122 bool receiveLight_ = true;
123 bool castShadow_ = true;
124 bool receiveShadow_ = true;
125 bool castOcclusion_ = true;
126 bool isHair_ = false;
127 std::map<std::string, float> params_;
128};
129
134struct ModelPart {
135 std::string name;
136 Mesh *mesh = nullptr;
137 Material *material = nullptr;
138};
139
140} // namespace eve::graphics
std::string value
uint32_t a
uint32_t b
float roughness
float metallic
Shader * shader
glm::mat4 model
const char * name
Definition RockMesh.cpp:21
float scale
Definition TreeMesh.cpp:122
Packages shading method + surface parameters into one attachable asset.
Definition Material.h:26
float getFloat(const std::string &name) const
Definition Material.cpp:58
void setNormalTexture(Texture *texture)
Definition Material.h:43
void setAlbedoTexture(Texture *texture)
Definition Material.h:40
float getParallaxScale() const
Definition Material.h:71
bool hasParam(const std::string &name) const
Optional named float knobs (style / custom shader params).
Definition Material.cpp:54
bool getHair() const
Definition Material.h:88
void setCastShadow(bool cast)
Definition Material.h:78
void setCastOcclusion(bool cast)
Definition Material.h:84
void setHeightTexture(Texture *texture)
Definition Material.h:46
float getMetallic() const
Definition Material.h:60
Texture * getAlbedoTexture() const
Definition Material.h:41
float getTexCellBombRotation() const
Definition Material.h:68
float getTexCellBombStrength() const
Definition Material.h:67
float getTintR() const
Definition Material.h:54
void setMetallic(float metallic)
Definition Material.cpp:26
void setReceiveShadow(bool receive)
Definition Material.h:81
Material & operator=(const Material &)=delete
float getTexCellBombScale() const
Definition Material.h:66
Texture * getNormalTexture() const
Definition Material.h:44
float getRoughness() const
Definition Material.h:63
float getParallaxMinLayers() const
Definition Material.h:72
bool getReceiveShadow() const
Definition Material.h:82
void setRoughness(float roughness)
Definition Material.cpp:30
static constexpr int kMaxPartsHint
Definition Material.h:28
bool isTransparentHair() const
True when this material should go through the hair transparent pass.
Definition Material.cpp:68
float getTintA() const
Definition Material.h:57
bool getCastOcclusion() const
Definition Material.h:85
void setReceiveLight(bool receive)
Definition Material.h:75
void setShadingModel(const std::string &model)
"pbr" | "unlit" | "hair" | "custom" (unknown → pbr).
Definition Material.cpp:9
void setTexCellBomb(float cellScale, float strength, float rotAmount=1.f)
Definition Material.cpp:34
void setTint(float r, float g, float b, float a=1.f)
Definition Material.cpp:19
Shader * getShader() const
Definition Material.h:51
std::string getShadingModel() const
Definition Material.h:38
float getTintB() const
Definition Material.h:56
void setParallax(float scale, float minLayers=8.f, float maxLayers=32.f)
Definition Material.cpp:40
Material(const Material &)=delete
bool getCastShadow() const
Definition Material.h:79
float getTintG() const
Definition Material.h:55
bool getReceiveLight() const
Definition Material.h:76
float getParallaxMaxLayers() const
Definition Material.h:73
void bind(Graphics &gfx) const
Push this material onto Graphics mesh3d state for the next draw. Does not issue the draw itself.
Definition Material.cpp:72
void setFloat(const std::string &name, float value)
Definition Material.cpp:56
Shader * effectiveShader() const
Effective shader for Mesh3D draws (may be null → default PBR pipeline).
Definition Material.cpp:63
void setHair(bool hair)
Definition Material.cpp:49
Texture * getHeightTexture() const
Definition Material.h:47
void setShader(Shader *shader)
Optional Mesh3D / hair Shader. nullptr → built-in path for the shading model.
Definition Material.h:50
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:18
Custom GPU program.
Definition Shader.h:30
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6
One mesh + material slot on a multi-part model (Assimp mesh / body region). When Material* is null,...
Definition Material.h:134