Refactoring

This commit is contained in:
mklefrancois 2021-09-07 09:42:21 +02:00
parent 3e399adf0a
commit d90ce79135
222 changed files with 9045 additions and 5734 deletions

View file

@ -24,6 +24,7 @@
#include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/memallocator_dma_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp"
#include "shaders/host_device.h"
// #VKRay
#include "nvvk/raytraceKHR_vk.hpp"
@ -45,7 +46,7 @@ public:
void loadModel(const std::string& filename, nvmath::mat4f transform = nvmath::mat4f(1));
void updateDescriptorSet();
void createUniformBuffer();
void createSceneDescriptionBuffer();
void createObjDescriptionBuffer();
void createTextureImages(const VkCommandBuffer& cmdBuf, const std::vector<std::string>& textures);
void updateUniformBuffer(const VkCommandBuffer& cmdBuf);
void onResize(int /*w*/, int /*h*/) override;
@ -63,35 +64,30 @@ public:
nvvk::Buffer matIndexBuffer; // Device buffer of array of 'Wavefront material'
};
// Instance of the OBJ
struct ObjInstance
{
nvmath::mat4f transform{1}; // Position of the instance
nvmath::mat4f transformIT{1}; // Inverse transpose
uint32_t objIndex{0}; // Reference to the `m_objModel`
uint32_t txtOffset{0}; // Offset in `m_textures`
VkDeviceAddress vertices{0};
VkDeviceAddress indices{0};
VkDeviceAddress materials{0};
VkDeviceAddress materialIndices{0};
nvmath::mat4f transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference
};
// Information pushed at each draw call
struct ObjPushConstant
{
nvmath::vec3f lightPosition{10.f, 15.f, 8.f};
float lightIntensity{100.f};
nvmath::vec3f lightDirection{-1, -1, -1};
float lightSpotCutoff{cos(deg2rad(12.5f))};
float lightSpotOuterCutoff{cos(deg2rad(17.5f))};
int instanceId{0}; // To retrieve the transformation matrix
int lightType{0}; // 0: point, 1: infinite
PushConstantRaster m_pcRaster{
{1}, // model identity
{10.f, 15.f, 8.f}, // lightPosition
{0}, // instanceId to retrieve the transformation matrix
{100.f}, // lightIntensity
{-1.f, -1.f, -1.f}, // lightDirection
{cos(deg2rad(12.5f))}, // lightSpotCutoff
{cos(deg2rad(17.5f))}, // lightSpotOuterCutoff
{0} // lightType 0: point, 1: infinite
};
ObjPushConstant m_pushConstant;
// Array of objects and instances in the scene
std::vector<ObjModel> m_objModel;
std::vector<ObjInstance> m_objInstance;
std::vector<ObjModel> m_objModel; // Model on host
std::vector<ObjDesc> m_objDesc; // Model description for device access
std::vector<ObjInstance> m_instances; // Scene model instances
// Graphic pipeline
VkPipelineLayout m_pipelineLayout;
@ -101,8 +97,8 @@ public:
VkDescriptorSetLayout m_descSetLayout;
VkDescriptorSet m_descSet;
nvvk::Buffer m_cameraMat; // Device-Host of the camera matrices
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
nvvk::Buffer m_bGlobals; // Device-Host of the camera matrices
nvvk::Buffer m_bObjDesc; // Device buffer of the OBJ descriptions
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
@ -111,7 +107,7 @@ public:
nvvk::DebugUtil m_debug; // Utility to name objects
// #Post
// #Post - Draw the rendered image on a quad using a tonemapper
void createOffscreenRender();
void createPostPipeline();
void createPostDescriptor();
@ -152,16 +148,7 @@ public:
VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline;
struct RtPushConstant
{
nvmath::vec4f clearColor;
nvmath::vec3f lightPosition;
float lightIntensity;
nvmath::vec3f lightDirection{-1, -1, -1};
float lightSpotCutoff{deg2rad(12.5f)};
float lightSpotOuterCutoff{deg2rad(17.5f)};
int lightType;
} m_rtPushConstants;
PushConstantRay m_pcRay{};
nvvk::SBTWrapper m_sbtWrapper;
};