我試圖在幾何着色器中實現billboarded四邊形來渲染粒子效果。幾何着色器輸入是點(vec3),其輸出是具有位置和UV座標(vec3,vec2)的三角形條。我已經嘗試過兩種頂點輸入綁定的變體,但都不起作用。Vulkan:VkVertexInputBindingDescription總是與幾何着色器錯誤
如果我設置的頂點像這樣結合:
VkVertexInputBindingDescription binding_desc[2] = {};
binding_desc[0].binding = 0;
binding_desc[0].stride = sizeof(glm::vec3);
binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
binding_desc[1].binding = 1;
binding_desc[1].stride = sizeof(glm::vec2);
binding_desc[1].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
VkVertexInputAttributeDescription attribute_desc[2] = {};
attribute_desc[0].location = 0;
attribute_desc[0].binding = binding_desc[0].binding;
attribute_desc[0].format = VK_FORMAT_R32G32B32_SFLOAT;
attribute_desc[0].offset = offsetof(vert_shader_vertex, pos);
attribute_desc[1].location = 1;
attribute_desc[1].binding = binding_desc[1].binding;
attribute_desc[1].format = VK_FORMAT_R32G32_SFLOAT;
attribute_desc[1].offset = offsetof(vert_shader_vertex, uv);
主叫vkCmdDraw
當我得到以下錯誤:
ERROR [默認] DS:(OBJECT 0)(CODE 24)管道狀態對象 (0x3c)預計應通過vkCmdBindVertexBuffers設置此命令緩衝區的頂點綁定索引1 。這是因爲在 pVertexBindingDescriptions指數1 VkVertexInputBindingDescription結構有1
綁定值。但是,如果我將它設置成這樣:
VkVertexInputBindingDescription binding_desc[1] = {};
binding_desc[0].binding = 0;
binding_desc[0].stride = sizeof(glm::vec3);
binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
VkVertexInputAttributeDescription attribute_desc[1] = {};
attribute_desc[0].location = 0;
attribute_desc[0].binding = binding_desc[0].binding;
attribute_desc[0].format = VK_FORMAT_R32G32B32_SFLOAT;
attribute_desc[0].offset = offsetof(vert_shader_vertex, pos);
調用vkCreateGraphicsPipelines
,當我得到這個錯誤:
ERROR [默認] SC:(OBJECT 0)(CODE 3)頂點着色器消耗輸入 在位置1,但不提供
- 是否VkVertexInputBindingDescription描述輸入到幾何着色器或頂點着色器?
- 我是否需要「虛擬」UV座標在我的頂點緩衝區中作爲佔位符?
- 是否有可能我的幾何着色器未被激活,以及如何確認?
- 這兩種方法哪一種是正確的,我該如何解決相應的錯誤?
- 另外,我是Vulkan的新手,所以對着色器的評論值得歡迎。
幾何着色器
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (location = 0) in vec3 inPos[];
layout (location = 0) out vec3 outPos;
layout (location = 1) out vec2 outUV;
layout (push_constant) uniform constants_t {
vec3 up;
vec3 right;
mat4x4 world;
mat4x4 projection;
} constants;
void main(void)
{
const vec3 pos = gl_in[0].gl_Position.xyz;
const vec3 up = constants.up;
const vec3 right = constants.right;
outPos = pos + up - right;
outUV = vec2(0, 0);
EmitVertex();
outPos = pos + up + right;
outUV = vec2(1, 0);
EmitVertex();
outPos = pos - up - right;
outUV = vec2(0, 1);
EmitVertex();
outPos = pos - up + right;
outUV = vec2(1, 1);
EmitVertex();
EndPrimitive();
}
頂點着色器
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec2 inUV;
layout (location = 0) out vec4 outPos;
layout (location = 1) out vec2 outUV;
layout (push_constant) uniform constants_t {
vec3 up;
vec3 right;
mat4x4 world;
mat4x4 projection;
} constants;
void main(void) {
outUV = inUV;
outPos = vec4(inPos.xyz, 1.0) * constants.world * constants.projection;
}
vkCmdBindVertexBuffers
VkBuffer vertex_buffers[1] = {vertexBuffer};
VkDeviceSize vertex_offset[1] = {0};
vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertex_buffers, vertex_offset);
「*調用vkCmdDraw時出現以下錯誤:*」爲了說明發生了什麼,我們需要在渲染之前查看您發送的實際命令*。 –
我認爲vkCmdBindVertexBuffers對於第一個變體是非常重要的 –
@NicolBolas你真的嗎?我的文章包含相當一般的子彈尖端問題。此外,我沒有權限將所有代碼轉儲到某處供您查看。 – Brent