dl
dl_vertex.h
浏览该文件的文档.
1
12#pragma once
13
14#ifndef DL_DISABLE_RENDER
15#include <vulkan/vulkan.h>
16#include "dl_type.h"
17
18namespace dl
19{
20
22struct Vertex
23{
30 static VkVertexInputBindingDescription getBindingDescription()
31 {
32 VkVertexInputBindingDescription bindingDescription{};
33 bindingDescription.binding = 0;
34 bindingDescription.stride = sizeof(Vertex);
35 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
36 return bindingDescription;
37 }
38 static std::array<VkVertexInputAttributeDescription, 6> getAttributeDescriptions()
39 {
40 std::array<VkVertexInputAttributeDescription, 6> attributeDescriptions{};
41 uint32_t i = 0;
42 attributeDescriptions[i].binding = 0;
43 attributeDescriptions[i].location = i;
44 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
45 attributeDescriptions[i].offset = offsetof(Vertex, _pos);
46 ++i;
47 attributeDescriptions[i].binding = 0;
48 attributeDescriptions[i].location = i;
49 attributeDescriptions[i].format = VK_FORMAT_R32G32_SFLOAT;
50 attributeDescriptions[i].offset = offsetof(Vertex, _uv0);
51 ++i;
52 attributeDescriptions[i].binding = 0;
53 attributeDescriptions[i].location = i;
54 attributeDescriptions[i].format = VK_FORMAT_R32G32_SFLOAT;
55 attributeDescriptions[i].offset = offsetof(Vertex, _uv1);
56 ++i;
57 attributeDescriptions[i].binding = 0;
58 attributeDescriptions[i].location = i;
59 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
60 attributeDescriptions[i].offset = offsetof(Vertex, _normal);
61 ++i;
62 attributeDescriptions[i].binding = 0;
63 attributeDescriptions[i].location = i;
64 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
65 attributeDescriptions[i].offset = offsetof(Vertex, _tangent);
66 ++i;
67 attributeDescriptions[i].binding = 0;
68 attributeDescriptions[i].location = i;
69 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
70 attributeDescriptions[i].offset = offsetof(Vertex, _color);
71 return attributeDescriptions;
72 }
73};
74
75constexpr size_t NUM_BONE = 4;
78{
85 std::array<uint32_t, NUM_BONE> _joint0;
87 static VkVertexInputBindingDescription getBindingDescription()
88 {
89 VkVertexInputBindingDescription bindingDescription{};
90 bindingDescription.binding = 0;
91 bindingDescription.stride = sizeof(VertexBone);
92 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
93 return bindingDescription;
94 }
95 static std::array<VkVertexInputAttributeDescription, 8> getAttributeDescriptions()
96 {
97 std::array<VkVertexInputAttributeDescription, 8> attributeDescriptions{};
98 uint32_t i = 0;
99 attributeDescriptions[i].binding = 0;
100 attributeDescriptions[i].location = i;
101 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
102 attributeDescriptions[i].offset = offsetof(VertexBone, _pos);
103 ++i;
104 attributeDescriptions[i].binding = 0;
105 attributeDescriptions[i].location = i;
106 attributeDescriptions[i].format = VK_FORMAT_R32G32_SFLOAT;
107 attributeDescriptions[i].offset = offsetof(VertexBone, _uv0);
108 ++i;
109 attributeDescriptions[i].binding = 0;
110 attributeDescriptions[i].location = i;
111 attributeDescriptions[i].format = VK_FORMAT_R32G32_SFLOAT;
112 attributeDescriptions[i].offset = offsetof(VertexBone, _uv1);
113 ++i;
114 attributeDescriptions[i].binding = 0;
115 attributeDescriptions[i].location = i;
116 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
117 attributeDescriptions[i].offset = offsetof(VertexBone, _normal);
118 ++i;
119 attributeDescriptions[i].binding = 0;
120 attributeDescriptions[i].location = i;
121 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
122 attributeDescriptions[i].offset = offsetof(VertexBone, _tangent);
123 ++i;
124 attributeDescriptions[i].binding = 0;
125 attributeDescriptions[i].location = i;
126 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
127 attributeDescriptions[i].offset = offsetof(VertexBone, _weight0);
128 ++i;
129 attributeDescriptions[i].binding = 0;
130 attributeDescriptions[i].location = i;
131 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_UINT;
132 attributeDescriptions[i].offset = offsetof(VertexBone, _joint0);
133 ++i;
134 attributeDescriptions[i].binding = 0;
135 attributeDescriptions[i].location = i;
136 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
137 attributeDescriptions[i].offset = offsetof(VertexBone, _color);
138
139 return attributeDescriptions;
140 }
141};
142
145{
149 static VkVertexInputBindingDescription getBindingDescription()
150 {
151 VkVertexInputBindingDescription bindingDescription{};
152 bindingDescription.binding = 0;
153 bindingDescription.stride = sizeof(Vertex2D);
154 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
155 return bindingDescription;
156 }
157 static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions()
158 {
159 std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions{};
160 attributeDescriptions[0].binding = 0;
161 attributeDescriptions[0].location = 0;
162 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
163 attributeDescriptions[0].offset = offsetof(Vertex2D, _pos);
164 attributeDescriptions[1].binding = 0;
165 attributeDescriptions[1].location = 1;
166 attributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
167 attributeDescriptions[1].offset = offsetof(Vertex2D, _color);
168 attributeDescriptions[2].binding = 0;
169 attributeDescriptions[2].location = 2;
170 attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
171 attributeDescriptions[2].offset = offsetof(Vertex2D, _uv);
172 return attributeDescriptions;
173 }
174};
175
178{
181 static VkVertexInputBindingDescription getBindingDescription()
182 {
183 VkVertexInputBindingDescription bindingDescription{};
184 bindingDescription.binding = 0;
185 bindingDescription.stride = sizeof(VertexGfx);
186 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
187 return bindingDescription;
188 }
189 static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions()
190 {
191 std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
192 attributeDescriptions[0].binding = 0;
193 attributeDescriptions[0].location = 0;
194 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
195 attributeDescriptions[0].offset = offsetof(VertexGfx, _pos);
196 attributeDescriptions[1].binding = 0;
197 attributeDescriptions[1].location = 1;
198 attributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
199 attributeDescriptions[1].offset = offsetof(VertexGfx, _color);
200 return attributeDescriptions;
201 }
202};
203
206{
208 static VkVertexInputBindingDescription getBindingDescription()
209 {
210 VkVertexInputBindingDescription bindingDescription{};
211 bindingDescription.binding = 0;
212 bindingDescription.stride = sizeof(VertexSkybox);
213 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
214 return bindingDescription;
215 }
216 static std::array<VkVertexInputAttributeDescription, 1> getAttributeDescriptions()
217 {
218 std::array<VkVertexInputAttributeDescription, 1> attributeDescriptions{};
219 attributeDescriptions[0].binding = 0;
220 attributeDescriptions[0].location = 0;
221 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
222 attributeDescriptions[0].offset = offsetof(VertexSkybox, _pos);
223 return attributeDescriptions;
224 }
225};
226
228struct alignas(16) Material
229{
230 Position4 _baseColorFactor; // 基础颜色系数
231 Position4 _emissiveFactor; // 自发光系数
232 // -1.无贴图 0.使用UV0 1.使用UV1
238
239 float _metallicFactor; // 金属度
240 float _roughnessFactor; // 粗糙度
241 float _alphaMask; // 透明度裁剪
242 float _alphaMaskCutoff; // 丢弃阈值
243 float _emissiveStrength;// 自发光强度
244 float _pad[2] = {};
245
246 bool operator==(const Material& b) const
247 {
248 static_assert(sizeof(Material) % 16 == 0);
249 return memcmp(this, &b, sizeof(Material)) == 0;
250 }
251};
252
253struct alignas(16) Light
254{
256 float _falloffStart; // 衰减起始 仅点光源、聚光灯
257 Position3 _direction; // 方向 仅平行光、聚光灯
258 float _falloffEnd; // 衰减结束 仅点光源、聚光灯
259 Position3 _position; // 位置 仅点光源、聚光灯
260 float _spotPower; // 聚光灯强度 仅聚光灯
261};
262
263struct alignas(16) UbPass
264{
265 float _exposure; // 曝光度
266 float _gamma; // gamma校正
267 float _prefilteredCubeMipLevels; // 预过滤的立方体贴图级数
268 float _scaleIBLAmbient; // ibl环境光系数
269 std::array<Position4, 9> _sh; // 球谐函数系数(环境光漫反射)
270 Position4 _cascadeSplits; // 级联阴影分段
272 std::array<Light, 16> _light;
273};
274
275}
276
277#endif
通用类型
Array< Float, 2 > Position2
constexpr size_t NUM_BONE
Array< Float, 3 > Position3
Array< Float, 4 > Position4
Array< float, 4 > Color
Position3 _position
Position3 _direction
float _falloffStart
Position3 _strength
材质(pbr 金属度/粗糙度)
Position4 _baseColorFactor
int _physicalDescriptorTextureSet
Position4 _emissiveFactor
bool operator==(const Material &b) const
std::array< Position4, 9 > _sh
std::array< Light, 16 > _light
float _prefilteredCubeMipLevels
float _scaleIBLAmbient
Position4 _cascadeSplits
static std::array< VkVertexInputAttributeDescription, 3 > getAttributeDescriptions()
static VkVertexInputBindingDescription getBindingDescription()
3d顶点(带骨骼)
std::array< uint32_t, NUM_BONE > _joint0
static std::array< VkVertexInputAttributeDescription, 8 > getAttributeDescriptions()
static VkVertexInputBindingDescription getBindingDescription()
static std::array< VkVertexInputAttributeDescription, 2 > getAttributeDescriptions()
static VkVertexInputBindingDescription getBindingDescription()
static VkVertexInputBindingDescription getBindingDescription()
Position3 _normal
Position3 _pos
Position2 _uv1
static std::array< VkVertexInputAttributeDescription, 6 > getAttributeDescriptions()
Position2 _uv0
Position4 _color
Position3 _tangent
static std::array< VkVertexInputAttributeDescription, 1 > getAttributeDescriptions()
static VkVertexInputBindingDescription getBindingDescription()