Bulk update nvpro-samples 11/20/23
5c72ddfc0522eb6604828e74886cf39be646ba78
This commit is contained in:
parent
debd0d5e33
commit
0c73e8ec1b
96 changed files with 927 additions and 922 deletions
|
|
@ -142,8 +142,8 @@ The motion matrix must fill the structure [`VkAccelerationStructureMatrixMotionI
|
|||
objId = 0;
|
||||
{
|
||||
// Position of the instance at T0 and T1
|
||||
nvmath::mat4f matT0 = m_instances[0].transform;
|
||||
nvmath::mat4f matT1 = nvmath::translation_mat4(nvmath::vec3f(0.30f, 0.0f, 0.0f)) * matT0;
|
||||
glm::mat4 matT0 = m_instances[0].transform;
|
||||
glm::mat4 matT1 = glm::translate(glm::mat4(1),glm::vec3(0.30f, 0.0f, 0.0f)) * matT0;
|
||||
|
||||
VkAccelerationStructureMatrixMotionInstanceNV data;
|
||||
data.transformT0 = nvvk::toTransformMatrixKHR(matT0);
|
||||
|
|
@ -169,7 +169,7 @@ where it interpolates between two structures [`VkSRTDataNV`](https://www.khronos
|
|||
// Cube (moving/SRT rotation)
|
||||
objId = 0;
|
||||
{
|
||||
nvmath::quatf rot;
|
||||
glm::quatf rot;
|
||||
rot.from_euler_xyz({0, 0, 0});
|
||||
// Position of the instance at T0 and T1
|
||||
VkSRTDataNV matT0{}; // Translated to 0,0,2
|
||||
|
|
@ -182,7 +182,7 @@ where it interpolates between two structures [`VkSRTDataNV`](https://www.khronos
|
|||
matT0.qz = rot.z;
|
||||
matT0.qw = rot.w;
|
||||
VkSRTDataNV matT1 = matT0; // Setting a rotation
|
||||
rot.from_euler_xyz({deg2rad(10.0f), deg2rad(30.0f), 0.0f});
|
||||
rot.from_euler_xyz({glm::radians(10.0f), glm::radians(30.0f), 0.0f});
|
||||
matT1.qx = rot.x;
|
||||
matT1.qy = rot.y;
|
||||
matT1.qz = rot.z;
|
||||
|
|
@ -213,7 +213,7 @@ First the plane is not moving at all
|
|||
// Plane (static)
|
||||
objId = 1;
|
||||
{
|
||||
nvmath::mat4f matT0 = m_instances[1].transform;
|
||||
glm::mat4 matT0 = m_instances[1].transform;
|
||||
|
||||
VkAccelerationStructureInstanceKHR data{};
|
||||
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance
|
||||
|
|
@ -235,7 +235,7 @@ Second the deformed cube is not moving, only its geometry. This was done when se
|
|||
// Cube+Cubemodif (static)
|
||||
objId = 2;
|
||||
{
|
||||
nvmath::mat4f matT0 = m_instances[2].transform;
|
||||
glm::mat4 matT0 = m_instances[2].transform;
|
||||
|
||||
VkAccelerationStructureInstanceKHR data{};
|
||||
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "obj_loader.h"
|
||||
|
|
@ -60,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
|
|||
const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
|
||||
GlobalUniforms hostUBO = {};
|
||||
const auto& view = CameraManip.getMatrix();
|
||||
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f);
|
||||
// proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
|
||||
glm::mat4 proj = glm::perspectiveRH_ZO(glm::radians(CameraManip.getFov()), aspectRatio, 0.1f, 1000.0f);
|
||||
proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
|
||||
|
||||
hostUBO.viewProj = proj * view;
|
||||
hostUBO.viewInverse = nvmath::invert(view);
|
||||
hostUBO.projInverse = nvmath::invert(proj);
|
||||
hostUBO.viewInverse = glm::inverse(view);
|
||||
hostUBO.projInverse = glm::inverse(proj);
|
||||
|
||||
// UBO on the device, and what stages access it.
|
||||
VkBuffer deviceUBO = m_bGlobals.buffer;
|
||||
|
|
@ -184,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
|
|||
//--------------------------------------------------------------------------------------------------
|
||||
// Loading the OBJ file and setting up all buffers
|
||||
//
|
||||
void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform)
|
||||
void HelloVulkan::loadModel(const std::string& filename, glm::mat4 transform)
|
||||
{
|
||||
LOGI("Loading File: %s \n", filename.c_str());
|
||||
ObjLoader loader;
|
||||
|
|
@ -193,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
|
|||
// Converting from Srgb to linear
|
||||
for(auto& m : loader.m_materials)
|
||||
{
|
||||
m.ambient = nvmath::pow(m.ambient, 2.2f);
|
||||
m.diffuse = nvmath::pow(m.diffuse, 2.2f);
|
||||
m.specular = nvmath::pow(m.specular, 2.2f);
|
||||
m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
|
||||
m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
|
||||
m.specular = glm::pow(m.specular, glm::vec3(2.2f));
|
||||
}
|
||||
|
||||
ObjModel model;
|
||||
|
|
@ -684,8 +685,8 @@ void HelloVulkan::createTopLevelAS()
|
|||
objId = 0;
|
||||
{
|
||||
// Position of the instance at T0 and T1
|
||||
nvmath::mat4f matT0 = m_instances[0].transform;
|
||||
nvmath::mat4f matT1 = nvmath::translation_mat4(nvmath::vec3f(0.30f, 0.0f, 0.0f)) * matT0;
|
||||
glm::mat4 matT0 = m_instances[0].transform;
|
||||
glm::mat4 matT1 = glm::translate(glm::mat4(1), glm::vec3(0.30f, 0.0f, 0.0f)) * matT0;
|
||||
|
||||
VkAccelerationStructureMatrixMotionInstanceNV data;
|
||||
data.transformT0 = nvvk::toTransformMatrixKHR(matT0);
|
||||
|
|
@ -705,24 +706,25 @@ void HelloVulkan::createTopLevelAS()
|
|||
objId = 0;
|
||||
{
|
||||
// m_instance[3].transform -> no matrix to SRT
|
||||
nvmath::quatf rot;
|
||||
rot.from_euler_xyz({0, 0, 0});
|
||||
glm::quat rot = {};
|
||||
|
||||
// Position of the instance at T0 and T1
|
||||
VkSRTDataNV matT0{}; // Translated to 0,0,2
|
||||
matT0.sx = 1.0f;
|
||||
matT0.sy = 1.0f;
|
||||
matT0.sz = 1.0f;
|
||||
matT0.tz = 2.0f;
|
||||
matT0.qx = rot.x;
|
||||
matT0.qy = rot.y;
|
||||
matT0.qz = rot.z;
|
||||
matT0.qw = rot.w;
|
||||
matT0.sx = 1.0f;
|
||||
matT0.sy = 1.0f;
|
||||
matT0.sz = 1.0f;
|
||||
matT0.tz = 2.0f;
|
||||
matT0.qx = rot.x;
|
||||
matT0.qy = rot.y;
|
||||
matT0.qz = rot.z;
|
||||
matT0.qw = rot.w;
|
||||
|
||||
VkSRTDataNV matT1 = matT0; // Setting a rotation
|
||||
rot.from_euler_xyz({deg2rad(10.0f), deg2rad(30.0f), 0.0f});
|
||||
matT1.qx = rot.x;
|
||||
matT1.qy = rot.y;
|
||||
matT1.qz = rot.z;
|
||||
matT1.qw = rot.w;
|
||||
rot = glm::quat(glm::vec3(glm::radians(10.0f), glm::radians(30.0f), 0.0f));
|
||||
matT1.qx = rot.x;
|
||||
matT1.qy = rot.y;
|
||||
matT1.qz = rot.z;
|
||||
matT1.qw = rot.w;
|
||||
|
||||
VkAccelerationStructureSRTMotionInstanceNV data{};
|
||||
data.transformT0 = matT0;
|
||||
|
|
@ -741,7 +743,7 @@ void HelloVulkan::createTopLevelAS()
|
|||
// Plane (static)
|
||||
objId = 1;
|
||||
{
|
||||
nvmath::mat4f matT0 = m_instances[1].transform;
|
||||
glm::mat4 matT0 = m_instances[1].transform;
|
||||
|
||||
VkAccelerationStructureInstanceKHR data{};
|
||||
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance
|
||||
|
|
@ -760,7 +762,7 @@ void HelloVulkan::createTopLevelAS()
|
|||
// Cube+Cubemodif (static)
|
||||
objId = 2;
|
||||
{
|
||||
nvmath::mat4f matT0 = m_instances[2].transform;
|
||||
glm::mat4 matT0 = m_instances[2].transform;
|
||||
|
||||
VkAccelerationStructureInstanceKHR data{};
|
||||
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance
|
||||
|
|
@ -800,7 +802,7 @@ void HelloVulkan::createRtDescriptorSet()
|
|||
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet);
|
||||
|
||||
|
||||
VkAccelerationStructureKHR tlas = m_rtBuilder.getAccelerationStructure();
|
||||
VkAccelerationStructureKHR tlas = m_rtBuilder.getAccelerationStructure();
|
||||
VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
|
||||
descASInfo.accelerationStructureCount = 1;
|
||||
descASInfo.pAccelerationStructures = &tlas;
|
||||
|
|
@ -958,7 +960,7 @@ void HelloVulkan::createRtShaderBindingTable()
|
|||
// Fetch all the shader handles used in the pipeline. This is opaque data,/ so we store it in a vector of bytes.
|
||||
// The order of handles follow the stage entry.
|
||||
std::vector<uint8_t> shaderHandleStorage(sbtSize);
|
||||
auto result = vkGetRayTracingShaderGroupHandlesKHR(m_device, m_rtPipeline, 0, groupCount, sbtSize, shaderHandleStorage.data());
|
||||
auto result = vkGetRayTracingShaderGroupHandlesKHR(m_device, m_rtPipeline, 0, groupCount, sbtSize, shaderHandleStorage.data());
|
||||
|
||||
assert(result == VK_SUCCESS);
|
||||
|
||||
|
|
@ -984,7 +986,7 @@ void HelloVulkan::createRtShaderBindingTable()
|
|||
//--------------------------------------------------------------------------------------------------
|
||||
// Ray Tracing the scene
|
||||
//
|
||||
void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor)
|
||||
void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor)
|
||||
{
|
||||
updateFrame();
|
||||
if(m_pcRay.frame >= m_maxFrames)
|
||||
|
|
@ -1032,13 +1034,13 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
|
|||
//
|
||||
void HelloVulkan::updateFrame()
|
||||
{
|
||||
static nvmath::mat4f refCamMatrix;
|
||||
static float refFov{CameraManip.getFov()};
|
||||
static glm::mat4 refCamMatrix;
|
||||
static float refFov{CameraManip.getFov()};
|
||||
|
||||
const auto& m = CameraManip.getMatrix();
|
||||
const auto fov = CameraManip.getFov();
|
||||
|
||||
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov)
|
||||
if(refCamMatrix != m || refFov != fov)
|
||||
{
|
||||
resetFrame();
|
||||
refCamMatrix = m;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public:
|
|||
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
|
||||
void createDescriptorSetLayout();
|
||||
void createGraphicsPipeline();
|
||||
void loadModel(const std::string& filename, nvmath::mat4f transform = nvmath::mat4f(1));
|
||||
void loadModel(const std::string& filename, glm::mat4 transform = glm::mat4(1));
|
||||
void updateDescriptorSet();
|
||||
void createUniformBuffer();
|
||||
void createObjDescriptionBuffer();
|
||||
|
|
@ -66,18 +66,18 @@ public:
|
|||
// Instance of the OBJ
|
||||
struct ObjInstance
|
||||
{
|
||||
nvmath::mat4f transform; // Matrix of the instance
|
||||
uint32_t objIndex{0}; // Model index reference
|
||||
glm::mat4 transform; // Matrix of the instance
|
||||
uint32_t objIndex{0}; // Model index reference
|
||||
};
|
||||
|
||||
|
||||
// Information pushed at each draw call
|
||||
PushConstantRaster m_pcRaster{
|
||||
{1}, // Identity matrix
|
||||
{9.5f, 5.5f, -6.5f}, // light position
|
||||
0, // instance Id
|
||||
100.f, // light intensity
|
||||
0 // light type
|
||||
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, // Identity matrix
|
||||
{9.5f, 5.5f, -6.5f}, // light position
|
||||
0, // instance Id
|
||||
100.f, // light intensity
|
||||
0 // light type
|
||||
};
|
||||
|
||||
// Array of objects and instances in the scene
|
||||
|
|
@ -133,17 +133,17 @@ public:
|
|||
void updateRtDescriptorSet();
|
||||
void createRtPipeline();
|
||||
void createRtShaderBindingTable();
|
||||
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor);
|
||||
void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
|
||||
void updateFrame();
|
||||
void resetFrame();
|
||||
|
||||
|
||||
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
|
||||
nvvk::RaytracingBuilderKHR m_rtBuilder;
|
||||
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
|
||||
VkDescriptorPool m_rtDescPool;
|
||||
VkDescriptorSetLayout m_rtDescSetLayout;
|
||||
VkDescriptorSet m_rtDescSet;
|
||||
nvvk::RaytracingBuilderKHR m_rtBuilder;
|
||||
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
|
||||
VkDescriptorPool m_rtDescPool;
|
||||
VkDescriptorSetLayout m_rtDescSetLayout;
|
||||
VkDescriptorSet m_rtDescSet;
|
||||
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
|
||||
VkPipelineLayout m_rtPipelineLayout;
|
||||
VkPipeline m_rtPipeline;
|
||||
|
|
|
|||
|
|
@ -183,10 +183,10 @@ int main(int argc, char** argv)
|
|||
helloVk.loadModel(nvh::findFile("media/scenes/cube_modif.obj", defaultSearchPaths, true));
|
||||
|
||||
// Set the positions of the instances and reuse the last instance (cube_modif) to use cube_multi instead
|
||||
helloVk.m_instances[1].transform = nvmath::translation_mat4(nvmath::vec3f(0, -1, 0));
|
||||
helloVk.m_instances[2].transform = nvmath::translation_mat4(nvmath::vec3f(2, 0, 2));
|
||||
helloVk.m_instances[1].transform = glm::translate(glm::mat4(1), glm::vec3(0, -1, 0));
|
||||
helloVk.m_instances[2].transform = glm::translate(glm::mat4(1), glm::vec3(2, 0, 2));
|
||||
helloVk.m_instances[3].objIndex = 0;
|
||||
helloVk.m_instances[3].transform = nvmath::translation_mat4(nvmath::vec3f(0, 0, 2)); // SRT - unused
|
||||
helloVk.m_instances[3].transform = glm::translate(glm::mat4(1), glm::vec3(0, 0, 2)); // SRT - unused
|
||||
|
||||
|
||||
helloVk.createOffscreenRender();
|
||||
|
|
@ -209,8 +209,8 @@ int main(int argc, char** argv)
|
|||
helloVk.updatePostDescriptorSet();
|
||||
|
||||
|
||||
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f);
|
||||
bool useRaytracer = true;
|
||||
glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
|
||||
bool useRaytracer = true;
|
||||
|
||||
|
||||
helloVk.setupGlfwCallbacks(window);
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@
|
|||
#define COMMON_HOST_DEVICE
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "nvmath/nvmath.h"
|
||||
#include <glm/glm.hpp>
|
||||
// GLSL Type
|
||||
using vec2 = nvmath::vec2f;
|
||||
using vec3 = nvmath::vec3f;
|
||||
using vec4 = nvmath::vec4f;
|
||||
using mat4 = nvmath::mat4f;
|
||||
using vec2 = glm::vec2;
|
||||
using vec3 = glm::vec3;
|
||||
using vec4 = glm::vec4;
|
||||
using mat4 = glm::mat4;
|
||||
using uint = unsigned int;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue