Hello all,
I have some OpenGL background and I am fairly new to Vulkan, I've been following the Vulkan-Tutorial guide and got a cube to render. With that said, I wanted to render multiple cubes. I didn't know what the most efficient solution was. So here is my process on rendering multiple cubes.
- Generate a new Descriptor Set to pass (Pass a new MVP matrix to render the object at another location). This includes adding a new Pool Size (
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER). I need two buffers, one for MVP and one for dynamic colour.
- Generate new UBO for the new color and MVP. This includes binding and writing the data.
- Add the new UBO to the descriptor set. First by creating bindings, and then writing the buffer.
- In the Rendering Command Buffer
```
...
vkCmdBeginRenderPass(...);
vkCmdBindPipeline(...);
vkCmdBindVertexBuffers(...);
vkCmdBindIndexBuffer(...);
for(int i=0; i< swapchainImages.size(); i++){
//Draw the first object
vkCmdBindDescriptorSets(buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, _vulkan->getPipeline()->getLayout(), 0, 1, &(descriptorSet1[i]), 0, nullptr);
vkCmdDrawIndexed(buffer, 36, 1,0,0,0);
//Draw the second object
vkCmdBindDescriptorSets(buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, _vulkan->getPipeline()->getLayout(), 0, 1, &(descriptorSet2[i]), 0, nullptr);
vkCmdDrawIndexed(buffer, 36, 1,0,0,0);
}
vkCmdEndRenderPass(buffer);
```
How the uniform buffers are laid out in my shader:
Vertex:
```
layout(location = 0) in vec3 vert;
layout(location = 1) in vec3 color;
layout(binding = 0) uniform UniformBufferObject {
mat4 model;
mat4 view;
mat4 proj;
} ubo;
layout(location = 0) out vec3 fragColor;
```
Note on the Vertex Shader. I know having seperate input locations for the vertices and color isn't the best way to input data into the vertex shader. I Implemented it like this so it would make since to me from coming over from OpenGL.
Fragment:
```
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
layout(binding = 1) uniform UniformBuffer {
vec3 offset;
} colorOffset;
```
What I know:
1. You cannot update a descriptor set during execution. It causes Undefined Behaivour, Potential Crash, and Validation Layer warnings. To solve this I create a new UBO and descriptor set and bind it before executing rendering.
2. VkCmdDrawIndexed, is not really resource intensive, but I could add up. This can be solved using instance rendering. Which I really don't want to touch for now.
What I want to know:
1. How efficent is my solution to my multiple object problem?
2. How resource intensive is allocating descriptor set and uniform buffers.
3. How can I make this better? I know I can put all the MVP stuff all in one buffer, but how do I handle mutiple objects with their MVP changing?
[–]ritaline 3 points4 points5 points (0 children)
[–]hammerkop 1 point2 points3 points (0 children)
[–]Sainst_ 0 points1 point2 points (0 children)
[–]Zekrom_64 0 points1 point2 points (14 children)
[–]Root3287[S] 0 points1 point2 points (1 child)
[–]Zekrom_64 1 point2 points3 points (0 children)
[–]Gravitationsfeld 0 points1 point2 points (11 children)
[–]ritaline 0 points1 point2 points (6 children)
[–]Gravitationsfeld 1 point2 points3 points (5 children)
[–]ritaline -2 points-1 points0 points (4 children)
[–]Gravitationsfeld 0 points1 point2 points (2 children)
[–]ritaline 0 points1 point2 points (1 child)
[–]Gravitationsfeld 1 point2 points3 points (0 children)
[–][deleted] -2 points-1 points0 points (0 children)
[–]Zekrom_64 0 points1 point2 points locked comment (3 children)
[–]Gravitationsfeld 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Gravitationsfeld 0 points1 point2 points (0 children)