Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
MaterialData.h
1#pragma once
2#include <glm/vec3.hpp>
3#include <glm/vec4.hpp>
4#include <cstdint>
5
6#include "MaterialTypes.h"
7
8namespace Engine::Core
9{
22 struct MaterialData {
30
32 uint32_t baseColorTextureIndex = 0xFFFFFFFF;
34 uint32_t normalTextureIndex = 0xFFFFFFFF;
36 uint32_t roughnessMetallicTextureIndex = 0xFFFFFFFF;
38 uint32_t emissiveTextureIndex = 0xFFFFFFFF;
40 uint32_t lightmapTextureIndex = 0xFFFFFFFF;
41
42 glm::vec4 baseColorFactor = glm::vec4(1.0f);
43 glm::vec3 emissiveFactor = glm::vec3(0.0f);
45 float roughnessFactor = 1.0f;
47 float metallicFactor = 0.0f;
48 float normalScale = 1.0f;
49
50 float shScale = 1.0f;
51 float ambientTerm = 0.0f;
52 uint32_t debugMode = 0;
53 uint32_t toneMapping = 1;
54
55 bool normalMapBC5 = false;
56 float alphaCutoff = 1.0f;
57
61 MaterialData() = default;
62
68
76 MaterialData(Rendering::PipelineNames pipe, uint32_t baseColorTexIdx, const glm::vec4& baseColorFac)
77 : pipeline(pipe),
78 baseColorTextureIndex(baseColorTexIdx),
79 baseColorFactor(baseColorFac) {}
80
85 [[nodiscard]] bool hasBaseColorTexture() const { return baseColorTextureIndex != 0xFFFFFFFF; }
86
91 [[nodiscard]] bool hasNormalTexture() const { return normalTextureIndex != 0xFFFFFFFF; }
92
97 [[nodiscard]] bool hasMetallicRoughnessTexture() const { return roughnessMetallicTextureIndex != 0xFFFFFFFF; }
98
103 [[nodiscard]] bool hasEmissiveTexture() const { return emissiveTextureIndex != 0xFFFFFFFF; }
104
109 [[nodiscard]] bool hasLightmapTexture() const { return lightmapTextureIndex != 0xFFFFFFFF; }
110
115 [[nodiscard]] bool isAlphaMasked() const { return alphaCutoff < 1.0f; }
116
122 MaterialData& withBaseColorTexture(uint32_t idx) { baseColorTextureIndex = idx; return *this; }
123
129 MaterialData& withNormalTexture(uint32_t idx) { normalTextureIndex = idx; return *this; }
130
137
143 MaterialData& withEmissiveTexture(uint32_t idx) { emissiveTextureIndex = idx; return *this; }
144
150 MaterialData& withLightmapTexture(uint32_t idx) { lightmapTextureIndex = idx; return *this; }
151
157 MaterialData& withBaseColorFactor(const glm::vec4& fac) { baseColorFactor = fac; return *this; }
158
164 MaterialData& withEmissiveFactor(const glm::vec3& fac) { emissiveFactor = fac; return *this; }
165
171 MaterialData& withRoughness(float r) { roughnessFactor = r; return *this; }
172
178 MaterialData& withMetallic(float m) { metallicFactor = m; return *this; }
179
185 MaterialData& withNormalScale(float s) { normalScale = s; return *this; }
186
192 MaterialData& withShScale(float s) { shScale = s; return *this; }
193
199 MaterialData& withAmbientTerm(float a) { ambientTerm = a; return *this; }
200
206 MaterialData& withDebugMode(uint32_t d) { debugMode = d; return *this; }
207
213 MaterialData& withToneMapping(uint32_t t) { toneMapping = t; return *this; }
214
223 MaterialData& withAlphaCutoff(float cutoff) { alphaCutoff = cutoff; return *this; }
224
230 MaterialData& withNormalMapBC5(bool bc5) { normalMapBC5 = bc5; return *this; }
231
232 };
233
234} // namespace Engine::Core
235
Compatibility aliases for material data names used by older material code.
Engine::Core::MaterialData DiffuseFlatColorMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData L2ShaderMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData StaticLightmapMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData MovableDiffuseShaderMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData DynamicTexturesMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData MaterialData
Alias for the unified material data type.
Engine::Core::MaterialData DiffuseShaderMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData L1ShaderMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData NormalMaterialData
Alias for the unified material data type.
Engine::Core::MaterialData L0ShaderMaterialData
Alias for the unified material data type.
PipelineNames
Named graphics pipelines used by material selection and shader lookup.
@ NORMALS_SHADER
Debug pipeline that renders mesh normals.
CPU-side material description consumed by renderer material upload code.
uint32_t lightmapTextureIndex
Lightmap texture descriptor index, or 0xFFFFFFFF when absent.
MaterialData & withBaseColorTexture(uint32_t idx)
Sets the base-color texture descriptor index.
MaterialData()=default
Creates a material with default values and the normals debug pipeline.
float alphaCutoff
Alpha-mask discard threshold. Values below 1.0f mark the material as masked.
MaterialData & withDebugMode(uint32_t d)
Sets the material debug mode selector.
float metallicFactor
Scalar metallic value used when no metallic-roughness texture is present.
uint32_t debugMode
Material debug mode selector.
bool isAlphaMasked() const
Checks whether the material is configured for alpha masking.
MaterialData & withBaseColorFactor(const glm::vec4 &fac)
Sets the linear RGBA base-color multiplier.
MaterialData & withAmbientTerm(float a)
Sets the ambient lighting term.
float normalScale
Scale applied to sampled tangent-space normals.
bool hasNormalTexture() const
Checks whether a normal texture descriptor index is present.
Rendering::PipelineNames pipeline
Graphics pipeline used to interpret this material.
bool hasLightmapTexture() const
Checks whether a lightmap texture descriptor index is present.
uint32_t baseColorTextureIndex
Base-color texture descriptor index, or 0xFFFFFFFF when absent.
MaterialData & withEmissiveFactor(const glm::vec3 &fac)
Sets the linear RGB emissive multiplier.
uint32_t emissiveTextureIndex
Emissive texture descriptor index, or 0xFFFFFFFF when absent.
bool hasBaseColorTexture() const
Checks whether a base-color texture descriptor index is present.
float ambientTerm
Ambient lighting term mixed with probe or spherical harmonics lighting.
uint32_t toneMapping
Material tone-mapping mode: 0=None, 1=Reinhard, 2=ACES.
bool normalMapBC5
True when the normal map stores X and Y in BC5/RG format and reconstructs Z.
glm::vec4 baseColorFactor
Linear RGBA base-color multiplier.
MaterialData & withMetallicRoughnessTexture(uint32_t idx)
Sets the metallic-roughness texture descriptor index.
float roughnessFactor
Scalar roughness used when no metallic-roughness texture is present.
MaterialData & withNormalScale(float s)
Sets the normal map scale.
MaterialData & withEmissiveTexture(uint32_t idx)
Sets the emissive texture descriptor index.
MaterialData & withNormalTexture(uint32_t idx)
Sets the normal texture descriptor index.
MaterialData & withLightmapTexture(uint32_t idx)
Sets the lightmap texture descriptor index.
bool hasEmissiveTexture() const
Checks whether an emissive texture descriptor index is present.
MaterialData & withToneMapping(uint32_t t)
Sets the material tone-mapping mode.
MaterialData & withRoughness(float r)
Sets the scalar roughness value.
bool hasMetallicRoughnessTexture() const
Checks whether a metallic-roughness texture descriptor index is present.
uint32_t normalTextureIndex
Normal texture descriptor index, or 0xFFFFFFFF when absent.
MaterialData & withShScale(float s)
Sets the spherical harmonics lighting multiplier.
MaterialData & withAlphaCutoff(float cutoff)
Sets the alpha-mask cutoff threshold.
MaterialData(Rendering::PipelineNames pipe)
Creates a material for a specific pipeline.
MaterialData & withMetallic(float m)
Sets the scalar metallic value.
float shScale
Spherical harmonics lighting multiplier.
MaterialData(Rendering::PipelineNames pipe, uint32_t baseColorTexIdx, const glm::vec4 &baseColorFac)
Creates a material with a pipeline, base-color texture, and base-color factor.
uint32_t roughnessMetallicTextureIndex
Metallic-roughness texture descriptor index, or 0xFFFFFFFF when absent.
MaterialData & withNormalMapBC5(bool bc5)
Selects BC5/RG normal map decoding.