载入中...
搜索中...
未找到
Material.cpp
浏览该文件的文档.
1#include "graphics/Material.h"
2
4#include "graphics/Graphics.h"
5#include "graphics/Light.h"
6
7namespace eve::graphics {
8
9void Material::setShadingModel(const std::string &model) {
10 if (model == "unlit" || model == "hair" || model == "custom" || model == "pbr") {
11 shadingModel_ = model;
12 } else {
13 shadingModel_ = "pbr";
14 }
15 if (shadingModel_ == "unlit") receiveLight_ = false;
16 if (shadingModel_ == "hair") isHair_ = true;
17}
18
19void Material::setTint(float r, float g, float b, float a) {
20 r_ = r;
21 g_ = g;
22 b_ = b;
23 a_ = a;
24}
25
27 metallic_ = metallic < 0.f ? 0.f : (metallic > 1.f ? 1.f : metallic);
28}
29
31 roughness_ = roughness < 0.04f ? 0.04f : (roughness > 1.f ? 1.f : roughness);
32}
33
34void Material::setTexCellBomb(float cellScale, float strength, float rotAmount) {
35 texBombScale_ = cellScale > 1e-3f ? cellScale : 1e-3f;
36 texBombStrength_ = strength < 0.f ? 0.f : (strength > 1.f ? 1.f : strength);
37 texBombRot_ = rotAmount < 0.f ? 0.f : (rotAmount > 1.f ? 1.f : rotAmount);
38}
39
40void Material::setParallax(float scale, float minLayers, float maxLayers) {
41 parallaxScale_ = scale < 0.f ? 0.f : (scale > 0.25f ? 0.25f : scale);
42 float minL = minLayers < 1.f ? 1.f : minLayers;
43 float maxL = maxLayers < minL ? minL : maxLayers;
44 if (maxL > 64.f) maxL = 64.f;
45 parallaxMinLayers_ = minL;
46 parallaxMaxLayers_ = maxL;
47}
48
49void Material::setHair(bool hair) {
50 isHair_ = hair;
51 if (hair) shadingModel_ = "hair";
52}
53
54bool Material::hasParam(const std::string &name) const { return params_.count(name) > 0; }
55
56void Material::setFloat(const std::string &name, float value) { params_[name] = value; }
57
58float Material::getFloat(const std::string &name) const {
59 auto it = params_.find(name);
60 return it == params_.end() ? 0.f : it->second;
61}
62
64 if (shadingModel_ == "custom") return shader_;
65 return shader_;
66}
67
69 return isHair_ || shadingModel_ == "hair";
70}
71
72void Material::bind(Graphics &gfx) const {
73 gfx.setMesh3DMaterial(metallic_, roughness_);
74 gfx.setMesh3DTexCellBomb(texBombScale_, texBombStrength_, texBombRot_);
75 gfx.setMesh3DNormalTexture(normal_);
76 gfx.setMesh3DHeightTexture(height_);
77 gfx.setMesh3DParallax(parallaxScale_, parallaxMinLayers_, parallaxMaxLayers_);
78 gfx.setMesh3DShadowReceive(receiveShadow_);
79
80 if (!receiveLight_ || shadingModel_ == "unlit") {
81 // Cheap toggle only: never clobber the clustered light table that the
82 // frame uploaded once (see Graphics::setMesh3DClusteredActive).
83 gfx.setMesh3DClusteredActive(false);
84 Lighting3DPack none{};
85 none.count = 0;
86 none.ambient = glm::vec4(1.f, 1.f, 1.f, 0.f);
87 gfx.setMesh3DLighting(none);
88 }
89
90 if (shader_ && !params_.empty()) {
91 for (const auto &kv : params_) {
92 if (shader_->hasUniform(kv.first)) shader_->sendFloat(kv.first, kv.second);
93 }
94 }
95}
96
97} // namespace eve::graphics
std::string value
uint32_t a
uint32_t b
float roughness
float metallic
bool hair
glm::mat4 model
const char * name
Definition RockMesh.cpp:21
float scale
Definition TreeMesh.cpp:122
virtual void setMesh3DMaterial(float metallic, float roughness)=0
Metallic (0..1) and roughness (0..1) for the next default mesh draw.
virtual void setMesh3DClusteredActive(bool active)=0
Cheap per-draw toggle for the already-uploaded clustered light table. Unlike setMesh3DClusteredLighti...
virtual void setMesh3DTexCellBomb(float cellScale, float strength, float rotAmount=1.f)=0
Texture cell bombing for the next default mesh draw (breaks tiling). cellScale: cells per UV unit (ty...
virtual void setMesh3DParallax(float scale, float minLayers=8.f, float maxLayers=32.f)=0
Parallax occlusion mapping for the next default mesh draw. scale: UV displacement strength (0=off)....
virtual void setMesh3DShadowReceive(bool receive)=0
Per-draw: when false, shadow sampling is forced off for the next mesh draw.
virtual void setMesh3DNormalTexture(Texture *normal)=0
Optional normal map for the next drawMesh / drawMeshShader (nullptr = flat).
virtual void setMesh3DHeightTexture(Texture *height)=0
Optional height map for parallax (R channel; nullptr = flat / off).
virtual void setMesh3DLighting(const Lighting3DPack &pack)=0
Per-frame ambient + up to 8 lights packed into Mesh3DUBO.
float getFloat(const std::string &name) const
Definition Material.cpp:58
bool hasParam(const std::string &name) const
Optional named float knobs (style / custom shader params).
Definition Material.cpp:54
void setMetallic(float metallic)
Definition Material.cpp:26
void setRoughness(float roughness)
Definition Material.cpp:30
bool isTransparentHair() const
True when this material should go through the hair transparent pass.
Definition Material.cpp:68
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
void setParallax(float scale, float minLayers=8.f, float maxLayers=32.f)
Definition Material.cpp:40
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
Custom GPU program.
Definition Shader.h:30
bool hasUniform(const std::string &name) const
Definition Shader.cpp:46
void sendFloat(const std::string &name, float x)
Definition Shader.cpp:82
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6