I’m building a video game engine using C++ as the coding language and Vulkan for graphics. I am trying to set up a generic renderer using Vulkan that is flexible and will render objects based on a vector that is supplied to it. The renderer will also handle the creation of the window using GLFW and use GLM for all relevant math calls. I am using the ASSIMP library to load 3d models and animations.
void Initialize();
void MainLoop();
void Update(float deltaTime);
void Render();
Window window;
Renderer renderer;
Scene scene;
std::vector<std::unique_ptr<Mesh>> meshes; // Unique pointer vector to store Mesh objects
std::vector<std::unique_ptr<Material>> materials; // Unique pointer vector to store Material objects
std::vector<GameObject> gameObjects; // Game object vector
vk::UniqueDescriptorPool descriptorPool;
bool pauseRender;
};
Material.h:
#pragma once
#include <vulkan/vulkan.hpp>
#include "Texture.h"
#include <glm/glm.hpp>
#include "Shader.h"
#include
#include // Don’t forget to include
#include
#include
class Material {
public:
Material();
~Material();
code
Assistant
It is possible to split the model, view, and position matrices into separate uniform buffers for added flexibility. This approach can be useful in scenarios where you want to update specific matrices independently without affecting others, or if you want to reuse or update certain matrices more frequently than others.
By separating the matrices into individual buffers, you can update only the specific buffer that needs to be changed, rather than updating the entire buffer containing all matrices. This can potentially improve performance by reducing unnecessary updates.
Currently the rendering pipeline will pass the model, view and position matrices to the shader using a single uniform buffer. For added flexibility, would it make sense to split this into three separate buffers that can all then be stored and updated individually?
Here are some steps you can follow to implement this approach:
Create separate uniform buffers for each matrix: Create separate VkBuffers for the model, view, and position matrices. You can use the same memory properties and allocation logic as the current uniform buffer.
Update each buffer individually: Update each buffer separately whenever the corresponding matrix changes. For example, if the model matrix changes, update the model matrix buffer. Use appropriate Vulkan functions, such as vkMapMemory and vkUnmapMemory, to update the buffer data.
Update descriptor sets: When updating the descriptor sets, bind the appropriate buffer to the corresponding descriptor binding. Modify the buffer bindings in the descriptor set write operation to reflect the new buffer bindings.
Update shaders: In the shaders, define separate descriptor bindings for the model, view, and position matrices. Update the shader code to use the correct descriptor binding when accessing each matrix data.
Update pipeline layout: Modify the pipeline layout to reflect the changes in descriptor set and shader bindings. Ensure that the pipeline layout matches the updated descriptor sets and shader code.
By splitting the matrices into separate uniform buffers, you can update and manage the matrices individually, providing more flexibility in your rendering pipeline. However, keep in mind that this approach may introduce additional complexity and overhead, so make sure to consider the specific requirements and performance trade-offs of your application.