Rendering instanced geometry
A common task in 3D rendering is drawing multiple meshes that share the same geometry but have different transformations and materials. This can result in additional CPU overhead from generating commands for the GPU to draw each mesh individually, even though the Vulkan API already reduces CPU overhead significantly.
One solution to this issue, provided by modern graphics APIs like Vulkan, is instanced rendering. This approach allows API draw commands to include the number of instances as a parameter, while the vertex shader gains access to the current instance number via gl_InstanceIndex
. When combined with the PVP approach from the previous recipe, this technique becomes extremely flexible. The gl_InstanceIndex
can be used to fetch material properties, transformations, and other data directly from buffers.
Let’s explore a basic instanced geometry demo to learn how to implement this in Vulkan.
Getting ready
Be sure to review the...