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
|
|
@ -62,12 +62,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;
|
||||
|
|
@ -192,7 +192,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;
|
||||
|
|
@ -201,9 +201,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;
|
||||
|
|
@ -698,7 +698,7 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
|
|||
for(uint32_t i = 0; i < nbSpheres; i++)
|
||||
{
|
||||
Sphere s;
|
||||
s.center = nvmath::vec3f(xzd(gen), yd(gen), xzd(gen));
|
||||
s.center = glm::vec3(xzd(gen), yd(gen), xzd(gen));
|
||||
s.radius = radd(gen);
|
||||
m_spheres[i] = std::move(s);
|
||||
}
|
||||
|
|
@ -709,18 +709,18 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
|
|||
for(const auto& s : m_spheres)
|
||||
{
|
||||
Aabb aabb;
|
||||
aabb.minimum = s.center - nvmath::vec3f(s.radius);
|
||||
aabb.maximum = s.center + nvmath::vec3f(s.radius);
|
||||
aabb.minimum = s.center - glm::vec3(s.radius);
|
||||
aabb.maximum = s.center + glm::vec3(s.radius);
|
||||
aabbs.emplace_back(aabb);
|
||||
}
|
||||
|
||||
// Creating two materials
|
||||
MaterialObj mat;
|
||||
mat.diffuse = nvmath::vec3f(0, 1, 1);
|
||||
mat.diffuse = glm::vec3(0, 1, 1);
|
||||
std::vector<MaterialObj> materials;
|
||||
std::vector<int> matIdx(nbSpheres);
|
||||
materials.emplace_back(mat);
|
||||
mat.diffuse = nvmath::vec3f(1, 1, 0);
|
||||
mat.diffuse = glm::vec3(1, 1, 0);
|
||||
materials.emplace_back(mat);
|
||||
|
||||
// Assign a material to each sphere
|
||||
|
|
@ -735,8 +735,8 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
|
|||
auto cmdBuf = genCmdBuf.createCommandBuffer();
|
||||
m_spheresBuffer = m_alloc.createBuffer(cmdBuf, m_spheres, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
|
||||
m_spheresAabbBuffer = m_alloc.createBuffer(cmdBuf, aabbs,
|
||||
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
|
||||
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
|
||||
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
|
||||
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
|
||||
m_spheresMatIndexBuffer =
|
||||
m_alloc.createBuffer(cmdBuf, matIdx, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
|
||||
m_spheresMatColorBuffer =
|
||||
|
|
@ -812,7 +812,7 @@ void HelloVulkan::createTopLevelAS()
|
|||
// Add the blas containing all implicit objects
|
||||
{
|
||||
VkAccelerationStructureInstanceKHR rayInst{};
|
||||
rayInst.transform = nvvk::toTransformMatrixKHR(nvmath::mat4f(1)); // (identity)
|
||||
rayInst.transform = nvvk::toTransformMatrixKHR(glm::mat4(1)); // (identity)
|
||||
rayInst.instanceCustomIndex = nbObj; // nbObj == last object == implicit
|
||||
rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(m_objModel.size()));
|
||||
rayInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR;
|
||||
|
|
@ -846,7 +846,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;
|
||||
|
|
@ -1025,9 +1025,9 @@ void HelloVulkan::createRtShaderBindingTable()
|
|||
// Allocate a buffer for storing the SBT.
|
||||
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
|
||||
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
|
||||
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
|
||||
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
|
||||
|
||||
// Find the SBT addresses of each group
|
||||
|
|
@ -1069,7 +1069,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)
|
||||
{
|
||||
m_debug.beginLabel(cmdBuf, "Ray trace");
|
||||
// Initializing push constant values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue