I’m new to Vulkan coding, and worked through the Vulkan Example web site. Using that code as a base, I added an instance buffer which holds a vec3. The position data was mapped to the fragment shader and then I used VkCmdDrawIndexed
to successfully draw a set of identical objects to the screen. In the fragment shader I had:
layout(location = 0) in vec3 inPosition;
layout(location = 4) in vec3 instancePos;
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition + instancePos, 1.0);
and the VkCmdDrawIndexed
command:
vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(indices.size()), 27, 0, 0, 0);
This works fine, and as expected I had 27 identical objects in a 3 x 3 x 3 cube. I’m now trying to extend things by rendering multiple non-identical objects but I can only ever see the first object on screen. I have followed tips from this post but still only see the first object in the perMeshData
array. The title of the post in the Khronos forums is ‘Render multiple meshes with one VBO’:
My drawing command looks like this:
for(auto m : perMeshData){
vkCmdDrawIndexed(commandBuffers[i], m.numIndices, 1, m.startIndex, m.startVertIndex, m.startInstance);
}
Logging what is passed to vkCmdDrawIndexed
when drawing a cube and mesh I can see:
vKCmdDrawIndexed = CB 36 1 0 0 0
vKCmdDrawIndexed = CB 6 1 36 24 1
But only the first object (cube) is rendered. I’ve checked what is in the vertex, index and instance arrays and it looks like legitimate data. Likewise, the logged for vkCmdDrawIndexed
looks sane I think. If I swap objects around in the perMeshData
array, I always only see the first object. As with the instanced example, I am passing a position vector for each object to the shader in the instance buffer objects. Can anyone suggest why I’m not seeing multiple objects being rendered? I’m happy to paste more bits of code here, just ask.
Summary
This text will be hidden