vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
material_asset.h
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include <glm/glm.hpp>
7
8#include "resource/resource.h"
9#include "resource/resource_handle.h"
10
11#include "resource/asset/texture_asset.h"
12
13#include "core/reflect.h"
14
15namespace Vkm::Engine {
16
24#define VKM_MATERIAL_MAPS(X) \
25 X(albedo, albedoTexture, ALBEDO, Base color (RGBA; A feeds AlphaMask / Transparent)) \
26 X(normal, normalTexture, NORMAL, Tangent-space normal map (RGB)) \
27 X(metallicRoughness, metallicRoughnessTexture, METALLIC_ROUGHNESS, Combined roughness (G) + metallic (B) in the glTF layout) \
28 X(metallic, metallicTexture, METALLIC, Separate metalness (R channel)) \
29 X(roughness, roughnessTexture, ROUGHNESS, Separate roughness (R channel)) \
30 X(ao, aoTexture, AO, Ambient occlusion (R channel)) \
31 X(aoMetallicRoughness, aoMetallicRoughnessTexture, AO_METALLIC_ROUGHNESS, Combined AO (R) + roughness (G) + metallic (B)) \
32 X(emission, emissionTexture, EMISSION, Emission (RGB)) \
33 X(height, heightTexture, HEIGHT, Height field for parallax (R channel, white is high)) \
34 X(clearcoat, clearcoatTexture, CLEARCOAT, Clearcoat strength mask (R channel)) \
35 X(transmission, transmissionTexture, TRANSMISSION, Transmission mask (R channel))
36
42#define VKM_MATERIAL_MAP_COUNT(key, member, slot, doc) +1
43inline constexpr std::size_t MATERIAL_MAP_COUNT = 0 VKM_MATERIAL_MAPS(VKM_MATERIAL_MAP_COUNT);
44#undef VKM_MATERIAL_MAP_COUNT
45
53enum class MaterialType : uint8_t {
54 Opaque = 0,
55 Transparent = 1,
56 Unlit = 2,
57 AlphaMask = 3,
58 Count
59};
60
67struct MaterialAsset : public Resource {
68 MaterialType type = MaterialType::Opaque;
70 float alphaCutoff = 0.5f;
71
73 glm::vec4 albedo = {1,1,1,1};
74 float metallic = 0.0f;
76 float roughness = 0.5f;
77 float ior = 1.5f;
79 float ao = 1.0f;
81 float normalScale = 1.0f;
82
83 glm::vec3 emission = {0,0,0};
84 float emissiveStrength = 1.0f;
85
87 float clearcoat = 0.0f;
88 float clearcoatRoughness = 0.0f;
89 float anisotropy = 0.0f;
90 glm::vec3 anisotropyDirection = {1,0,0};
91
92 glm::vec3 sheenColor = {0,0,0};
93 float sheenRoughness = 0.3f;
94
95 float subsurface = 0.0f;
96 glm::vec3 subsurfaceColor = {1,1,1};
97
99 float transmission = 0.0f;
100 // KHR_materials_volume: transmittance = pow(attenuationColor, path / attenuationDistance),
101 // the path from thicknessFactor.
103 float thicknessFactor = 0.0f;
107 glm::vec3 attenuationColor = {1,1,1};
108
110 float heightScale = 0.0f;
111
112#define VKM_MATERIAL_MAP_MEMBER(key, member, slot, doc) TextureHandle member;
113 VKM_MATERIAL_MAPS(VKM_MATERIAL_MAP_MEMBER)
114#undef VKM_MATERIAL_MAP_MEMBER
115};
116
117using MaterialHandle = Handle<MaterialAsset>;
118
119} // namespace Vkm::Engine
120
121VKM_ENUM_NAMES(::Vkm::Engine::MaterialType, "Opaque", "Transparent", "Unlit", "AlphaMask")
122
123// Non-texture fields; texture handles serialize separately as name refs.
124VKM_REFLECT_BEGIN(::Vkm::Engine::MaterialAsset)
125 VKM_F(type)
126 VKM_F(alphaCutoff)
127 VKM_F(albedo)
128 VKM_F(metallic)
129 VKM_F(roughness)
130 VKM_F(ior)
131 VKM_F(ao)
132 VKM_F(normalScale)
133 VKM_F(emission)
134 VKM_F(emissiveStrength)
135 VKM_F(clearcoat)
136 VKM_F(clearcoatRoughness)
137 VKM_F(anisotropy)
138 VKM_F(anisotropyDirection)
139 VKM_F(sheenColor)
140 VKM_F(sheenRoughness)
141 VKM_F(subsurface)
142 VKM_F(subsurfaceColor)
143 VKM_F(transmission)
144 VKM_F(thicknessFactor)
145 VKM_F(attenuationDistance)
146 VKM_F(attenuationColor)
147 VKM_F(heightScale)
148VKM_REFLECT_END()
Opaque, type-safe handle for resources, distinguished by ResourceType.
Definition resource_handle.h:16
A complete PBR material.
Definition material_asset.h:67
float metallic
Definition material_asset.h:74
glm::vec3 attenuationColor
Transmittance after one attenuationDistance (white = no tint)
Definition material_asset.h:107
float heightScale
Parallax-occlusion depth scale (0: off; 0.02-0.1 typical)
Definition material_asset.h:110
glm::vec3 anisotropyDirection
Anisotropy direction (tangent space)
Definition material_asset.h:90
float normalScale
Normal map intensity (0: flat, 1: as authored, >1: exaggerated)
Definition material_asset.h:81
glm::vec3 subsurfaceColor
Subsurface color tint.
Definition material_asset.h:96
float clearcoatRoughness
Clearcoat lobe roughness (0: smooth, 1: rough)
Definition material_asset.h:88
glm::vec4 albedo
Base color (RGB) + opacity (A; Transparent type blends on it)
Definition material_asset.h:73
glm::vec3 sheenColor
Sheen tint, Charlie lobe (0 = disabled); cloth / velvet.
Definition material_asset.h:92
float ior
Definition material_asset.h:77
glm::vec3 emission
Emissive color (RGB), linear.
Definition material_asset.h:83
float ao
Ambient occlusion factor on indirect light (0: occluded, 1: open)
Definition material_asset.h:79
float thicknessFactor
Volume thickness in metres (0: thin-walled, no absorption)
Definition material_asset.h:103
float clearcoat
Clearcoat layer strength (0: none, 1: full); attenuates the base layer.
Definition material_asset.h:87
float transmission
Fraction of light refracted instead of diffused (0: opaque, 1: glass)
Definition material_asset.h:99
float roughness
Surface roughness (0: smooth, 1: rough); GGX alpha = roughness^2.
Definition material_asset.h:76
float sheenRoughness
Sheen lobe roughness.
Definition material_asset.h:93
float anisotropy
Anisotropy strength (0: isotropic, 1: fully anisotropic)
Definition material_asset.h:89
float emissiveStrength
HDR multiplier on emission.
Definition material_asset.h:84
float attenuationDistance
Path length at which radiance reaches attenuationColor (m)
Definition material_asset.h:105
float alphaCutoff
AlphaMask: discard below this albedo alpha (glTF default 0.5)
Definition material_asset.h:70
float subsurface
Subsurface scattering strength; skin / wax / leaves.
Definition material_asset.h:95