一:概述
到目前为止,我们已经将几何体投影到 3D 中,但它仍然是完全平面的。在本章中,我们将为位置添加一个 Z 坐标,为 3D 网格做好准备。我们将使用第三个坐标将一个正方形放置在另一个正方形上面,以了解几何体未按深度排序时出现的问题。
二:3D几何
更改顶点结构以便使用三维坐标表示位置,并更新相应 VkVertexInputAttributeDescription 中的格式:
struct Vertex {
glm::vec3 pos;
glm::vec3 color;
glm::vec2 texCoord;
...
static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions() {
std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions{};
attributeDescriptions[0].binding = 0;
attributeDescriptions[0].location = 0;
attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[0].offset = offsetof(Vertex, pos);
...
}
};
接下来,更新顶点着色器,以接受并转换三维坐标作为输入。之后不要忘记重新编译!
la