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
|
|
@ -66,12 +66,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;
|
||||
|
|
@ -199,7 +199,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;
|
||||
|
|
@ -208,9 +208,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;
|
||||
|
|
@ -466,7 +466,7 @@ void HelloVulkan::initRayTracing()
|
|||
//--------------------------------------------------------------------------------------------------
|
||||
// Ray trace 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_pcRaster.frame >= m_maxFrames)
|
||||
|
|
@ -481,13 +481,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;
|
||||
|
|
@ -502,7 +502,7 @@ void HelloVulkan::resetFrame()
|
|||
}
|
||||
|
||||
|
||||
void HelloVulkan::addImplSphere(nvmath::vec3f center, float radius, int matId)
|
||||
void HelloVulkan::addImplSphere(glm::vec3 center, float radius, int matId)
|
||||
{
|
||||
ObjImplicit impl;
|
||||
impl.minimum = center - radius;
|
||||
|
|
@ -512,7 +512,7 @@ void HelloVulkan::addImplSphere(nvmath::vec3f center, float radius, int matId)
|
|||
m_implObjects.objImpl.push_back(impl);
|
||||
}
|
||||
|
||||
void HelloVulkan::addImplCube(nvmath::vec3f minumum, nvmath::vec3f maximum, int matId)
|
||||
void HelloVulkan::addImplCube(glm::vec3 minumum, glm::vec3 maximum, int matId)
|
||||
{
|
||||
ObjImplicit impl;
|
||||
impl.minimum = minumum;
|
||||
|
|
@ -546,9 +546,9 @@ void HelloVulkan::createImplictBuffers()
|
|||
|
||||
auto cmdBuf = cmdGen.createCommandBuffer();
|
||||
m_implObjects.implBuf = m_alloc.createBuffer(cmdBuf, m_implObjects.objImpl,
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR
|
||||
| VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
|
||||
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR
|
||||
| VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
|
||||
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
|
||||
m_implObjects.implMatBuf = m_alloc.createBuffer(cmdBuf, m_implObjects.implMat,
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
|
||||
cmdGen.submitAndWait(cmdBuf);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,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();
|
||||
|
|
@ -79,14 +79,14 @@ public:
|
|||
|
||||
// Information pushed at each draw call
|
||||
PushConstantRaster m_pcRaster{
|
||||
{1}, // Identity matrix
|
||||
{10.f, 15.f, 8.f}, // light position
|
||||
0, // instance Id
|
||||
{-1.f, -1.f, -.4f}, // lightDirection;
|
||||
0.939692621f, // {cos(deg2rad(20.0f))}, // lightSpotCutoff;
|
||||
0.866025404f, // {cos(deg2rad(30.0f))}, // lightSpotOuterCutoff;
|
||||
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
|
||||
{10.f, 15.f, 8.f}, // light position
|
||||
0, // instance Id
|
||||
{-1.f, -1.f, -.4f}, // lightDirection;
|
||||
0.939692621f, // {cos(glm::radians(20.0f))}, // lightSpotCutoff;
|
||||
0.866025404f, // {cos(glm::radians(30.0f))}, // lightSpotOuterCutoff;
|
||||
100.f, // light intensity
|
||||
0 // light type
|
||||
};
|
||||
|
||||
// Array of objects and instances in the scene
|
||||
|
|
@ -125,13 +125,13 @@ public:
|
|||
Raytracer m_raytrace;
|
||||
|
||||
void initRayTracing();
|
||||
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor);
|
||||
void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
|
||||
|
||||
// Implicit
|
||||
ImplInst m_implObjects;
|
||||
|
||||
void addImplSphere(nvmath::vec3f center, float radius, int matId);
|
||||
void addImplCube(nvmath::vec3f minumum, nvmath::vec3f maximum, int matId);
|
||||
void addImplSphere(glm::vec3 center, float radius, int matId);
|
||||
void addImplCube(glm::vec3 minumum, glm::vec3 maximum, int matId);
|
||||
void addImplMaterial(const MaterialObj& mat);
|
||||
void createImplictBuffers();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -85,14 +85,14 @@ void renderUI(HelloVulkan& helloVk)
|
|||
}
|
||||
if(pc.lightType == 1)
|
||||
{
|
||||
float dCutoff = rad2deg(acos(pc.lightSpotCutoff));
|
||||
float dOutCutoff = rad2deg(acos(pc.lightSpotOuterCutoff));
|
||||
float dCutoff = glm::degrees(acos(pc.lightSpotCutoff));
|
||||
float dOutCutoff = glm::degrees(acos(pc.lightSpotOuterCutoff));
|
||||
changed |= ImGui::SliderFloat("Cutoff", &dCutoff, 0.f, 45.f);
|
||||
changed |= ImGui::SliderFloat("OutCutoff", &dOutCutoff, 0.f, 45.f);
|
||||
dCutoff = dCutoff > dOutCutoff ? dOutCutoff : dCutoff;
|
||||
|
||||
pc.lightSpotCutoff = cos(deg2rad(dCutoff));
|
||||
pc.lightSpotOuterCutoff = cos(deg2rad(dOutCutoff));
|
||||
pc.lightSpotCutoff = cos(glm::radians(dCutoff));
|
||||
pc.lightSpotOuterCutoff = cos(glm::radians(dOutCutoff));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ int main(int argc, char** argv)
|
|||
helloVk.loadModel(nvh::findFile("media/scenes/Medieval_building.obj", defaultSearchPaths, true));
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true));
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true),
|
||||
nvmath::scale_mat4(nvmath::vec3f(0.5f)) * nvmath::translation_mat4(nvmath::vec3f(0.0f, 0.0f, 6.0f)));
|
||||
glm::scale(glm::mat4(1.f), glm::vec3(0.5f)) * glm::translate(glm::mat4(1.f), glm::vec3(0.0f, 0.0f, 6.0f)));
|
||||
|
||||
std::random_device rd; // Will be used to obtain a seed for the random number engine
|
||||
std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
|
||||
|
|
@ -206,11 +206,11 @@ int main(int argc, char** argv)
|
|||
for(int n = 0; n < 50; ++n)
|
||||
{
|
||||
ObjInstance inst;
|
||||
inst.objIndex = wusonIndex;
|
||||
float scale = fabsf(disn(gen));
|
||||
nvmath::mat4f mat = nvmath::translation_mat4(nvmath::vec3f{dis(gen), 0.f, dis(gen) + 6});
|
||||
// mat = mat * nvmath::rotation_mat4_x(dis(gen));
|
||||
mat = mat * nvmath::scale_mat4(nvmath::vec3f(scale));
|
||||
inst.objIndex = wusonIndex;
|
||||
float scale = fabsf(disn(gen));
|
||||
glm::mat4 mat = glm::translate(glm::mat4(1), glm::vec3{dis(gen), 0.f, dis(gen) + 6});
|
||||
// mat = mat * glm::rotation_mat4_x(dis(gen));
|
||||
mat = glm::scale(mat, glm::vec3(scale));
|
||||
inst.transform = mat;
|
||||
|
||||
helloVk.m_instances.push_back(inst);
|
||||
|
|
@ -219,13 +219,13 @@ int main(int argc, char** argv)
|
|||
// Creation of implicit geometry
|
||||
MaterialObj mat;
|
||||
// Reflective
|
||||
mat.diffuse = nvmath::vec3f(0, 0, 0);
|
||||
mat.specular = nvmath::vec3f(1.f);
|
||||
mat.diffuse = glm::vec3(0, 0, 0);
|
||||
mat.specular = glm::vec3(1.f);
|
||||
mat.shininess = 0.0;
|
||||
mat.illum = 3;
|
||||
helloVk.addImplMaterial(mat);
|
||||
// Transparent
|
||||
mat.diffuse = nvmath::vec3f(0.4, 0.4, 1);
|
||||
mat.diffuse = glm::vec3(0.4, 0.4, 1);
|
||||
mat.illum = 4;
|
||||
mat.dissolve = 0.5;
|
||||
helloVk.addImplMaterial(mat);
|
||||
|
|
@ -249,8 +249,8 @@ int main(int argc, char** argv)
|
|||
helloVk.initRayTracing();
|
||||
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ struct ObjModel
|
|||
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -48,10 +48,10 @@ enum EObjType
|
|||
// One single implicit object
|
||||
struct ObjImplicit
|
||||
{
|
||||
nvmath::vec3f minimum{0, 0, 0}; // Aabb
|
||||
nvmath::vec3f maximum{0, 0, 0}; // Aabb
|
||||
int objType{0}; // 0: Sphere, 1: Cube
|
||||
int matId{0};
|
||||
glm::vec3 minimum{0, 0, 0}; // Aabb
|
||||
glm::vec3 maximum{0, 0, 0}; // Aabb
|
||||
int objType{0}; // 0: Sphere, 1: Cube
|
||||
int matId{0};
|
||||
};
|
||||
|
||||
// All implicit objects
|
||||
|
|
@ -62,5 +62,5 @@ struct ImplInst
|
|||
nvvk::Buffer implBuf; // Buffer of objects
|
||||
nvvk::Buffer implMatBuf; // Buffer of material
|
||||
int blasId{0};
|
||||
nvmath::mat4f transform{1};
|
||||
glm::mat4 transform{1};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ void Offscreen::createFramebuffer(const VkExtent2D& size)
|
|||
// Creating the depth buffer
|
||||
{
|
||||
auto depthCreateInfo = nvvk::makeImage2DCreateInfo(size, m_depthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
|
||||
nvvk::Image image = m_alloc->createImage(depthCreateInfo);
|
||||
nvvk::Image image = m_alloc->createImage(depthCreateInfo);
|
||||
|
||||
VkImageViewCreateInfo depthStencilView{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
|
||||
depthStencilView.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
|
|
|
|||
|
|
@ -180,8 +180,8 @@ void Raytracer::createTopLevelAS(std::vector<ObjInstance>& instances, ImplInst&
|
|||
rayInst.transform = nvvk::toTransformMatrixKHR(implicitObj.transform); // Position of the instance
|
||||
rayInst.instanceCustomIndex = instances[nbObj].objIndex;
|
||||
rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(implicitObj.blasId));
|
||||
rayInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR;
|
||||
rayInst.mask = 0xFF; // Only be hit if rayMask & instance.mask != 0
|
||||
rayInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR;
|
||||
rayInst.mask = 0xFF; // Only be hit if rayMask & instance.mask != 0
|
||||
rayInst.instanceShaderBindingTableRecordOffset = 1; // We will use the same hit group for all objects (the second one)
|
||||
tlas.emplace_back(rayInst);
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ void Raytracer::createRtDescriptorSet(const VkImageView& outputImage)
|
|||
allocateInfo.pSetLayouts = &m_rtDescSetLayout;
|
||||
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;
|
||||
|
|
@ -405,7 +405,7 @@ void Raytracer::createRtPipeline(VkDescriptorSetLayout& sceneDescLayout)
|
|||
// Ray Tracing the scene
|
||||
//
|
||||
void Raytracer::raytrace(const VkCommandBuffer& cmdBuf,
|
||||
const nvmath::vec4f& clearColor,
|
||||
const glm::vec4& clearColor,
|
||||
VkDescriptorSet& sceneDescSet,
|
||||
VkExtent2D& size,
|
||||
PushConstantRaster& sceneConstants)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "nvmath/nvmath.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include "nvvk/descriptorsets_vk.hpp"
|
||||
#include "nvvk/raytraceKHR_vk.hpp"
|
||||
#include "nvvk/sbtwrapper_vk.hpp"
|
||||
|
|
@ -39,11 +39,7 @@ public:
|
|||
void createRtDescriptorSet(const VkImageView& outputImage);
|
||||
void updateRtDescriptorSet(const VkImageView& outputImage);
|
||||
void createRtPipeline(VkDescriptorSetLayout& sceneDescLayout);
|
||||
void raytrace(const VkCommandBuffer& cmdBuf,
|
||||
const nvmath::vec4f& clearColor,
|
||||
VkDescriptorSet& sceneDescSet,
|
||||
VkExtent2D& size,
|
||||
PushConstantRaster& sceneConstants);
|
||||
void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor, VkDescriptorSet& sceneDescSet, VkExtent2D& size, PushConstantRaster& sceneConstants);
|
||||
|
||||
private:
|
||||
nvvk::ResourceAllocator* m_alloc{nullptr}; // Allocator for buffer, images, acceleration structures
|
||||
|
|
@ -54,11 +50,11 @@ private:
|
|||
nvvk::SBTWrapper m_sbtWrapper;
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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