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{
28 static VkVertexInputBindingDescription getBindingDescription()
29 {
30 VkVertexInputBindingDescription bindingDescription{};
31 bindingDescription.binding = 0;
32 bindingDescription.stride = sizeof(Vertex);
33 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
34 return bindingDescription;
35 }
36 static std::array<VkVertexInputAttributeDescription, 4> getAttributeDescriptions()
37 {
38 std::array<VkVertexInputAttributeDescription, 4> attributeDescriptions{};
39 uint32_t i = 0;
40 attributeDescriptions[i].binding = 0;
41 attributeDescriptions[i].location = i;
42 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
43 attributeDescriptions[i].offset = offsetof(Vertex, _pos);
44 ++i;
45 attributeDescriptions[i].binding = 0;
46 attributeDescriptions[i].location = i;
47 attributeDescriptions[i].format = VK_FORMAT_R32G32_SFLOAT;
48 attributeDescriptions[i].offset = offsetof(Vertex, _uv);
49 ++i;
50 attributeDescriptions[i].binding = 0;
51 attributeDescriptions[i].location = i;
52 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
53 attributeDescriptions[i].offset = offsetof(Vertex, _normal);
54 ++i;
55 attributeDescriptions[i].binding = 0;
56 attributeDescriptions[i].location = i;
57 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
58 attributeDescriptions[i].offset = offsetof(Vertex, _tangent);
59 return attributeDescriptions;
60 }
61};
62
63constexpr size_t NUM_BONE = 4;
66{
73 std::array<uint32_t, NUM_BONE> _joint0;
75 static VkVertexInputBindingDescription getBindingDescription()
76 {
77 VkVertexInputBindingDescription bindingDescription{};
78 bindingDescription.binding = 0;
79 bindingDescription.stride = sizeof(VertexBone);
80 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
81 return bindingDescription;
82 }
83 static std::array<VkVertexInputAttributeDescription, 8> getAttributeDescriptions()
84 {
85 std::array<VkVertexInputAttributeDescription, 8> attributeDescriptions{};
86 uint32_t i = 0;
87 attributeDescriptions[i].binding = 0;
88 attributeDescriptions[i].location = i;
89 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
90 attributeDescriptions[i].offset = offsetof(VertexBone, _pos);
91 ++i;
92 attributeDescriptions[i].binding = 0;
93 attributeDescriptions[i].location = i;
94 attributeDescriptions[i].format = VK_FORMAT_R32G32_SFLOAT;
95 attributeDescriptions[i].offset = offsetof(VertexBone, _uv0);
96 ++i;
97 attributeDescriptions[i].binding = 0;
98 attributeDescriptions[i].location = i;
99 attributeDescriptions[i].format = VK_FORMAT_R32G32_SFLOAT;
100 attributeDescriptions[i].offset = offsetof(VertexBone, _uv1);
101 ++i;
102 attributeDescriptions[i].binding = 0;
103 attributeDescriptions[i].location = i;
104 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
105 attributeDescriptions[i].offset = offsetof(VertexBone, _normal);
106 ++i;
107 attributeDescriptions[i].binding = 0;
108 attributeDescriptions[i].location = i;
109 attributeDescriptions[i].format = VK_FORMAT_R32G32B32_SFLOAT;
110 attributeDescriptions[i].offset = offsetof(VertexBone, _tangent);
111 ++i;
112 attributeDescriptions[i].binding = 0;
113 attributeDescriptions[i].location = i;
114 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
115 attributeDescriptions[i].offset = offsetof(VertexBone, _weight0);
116 ++i;
117 attributeDescriptions[i].binding = 0;
118 attributeDescriptions[i].location = i;
119 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_UINT;
120 attributeDescriptions[i].offset = offsetof(VertexBone, _joint0);
121 ++i;
122 attributeDescriptions[i].binding = 0;
123 attributeDescriptions[i].location = i;
124 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
125 attributeDescriptions[i].offset = offsetof(VertexBone, _color);
126
127 return attributeDescriptions;
128 }
129};
130
133{
135 Position3 _fresnelR0; //菲涅耳系数
136 float _roughness; //粗糙度
137
138 bool operator==(const Material& b) const
139 {
140 return _roughness == b._roughness
141 && _fresnelR0 == b._fresnelR0
143 }
144};
145
146
149{
153 static VkVertexInputBindingDescription getBindingDescription()
154 {
155 VkVertexInputBindingDescription bindingDescription{};
156 bindingDescription.binding = 0;
157 bindingDescription.stride = sizeof(Vertex2D);
158 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
159 return bindingDescription;
160 }
161 static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions()
162 {
163 std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions{};
164 attributeDescriptions[0].binding = 0;
165 attributeDescriptions[0].location = 0;
166 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
167 attributeDescriptions[0].offset = offsetof(Vertex2D, _pos);
168 attributeDescriptions[1].binding = 0;
169 attributeDescriptions[1].location = 1;
170 attributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
171 attributeDescriptions[1].offset = offsetof(Vertex2D, _color);
172 attributeDescriptions[2].binding = 0;
173 attributeDescriptions[2].location = 2;
174 attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
175 attributeDescriptions[2].offset = offsetof(Vertex2D, _uv);
176 return attributeDescriptions;
177 }
178};
179
182{
185 static VkVertexInputBindingDescription getBindingDescription()
186 {
187 VkVertexInputBindingDescription bindingDescription{};
188 bindingDescription.binding = 0;
189 bindingDescription.stride = sizeof(VertexGfx);
190 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
191 return bindingDescription;
192 }
193 static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions()
194 {
195 std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
196 attributeDescriptions[0].binding = 0;
197 attributeDescriptions[0].location = 0;
198 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
199 attributeDescriptions[0].offset = offsetof(VertexGfx, _pos);
200 attributeDescriptions[1].binding = 0;
201 attributeDescriptions[1].location = 1;
202 attributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
203 attributeDescriptions[1].offset = offsetof(VertexGfx, _color);
204 return attributeDescriptions;
205 }
206};
207
208}
209
210#endif
通用类型
std::array< Float, 3 > Position3
std::array< Float, 4 > Position4
constexpr size_t NUM_BONE
std::array< float, 4 > Color
std::array< Float, 2 > Position2
Position4 _diffuseAlbedo
Position3 _fresnelR0
bool operator==(const Material &b) const
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()
Position2 _uv
static VkVertexInputBindingDescription getBindingDescription()
Position3 _normal
Position3 _pos
static std::array< VkVertexInputAttributeDescription, 4 > getAttributeDescriptions()
Position3 _tangent