9#include "resource/resource.h"
10#include "resource/resource_handle.h"
12#include "resource/asset/texture_asset.h"
14#include "core/reflect.h"
16namespace Vkm::Engine {
25#define VKM_MATERIAL_MAPS(X) \
26 X(albedo, albedoTexture, ALBEDO, Base color (RGBA; A feeds AlphaMask / Transparent)) \
27 X(normal, normalTexture, NORMAL, Tangent-space normal map (RGB)) \
28 X(metallicRoughness, metallicRoughnessTexture, METALLIC_ROUGHNESS, Combined roughness (G) + metallic (B) in the glTF layout) \
29 X(metallic, metallicTexture, METALLIC, Separate metalness (R channel)) \
30 X(roughness, roughnessTexture, ROUGHNESS, Separate roughness (R channel)) \
31 X(ao, aoTexture, AO, Ambient occlusion (R channel)) \
32 X(aoMetallicRoughness, aoMetallicRoughnessTexture, AO_METALLIC_ROUGHNESS, Combined AO (R) + roughness (G) + metallic (B)) \
33 X(emission, emissionTexture, EMISSION, Emission (RGB)) \
34 X(height, heightTexture, HEIGHT, Height field for parallax (R channel, white is high)) \
35 X(clearcoat, clearcoatTexture, CLEARCOAT, Clearcoat strength mask (R channel)) \
36 X(transmission, transmissionTexture, TRANSMISSION, Transmission mask (R channel))
43#define VKM_MATERIAL_MAP_COUNT(key, member, slot, doc) +1
44inline constexpr std::size_t MATERIAL_MAP_COUNT = 0 VKM_MATERIAL_MAPS(VKM_MATERIAL_MAP_COUNT);
45#undef VKM_MATERIAL_MAP_COUNT
54enum class MaterialType : uint8_t {
75 MaterialType type = MaterialType::Opaque;
126 glm::vec2 uvOffset = {0.0f, 0.0f};
140#define VKM_MATERIAL_MAP_MEMBER(key, member, slot, doc) TextureHandle member;
141 VKM_MATERIAL_MAPS(VKM_MATERIAL_MAP_MEMBER)
142#undef VKM_MATERIAL_MAP_MEMBER
152 std::array<MaterialHandle, MAX_LAYERS>
layers{};
160 for (
const MaterialHandle& layer :
layers) {
161 if (layer)
return true;
169VKM_ENUM_NAMES(::Vkm::Engine::MaterialType,
"Opaque",
"Transparent",
"Unlit",
"AlphaMask")
172VKM_REFLECT_BEGIN(::Vkm::Engine::MaterialAsset)
183 VKM_F(emissiveStrength)
185 VKM_F(clearcoatRoughness)
187 VKM_F(anisotropyDirection)
189 VKM_F(sheenRoughness)
191 VKM_F(subsurfaceColor)
193 VKM_F(thicknessFactor)
194 VKM_F(attenuationDistance)
195 VKM_F(attenuationColor)
Opaque, type-safe handle for resources, distinguished by ResourceType.
Definition resource_handle.h:16
A complete PBR material.
Definition material_asset.h:71
float metallic
Definition material_asset.h:83
glm::vec3 attenuationColor
Transmittance after one attenuationDistance (white = no tint)
Definition material_asset.h:117
float heightScale
Parallax-occlusion depth scale (0: off; 0.02-0.1 typical)
Definition material_asset.h:120
bool doubleSided
Both faces drawn, a back face lit as its own (glTF doubleSided): cloth, leaves, cards.
Definition material_asset.h:79
glm::vec3 anisotropyDirection
Anisotropy direction (tangent space)
Definition material_asset.h:100
float normalScale
Normal map intensity (0: flat, 1: as authored, >1: exaggerated)
Definition material_asset.h:91
std::array< MaterialHandle, MAX_LAYERS > layers
Materials blended in its place, by layerWeights: what a terrain draws with.
Definition material_asset.h:152
glm::vec3 subsurfaceColor
Subsurface color tint.
Definition material_asset.h:106
float clearcoatRoughness
Clearcoat lobe roughness (0: smooth, 1: rough)
Definition material_asset.h:98
std::array< glm::vec2, MAX_LAYERS > layerTiling
Definition material_asset.h:156
glm::vec4 albedo
Base color (RGB) + opacity (A; Transparent type blends on it)
Definition material_asset.h:82
bool layered() const
Whether it blends layers, as a terrain's does.
Definition material_asset.h:159
static constexpr uint32_t MAX_LAYERS
The most materials a layered one blends (layers).
Definition material_asset.h:73
glm::vec3 sheenColor
Sheen tint, Charlie lobe (0 = disabled); cloth / velvet.
Definition material_asset.h:102
float ior
Definition material_asset.h:86
bool waves
Definition material_asset.h:138
glm::vec3 emission
Emissive color (RGB), linear.
Definition material_asset.h:93
float ao
Definition material_asset.h:89
float boxMapping
Definition material_asset.h:134
float thicknessFactor
Volume thickness in metres (0: thin-walled, no absorption)
Definition material_asset.h:113
float clearcoat
Clearcoat layer strength (0: none, 1: full); attenuates the base layer.
Definition material_asset.h:97
glm::vec2 uvScale
Definition material_asset.h:125
float transmission
Fraction of light refracted instead of diffused (0: opaque, 1: glass)
Definition material_asset.h:109
float roughness
Surface roughness (0: smooth, 1: rough); GGX alpha = roughness^2.
Definition material_asset.h:85
float sheenRoughness
Sheen lobe roughness.
Definition material_asset.h:103
float anisotropy
Anisotropy strength (0: isotropic, 1: fully anisotropic)
Definition material_asset.h:99
float emissiveStrength
HDR multiplier on emission.
Definition material_asset.h:94
float attenuationDistance
Path length at which radiance reaches attenuationColor (m)
Definition material_asset.h:115
TextureHandle layerWeights
Definition material_asset.h:153
float alphaCutoff
AlphaMask: discard below this albedo alpha (glTF default 0.5)
Definition material_asset.h:77
float subsurface
Subsurface scattering strength; skin / wax / leaves.
Definition material_asset.h:105