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
|
|
@ -22,10 +22,10 @@ and the acceleration structure does not deal with this well.
|
|||
|
||||
~~~~ C++
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths),
|
||||
nvmath::scale_mat4(nvmath::vec3f(2.f, 1.f, 2.f)));
|
||||
glm::scale(glm::mat4(1.f),glm::vec3(2.f, 1.f, 2.f)));
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths));
|
||||
uint32_t wusonId = 1;
|
||||
nvmath::mat4f identity{1};
|
||||
glm::mat4 identity{1};
|
||||
for(int i = 0; i < 20; i++)
|
||||
helloVk.m_instances.push_back({identity, wusonId});
|
||||
~~~~
|
||||
|
|
@ -57,8 +57,8 @@ void HelloVulkan::animationInstances(float time)
|
|||
{
|
||||
int wusonIdx = i + 1;
|
||||
auto& transform = m_instances[wusonIdx].transform;
|
||||
transform = nvmath::rotation_mat4_y(i * deltaAngle + offset)
|
||||
* nvmath::translation_mat4(radius, 0.f, 0.f);
|
||||
transform = glm::rotation_mat4_y(i * deltaAngle + offset)
|
||||
* glm::translate(glm::mat4(1),radius, 0.f, 0.f);
|
||||
}
|
||||
~~~~
|
||||
|
||||
|
|
@ -152,10 +152,10 @@ In this chapter, we will animate a sphere. In `main.cpp`, set up the scene like
|
|||
|
||||
~~~~ C++
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true),
|
||||
nvmath::scale_mat4(nvmath::vec3f(2.f, 1.f, 2.f)));
|
||||
glm::scale(glm::mat4(1.f),glm::vec3(2.f, 1.f, 2.f)));
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true));
|
||||
uint32_t wusonId = 1;
|
||||
nvmath::mat4f identity{1};
|
||||
glm::mat4 identity{1};
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
helloVk.m_instances.push_back({identity, wusonId});
|
||||
|
|
|
|||
|
|
@ -61,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;
|
||||
|
|
@ -185,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;
|
||||
|
|
@ -194,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;
|
||||
|
|
@ -708,7 +708,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;
|
||||
|
|
@ -844,7 +844,7 @@ void HelloVulkan::createRtPipeline()
|
|||
//--------------------------------------------------------------------------------------------------
|
||||
// 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
|
||||
|
|
@ -885,9 +885,10 @@ void HelloVulkan::animationInstances(float time)
|
|||
|
||||
for(int i = 0; i < nbWuson; i++)
|
||||
{
|
||||
int wusonIdx = i + 1;
|
||||
auto& transform = m_instances[wusonIdx].transform;
|
||||
transform = nvmath::rotation_mat4_y(i * deltaAngle + offset) * nvmath::translation_mat4(radius, 0.f, 0.f);
|
||||
int wusonIdx = i + 1;
|
||||
glm::mat4 transform = m_instances[wusonIdx].transform;
|
||||
transform = glm::rotate(transform, i * deltaAngle + offset, glm::vec3(0.f, 1.f, 0.f));
|
||||
transform = glm::translate(transform, glm::vec3(radius, 0.f, 0.f));
|
||||
|
||||
VkAccelerationStructureInstanceKHR& tinst = m_tlas[wusonIdx];
|
||||
tinst.transform = nvvk::toTransformMatrixKHR(transform);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,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:
|
|||
|
||||
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
|
||||
{10.f, 15.f, 8.f}, // 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
|
||||
{10.f, 15.f, 8.f}, // light position
|
||||
0, // instance Id
|
||||
100.f, // light intensity
|
||||
0 // light type
|
||||
};
|
||||
|
||||
// Array of objects and instances in the scene
|
||||
|
|
@ -132,15 +132,15 @@ public:
|
|||
void createRtDescriptorSet();
|
||||
void updateRtDescriptorSet();
|
||||
void createRtPipeline();
|
||||
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor);
|
||||
void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
|
||||
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ int main(int argc, char** argv)
|
|||
|
||||
// Setup camera
|
||||
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT);
|
||||
CameraManip.setLookat(nvmath::vec3f(5, 4, -4), nvmath::vec3f(0, 1, 0), nvmath::vec3f(0, 1, 0));
|
||||
CameraManip.setLookat(glm::vec3(5, 4, -4), glm::vec3(0, 1, 0), glm::vec3(0, 1, 0));
|
||||
|
||||
// Setup Vulkan
|
||||
if(!glfwVulkanSupported())
|
||||
|
|
@ -161,10 +161,10 @@ int main(int argc, char** argv)
|
|||
|
||||
// Creation of the example
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true),
|
||||
nvmath::scale_mat4(nvmath::vec3f(2.f, 1.f, 2.f)));
|
||||
glm::scale(glm::mat4(1.f), glm::vec3(2.f, 1.f, 2.f)));
|
||||
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true));
|
||||
uint32_t wusonId = 1;
|
||||
nvmath::mat4f identity{1};
|
||||
uint32_t wusonId = 1;
|
||||
glm::mat4 identity{1};
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
helloVk.m_instances.push_back({identity, wusonId});
|
||||
|
|
@ -194,9 +194,9 @@ int main(int argc, char** argv)
|
|||
helloVk.createCompPipelines();
|
||||
|
||||
|
||||
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f);
|
||||
bool useRaytracer = true;
|
||||
auto start = std::chrono::system_clock::now();
|
||||
glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
|
||||
bool useRaytracer = true;
|
||||
auto start = std::chrono::system_clock::now();
|
||||
|
||||
|
||||
helloVk.setupGlfwCallbacks(window);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
||||
#version 460
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
#extension GL_EXT_scalar_block_layout : enable
|
||||
|
|
|
|||
|
|
@ -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