Multiple Object Rendering in Vulkan

If you are learning directly Vulkan with less experience with other APIs or without any graphics APIs experience, it can be very complicated. And sometimes don’t seeing the ‘full picture’ of rendering with Vulkan, can cause headache even while adding simple features like multiple different object rendering with Vulkan(not instancing). I saw some people struggle with it, didn’t see any tutorial about it and decided to write something about it. In a very simple way.

  1. Descriptor Set Layout

Now, look carefully to the function parameters. I define two seperate descritptor set layouts, for each model. If your models share same shader bindings (in correct order), then you can use the same descriptor set layout, but if they differs, then you must use seperate descriptor set layout. Here’s the function code:

I’m using three uniform buffers in my shaders. One is for model-view-projection matrix in vertex shader, and the others is for fragment shader (albedo and normal maps).

Create different descriptor set layouts for each model.

2.Graphics Pipelines

I define two seperate graphics pipelines for each model.

You must create different graphics pipelines for each shader model. Creating the graphics pipeline for each model is the standart graphics pipeline creation procedure. Only things differs that, you pass different shader files and essentially, different descriptor set layouts which we talked about, above. According to descriptor set layout information, we can create pipeline for according shader models.

That’s it in here. We’re creating to different graphics pipelines and pipeline layouts for each model.

Create different pipeline layouts and pipelines for each model.

3.Descriptor Pool

I create two different descriptor pools for each models. Here’s the function:

My shaders for each model, uses same uniform bindings, so I can create them with the same VkDescriptorPoolSize’s. Be careful on that. Create them according to your shader uniform bindings.

Create different descriptor pools for each model.

4.Descriptor Sets

Here, I create two different descriptor sets for each model. You can see from parameter names that, I pass uniform buffers for shader (uniform and 2 texture buffer->albedo and normal map) and descriptor pools.

Function:

Create different descriptor sets for each model.

5.Command Buffer

After these, you can now render objects on the screen. In vkCmd functions, you just need only pass buffers (vertex, index buffers are seperate for each model) and Vulkan objects which you created seperately for each model.

--

--

--

Graphics/Game Programmer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Promise.all() using Async/Await

eCommerce in 2022: Technologies, Pricing and Features All Sellers Need To Know About

How to host a static website for free

Tutorial: New React project with Uisum

Introducing Jockey.jl — A Pretty Rad New Notebook Editor

Let’s Clone the Google Fit App using React Native

Adding Audio to a HTML Webpage

Setting Up Your Environment For VM`s

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vasif Abdullayev

Vasif Abdullayev

Graphics/Game Programmer

More from Medium

Adding an executable target to a Rust library

Processing with WT588D Audio Module

wt588d- audio module

Embedded GUI Development

Kotlin code sample using LVGL KT

An SFML Input Handler Using C++ Lambda Function