载入中...
搜索中...
未找到
Material.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Result.h"
10
11#include <cstdint>
12#include <map>
13#include <memory>
14#include <string>
15
16namespace eve::graphics {
17
18class Graphics;
19class Mesh;
20class Shader;
21class Texture;
22
25
39public:
40 static constexpr int kMaxPartsHint = 8;
41
43 Material() = default;
45 ~Material() = default;
46
47 Material(const Material&) = delete;
48 Material& operator=(const Material&) = delete;
49
51 void setShadingModel(const std::string& model);
53 std::string getShadingModel() const { return shadingModel_; }
54
59 [[nodiscard]] Result<void> setPbrSurface(const PbrSurface& surface);
62 auto s = pbr_;
63 s.unlit = shadingModel_ == "unlit";
64 return s;
65 }
67 bool hasPbrSurface() const { return pbrEnabled_; }
68
92 [[nodiscard]] Result<void> setFoliageTranslucency(float red, float green, float blue, float intensity,
93 float strength, float normalDistortion, float scattering,
94 float direct, float ambient, float shadow);
102 [[nodiscard]] Result<void> setClearcoat(float factor, float roughness);
110 [[nodiscard]] Result<void> setFoliageWind(Texture* motionTexture, Texture* noiseTexture, float directionX,
111 float directionZ, float strength, float bending, float bendingSpeed,
112 float branch, float branchSpeed, float flutter, float flutterSpeed,
113 float fadeDistance, float bendFactor);
118 [[nodiscard]] Result<void> setFoliageWindTime(float seconds);
123 void setAlbedoTexture(Texture* texture) { pbr_.textures[0].texture = texture; }
128 Texture* getAlbedoTexture() const { return pbr_.textures[0].texture; }
129
139 [[nodiscard]] Result<void> setAlbedoUvOffset(float u, float v);
141 float getAlbedoUvOffsetU() const { return pbr_.textures[0].offset[0]; }
143 float getAlbedoUvOffsetV() const { return pbr_.textures[0].offset[1]; }
144
152 [[nodiscard]] Result<void> setAlbedoUvScale(float u, float v);
154 float getAlbedoUvScaleU() const { return pbr_.textures[0].scale[0]; }
156 float getAlbedoUvScaleV() const { return pbr_.textures[0].scale[1]; }
157
164 [[nodiscard]] Result<void> setAlbedoUvRotation(float radians);
166 float getAlbedoUvRotation() const { return pbr_.textures[0].rotation; }
167
172 void setNormalTexture(Texture* texture) { pbr_.textures[2].texture = texture; }
177 Texture* getNormalTexture() const { return pbr_.textures[2].texture; }
178
182 Texture* getHeightTexture() const { return height_; }
183
190 [[nodiscard]] eve::Result<void> enableVirtualTexture(const VirtualTextureStreamingConfig& config);
191
196 [[nodiscard]] eve::Result<std::uint32_t> addVirtualTextureLayer(const VirtualTextureBlendLayer& layer);
197
211 [[nodiscard]] eve::Result<void> setVirtualTexture(Texture* albedoAtlas, Texture* normalAtlas, Texture* pageTable,
212 int pageCountX, int pageCountY, int atlasSlotsX, int atlasSlotsY,
213 float borderFraction);
214
216 void clearVirtualTexture();
219 return virtualTextureEnabled_ ? MaterialVirtualTextureMode::AtlasPageTable
220 : MaterialVirtualTextureMode::Conventional;
221 }
222
227 void setShader(Shader* shader) { shader_ = shader; }
230 Shader* getShader() const { return shader_; }
231
233 void setTint(float r, float g, float b, float a = 1.f);
235 float getTintR() const { return r_; }
237 float getTintG() const { return g_; }
239 float getTintB() const { return b_; }
241 float getTintA() const { return a_; }
242
244 void setMetallic(float metallic);
246 float getMetallic() const { return metallic_; }
247
249 void setRoughness(float roughness);
251 float getRoughness() const { return roughness_; }
252
254 void setTexCellBomb(float cellScale, float strength, float rotAmount = 1.f);
256 float getTexCellBombScale() const { return texBombScale_; }
258 float getTexCellBombStrength() const { return texBombStrength_; }
260 float getTexCellBombRotation() const { return texBombRot_; }
261
263 void setParallax(float scale, float minLayers = 8.f, float maxLayers = 32.f);
265 float getParallaxScale() const { return parallaxScale_; }
267 float getParallaxMinLayers() const { return parallaxMinLayers_; }
269 float getParallaxMaxLayers() const { return parallaxMaxLayers_; }
270
272 void setReceiveLight(bool receive) { receiveLight_ = receive; }
274 bool getReceiveLight() const { return receiveLight_ && shadingModel_ != "unlit"; }
275
277 void setCastShadow(bool cast) { castShadow_ = cast; }
279 bool getCastShadow() const { return castShadow_; }
280
282 void setReceiveShadow(bool receive) { receiveShadow_ = receive; }
284 bool getReceiveShadow() const { return receiveShadow_; }
285
287 void setCastOcclusion(bool cast) { castOcclusion_ = cast; }
289 bool getCastOcclusion() const { return castOcclusion_; }
290
292 void setHair(bool hair);
294 bool getHair() const { return isHair_; }
295
297 bool hasParam(const std::string& name) const;
299 void setFloat(const std::string& name, float value);
301 float getFloat(const std::string& name) const;
302
312 [[nodiscard]] Result<void> bind(Graphics& gfx) const;
313
316 Shader* effectiveShader() const;
317
319 bool isTransparentHair() const;
320
322 void setSurfaceMode(const std::string& mode);
324 std::string getSurfaceMode() const;
326 SurfaceMode surfaceMode() const { return surfaceMode_; }
328 void setAlphaCutoff(float cutoff);
330 float getAlphaCutoff() const { return alphaCutoff_; }
332 void setBlendMode(const std::string& mode);
334 std::string getBlendMode() const;
336 BlendMode blendMode() const { return blendMode_; }
338 void setDepthWrite(bool enabled) { depthWrite_ = enabled; }
340 bool getDepthWrite() const { return depthWrite_; }
342 void setDoubleSided(bool enabled) { doubleSided_ = enabled; }
344 bool getDoubleSided() const { return doubleSided_; }
346 void setCameraFacing(bool enabled) { cameraFacing_ = enabled; }
348 bool getCameraFacing() const { return cameraFacing_; }
350 void setSortPriority(int priority) { sortPriority_ = priority; }
352 int getSortPriority() const { return sortPriority_; }
354 void setAlphaTechnique(const std::string& technique);
356 std::string getAlphaTechnique() const { return alphaTechnique_; }
357
358private:
359 [[nodiscard]] Result<void> tickVirtualTexture(Graphics& gfx) const;
360
361 PbrSurface pbr_;
362 bool pbrEnabled_ = false;
363 std::string shadingModel_ = "pbr";
364 Texture* height_ = nullptr;
365 Shader* shader_ = nullptr;
366 float r_ = 1.f, g_ = 1.f, b_ = 1.f, a_ = 1.f;
367 float metallic_ = 0.f;
368 float roughness_ = 0.45f;
369 float texBombScale_ = 4.f;
370 float texBombStrength_ = 0.f;
371 float texBombRot_ = 1.f;
372 float parallaxScale_ = 0.f;
373 float parallaxMinLayers_ = 8.f;
374 float parallaxMaxLayers_ = 32.f;
375 bool receiveLight_ = true;
376 bool castShadow_ = true;
377 bool receiveShadow_ = true;
378 bool castOcclusion_ = true;
379 bool isHair_ = false;
380 SurfaceMode surfaceMode_ = SurfaceMode::Opaque;
381 BlendMode blendMode_ = BlendMode::Alpha;
382 float alphaCutoff_ = 0.5f;
383 bool depthWrite_ = false;
384 bool doubleSided_ = false;
385 bool cameraFacing_ = false;
386 int sortPriority_ = 0;
387 std::string alphaTechnique_ = "cutoff";
388 bool virtualTextureEnabled_ = false;
389 int virtualPageCountX_ = 0;
390 int virtualPageCountY_ = 0;
391 int virtualAtlasSlotsX_ = 0;
392 int virtualAtlasSlotsY_ = 0;
393 float virtualBorderFraction_ = 0.f;
394 std::map<std::string, float> params_;
395 mutable std::unique_ptr<VirtualTextureStreaming> virtualStreaming_;
396 mutable std::uint64_t virtualStreamingEpoch_ = 0;
397 mutable bool virtualStreamingInitialized_ = false;
398};
399
404struct ModelPart {
405 std::string name;
406 Mesh* mesh = nullptr;
407 Material* material = nullptr;
410 bool hasSortPriority = false;
411};
412
413} // namespace eve::graphics
const std::string & s
int priority
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_BACKENDS
Definition Export.h:108
float strength
tensor::Graph g
Definition GpuGraph.cpp:7
float u
Definition Grass.cpp:233
double r
float v
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float roughness
float metallic
Texture * texture
TileLayer * layer
Object::Ptr value
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:176
Packages shading method + surface parameters into one attachable asset.
Definition Material.h:38
void setNormalTexture(Texture *texture)
Set the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:172
void setAlbedoTexture(Texture *texture)
Set the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:123
float getParallaxScale() const
Returns the parallax scale.
Definition Material.h:265
std::string getAlphaTechnique() const
Returns the alpha technique.
Definition Material.h:356
float getAlbedoUvOffsetV() const
Current base-color UV offset V.
Definition Material.h:143
bool hasPbrSurface() const
Whether full PBR texture/extension rendering is requested.
Definition Material.h:67
bool getHair() const
Returns the hair.
Definition Material.h:294
void setCastShadow(bool cast)
Sets the cast shadow.
Definition Material.h:277
void setCastOcclusion(bool cast)
Sets the cast occlusion.
Definition Material.h:287
void setHeightTexture(Texture *texture)
Sets the height texture.
Definition Material.h:180
float getMetallic() const
Returns the metallic.
Definition Material.h:246
~Material()=default
Material.
Texture * getAlbedoTexture() const
Get the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:128
float getTexCellBombRotation() const
Returns the tex cell bomb rotation.
Definition Material.h:260
float getTexCellBombStrength() const
Returns the tex cell bomb strength.
Definition Material.h:258
float getTintR() const
Returns the tint r.
Definition Material.h:235
void setReceiveShadow(bool receive)
Sets the receive shadow.
Definition Material.h:282
Material & operator=(const Material &)=delete
Material()=default
Material.
float getTexCellBombScale() const
Returns the tex cell bomb scale.
Definition Material.h:256
PbrSurface pbrSurface() const
Return an owning parameter snapshot; texture resources remain borrowed.
Definition Material.h:61
Texture * getNormalTexture() const
Get the borrowed material texture. @ownership Graphics factory owns the resource. @lifetime Keep aliv...
Definition Material.h:177
float getRoughness() const
Returns the roughness.
Definition Material.h:251
float getParallaxMinLayers() const
Returns the parallax min layers.
Definition Material.h:267
float getAlphaCutoff() const
Returns the alpha cutoff.
Definition Material.h:330
bool getReceiveShadow() const
Returns the receive shadow.
Definition Material.h:284
float getAlbedoUvScaleU() const
Current base-color UV scale U.
Definition Material.h:154
void setCameraFacing(bool enabled)
Keep a bottom-anchored card facing the active camera around world Y during GPU-driven draws.
Definition Material.h:346
BlendMode blendMode() const
Blend mode.
Definition Material.h:336
int getSortPriority() const
Returns the sort priority.
Definition Material.h:352
bool getCameraFacing() const
Return whether GPU-driven card vertices use cylindrical camera-facing orientation.
Definition Material.h:348
MaterialVirtualTextureMode virtualTextureMode() const
Return the active virtual-texture sampling mode.
Definition Material.h:218
float getTintA() const
Returns the tint a.
Definition Material.h:241
bool getCastOcclusion() const
Returns the cast occlusion.
Definition Material.h:289
bool getDoubleSided() const
Returns the double sided.
Definition Material.h:344
void setReceiveLight(bool receive)
Sets the receive light.
Definition Material.h:272
bool getDepthWrite() const
Returns the depth write.
Definition Material.h:340
Shader * getShader() const
Return the borrowed shader, or nullptr when the built-in path is active. @lifetime The pointer remain...
Definition Material.h:230
void setDepthWrite(bool enabled)
Sets the depth write.
Definition Material.h:338
std::string getShadingModel() const
Returns the shading model.
Definition Material.h:53
float getTintB() const
Returns the tint b.
Definition Material.h:239
float getAlbedoUvOffsetU() const
Current base-color UV offset U.
Definition Material.h:141
Material(const Material &)=delete
bool getCastShadow() const
Returns the cast shadow.
Definition Material.h:279
float getAlbedoUvRotation() const
Current base-color UV rotation in radians.
Definition Material.h:166
float getTintG() const
Returns the tint g.
Definition Material.h:237
bool getReceiveLight() const
Returns the receive light.
Definition Material.h:274
float getParallaxMaxLayers() const
Returns the parallax max layers.
Definition Material.h:269
SurfaceMode surfaceMode() const
Surface mode.
Definition Material.h:326
float getAlbedoUvScaleV() const
Current base-color UV scale V.
Definition Material.h:156
void setSortPriority(int priority)
Sets the sort priority.
Definition Material.h:350
Texture * getHeightTexture() const
Returns the height texture.
Definition Material.h:182
void setShader(Shader *shader)
Set an optional Mesh3D / hair shader; nullptr selects the built-in shading path.
Definition Material.h:227
void setDoubleSided(bool enabled)
Sets the double sided.
Definition Material.h:342
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:26
Custom GPU program.
Definition Shader.h:41
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
卡牌游戏 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:24
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:404
int sortPriority
Optional per-instance transparent ordering override.
Definition Material.h:409
Owning material parameter snapshot; texture pointers remain borrowed. Base color/metallic/roughness c...
Definition PbrSurface.h:240
One immutable source layer copied into a VirtualTextureBlend.
Runtime streaming budgets over a VirtualTextureBlend producer.
glm::vec4 ambient