Bulk update nvpro-samples 11/20/23

5c72ddfc0522eb6604828e74886cf39be646ba78
This commit is contained in:
Mathias Heyer 2023-11-20 13:54:44 -08:00
parent debd0d5e33
commit 0c73e8ec1b
96 changed files with 927 additions and 922 deletions

View file

@ -37,11 +37,11 @@ void ObjLoader::loadModel(const std::string& filename)
for(const auto& material : reader.GetMaterials()) for(const auto& material : reader.GetMaterials())
{ {
MaterialObj m; MaterialObj m;
m.ambient = nvmath::vec3f(material.ambient[0], material.ambient[1], material.ambient[2]); m.ambient = glm::vec3(material.ambient[0], material.ambient[1], material.ambient[2]);
m.diffuse = nvmath::vec3f(material.diffuse[0], material.diffuse[1], material.diffuse[2]); m.diffuse = glm::vec3(material.diffuse[0], material.diffuse[1], material.diffuse[2]);
m.specular = nvmath::vec3f(material.specular[0], material.specular[1], material.specular[2]); m.specular = glm::vec3(material.specular[0], material.specular[1], material.specular[2]);
m.emission = nvmath::vec3f(material.emission[0], material.emission[1], material.emission[2]); m.emission = glm::vec3(material.emission[0], material.emission[1], material.emission[2]);
m.transmittance = nvmath::vec3f(material.transmittance[0], material.transmittance[1], material.transmittance[2]); m.transmittance = glm::vec3(material.transmittance[0], material.transmittance[1], material.transmittance[2]);
m.dissolve = material.dissolve; m.dissolve = material.dissolve;
m.ior = material.ior; m.ior = material.ior;
m.shininess = material.shininess; m.shininess = material.shininess;
@ -113,10 +113,10 @@ void ObjLoader::loadModel(const std::string& filename)
VertexObj& v1 = m_vertices[m_indices[i + 1]]; VertexObj& v1 = m_vertices[m_indices[i + 1]];
VertexObj& v2 = m_vertices[m_indices[i + 2]]; VertexObj& v2 = m_vertices[m_indices[i + 2]];
nvmath::vec3f n = nvmath::normalize(nvmath::cross((v1.pos - v0.pos), (v2.pos - v0.pos))); glm::vec3 n = glm::normalize(glm::cross((v1.pos - v0.pos), (v2.pos - v0.pos)));
v0.nrm = n; v0.nrm = n;
v1.nrm = n; v1.nrm = n;
v2.nrm = n; v2.nrm = n;
} }
} }
} }

View file

@ -18,7 +18,7 @@
*/ */
#pragma once #pragma once
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
#include "tiny_obj_loader.h" #include "tiny_obj_loader.h"
#include <array> #include <array>
#include <iostream> #include <iostream>
@ -29,15 +29,15 @@
// Structure holding the material // Structure holding the material
struct MaterialObj struct MaterialObj
{ {
nvmath::vec3f ambient = nvmath::vec3f(0.1f, 0.1f, 0.1f); glm::vec3 ambient = glm::vec3(0.1f, 0.1f, 0.1f);
nvmath::vec3f diffuse = nvmath::vec3f(0.7f, 0.7f, 0.7f); glm::vec3 diffuse = glm::vec3(0.7f, 0.7f, 0.7f);
nvmath::vec3f specular = nvmath::vec3f(1.0f, 1.0f, 1.0f); glm::vec3 specular = glm::vec3(1.0f, 1.0f, 1.0f);
nvmath::vec3f transmittance = nvmath::vec3f(0.0f, 0.0f, 0.0f); glm::vec3 transmittance = glm::vec3(0.0f, 0.0f, 0.0f);
nvmath::vec3f emission = nvmath::vec3f(0.0f, 0.0f, 0.10); glm::vec3 emission = glm::vec3(0.0f, 0.0f, 0.10);
float shininess = 0.f; float shininess = 0.f;
float ior = 1.0f; // index of refraction float ior = 1.0f; // index of refraction
float dissolve = 1.f; // 1 == opaque; 0 == fully transparent float dissolve = 1.f; // 1 == opaque; 0 == fully transparent
// illumination model (see http://www.fileformat.info/format/material/) // illumination model (see http://www.fileformat.info/format/material/)
int illum = 0; int illum = 0;
int textureID = -1; int textureID = -1;
}; };
@ -45,10 +45,10 @@ struct MaterialObj
// NOTE: BLAS builder depends on pos being the first member // NOTE: BLAS builder depends on pos being the first member
struct VertexObj struct VertexObj
{ {
nvmath::vec3f pos; glm::vec3 pos;
nvmath::vec3f nrm; glm::vec3 nrm;
nvmath::vec3f color; glm::vec3 color;
nvmath::vec2f texCoord; glm::vec2 texCoord;
}; };

View file

@ -6,7 +6,7 @@
<link rel="stylesheet" href="vkrt_tutorial.css?"> <link rel="stylesheet" href="vkrt_tutorial.css?">
<script> window.markdeepOptions = { tocStyle: "medium" };</script> <script> window.markdeepOptions = { tocStyle: "medium" };</script>
<script src="markdeep.min.js" charset="utf-8"></script> <script src="markdeep.min.js" charset="utf-8"></script>
<script src="https://developer.download.nvidia.com/ProGraphics/nvpro-samples/scripts/markdeep.min.js" charset="utf-8"></script> <script src="https://developer.nvidia.com/sites/default/files/akamai/gameworks/whitepapers/markdeep.min.js" charset="utf-8"></script>
<script> <script>
window.alreadyProcessedMarkdeep || (document.body.style.visibility = "visible") window.alreadyProcessedMarkdeep || (document.body.style.visibility = "visible")
</script> </script>

View file

@ -73,8 +73,8 @@ the lanterns on the host.
// Information on each colored lantern illuminating the scene. // Information on each colored lantern illuminating the scene.
struct Lantern struct Lantern
{ {
nvmath::vec3f position; glm::vec3 position;
nvmath::vec3f color; glm::vec3 color;
float brightness; float brightness;
float radius; // Max world-space distance that light illuminates. float radius; // Max world-space distance that light illuminates.
}; };
@ -86,14 +86,14 @@ a new function for configuring a new lantern in the scene.
```` C ```` C
// Array of lanterns in scene. Not modifiable after acceleration structure build. // Array of lanterns in scene. Not modifiable after acceleration structure build.
std::vector<Lantern> m_lanterns; std::vector<Lantern> m_lanterns;
void addLantern(nvmath::vec3f pos, nvmath::vec3f color, float brightness, float radius); void addLantern(glm::vec3 pos, glm::vec3 color, float brightness, float radius);
```` ````
The `addLantern` function is implemented as The `addLantern` function is implemented as
```` C ```` C
// Add a light-emitting colored lantern to the scene. May only be called before TLAS build. // Add a light-emitting colored lantern to the scene. May only be called before TLAS build.
void HelloVulkan::addLantern(nvmath::vec3f pos, nvmath::vec3f color, float brightness, float radius) void HelloVulkan::addLantern(glm::vec3 pos, glm::vec3 color, float brightness, float radius)
{ {
assert(m_lanternCount == 0); // Indicates TLAS build has not happened yet. assert(m_lanternCount == 0); // Indicates TLAS build has not happened yet.
@ -240,11 +240,11 @@ in `hello_vulkan.h`
// Barely fits in 128-byte push constant limit guaranteed by spec. // Barely fits in 128-byte push constant limit guaranteed by spec.
struct LanternIndirectPushConstants struct LanternIndirectPushConstants
{ {
nvmath::vec4 viewRowX; // First 3 rows of view matrix. glm::vec4 viewRowX; // First 3 rows of view matrix.
nvmath::vec4 viewRowY; // Set w=1 implicitly in shader. glm::vec4 viewRowY; // Set w=1 implicitly in shader.
nvmath::vec4 viewRowZ; glm::vec4 viewRowZ;
nvmath::mat4 proj; // Perspective matrix glm::mat4 proj; // Perspective matrix
float nearZ; // Near plane used to create projection matrix. float nearZ; // Near plane used to create projection matrix.
// Pixel dimensions of output image (needed to scale NDC to screen coordinates). // Pixel dimensions of output image (needed to scale NDC to screen coordinates).
@ -475,7 +475,7 @@ between the compute shader and indirect draw stages.
// effect. This is stored in m_lanternIndirectBuffer. Then an indirect trace rays command // effect. This is stored in m_lanternIndirectBuffer. Then an indirect trace rays command
// is run for every lantern within its scissor rectangle. The lanterns' light // is run for every lantern within its scissor rectangle. The lanterns' light
// contribution is additively blended into the output image. // contribution is additively blended into the output image.
void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor) void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor)
{ {
// Before tracing rays, we need to dispatch the compute shaders that // Before tracing rays, we need to dispatch the compute shaders that
// fill in the ray trace indirect parameters for each lantern pass. // fill in the ray trace indirect parameters for each lantern pass.
@ -497,7 +497,7 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
// Bind compute shader, update push constant and descriptors, dispatch compute. // Bind compute shader, update push constant and descriptors, dispatch compute.
vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, m_lanternIndirectCompPipeline); vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, m_lanternIndirectCompPipeline);
nvmath::mat4 view = getViewMatrix(); glm::mat4 view = getViewMatrix();
m_lanternIndirectPushConstants.viewRowX = view.row(0); m_lanternIndirectPushConstants.viewRowX = view.row(0);
m_lanternIndirectPushConstants.viewRowY = view.row(1); m_lanternIndirectPushConstants.viewRowY = view.row(1);
m_lanternIndirectPushConstants.viewRowZ = view.row(2); m_lanternIndirectPushConstants.viewRowZ = view.row(2);
@ -535,16 +535,18 @@ Since the near plane and view/projection matrices are used in multiple places no
they were factored out to common code in `hello_vulkan.h`. they were factored out to common code in `hello_vulkan.h`.
```` C ```` C
nvmath::mat4 getViewMatrix() glm::mat4 getViewMatrix()
{ {
return CameraManip.getMatrix(); return CameraManip.getMatrix();
} }
static constexpr float nearZ = 0.1f; static constexpr float nearZ = 0.1f;
nvmath::mat4 getProjMatrix() glm::mat4 getProjMatrix()
{ {
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
return nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, nearZ, 1000.0f); glm::mat4 proj = glm::perspectiveRH_ZO(glm::radians(CameraManip.getFov()), aspectRatio, nearZ, 1000.0f);
proj[1][1] *= -1;
return proj;
} }
```` ````
@ -571,7 +573,7 @@ for delivering this sphere mesh to the BLAS builder.
```` C ```` C
private: private:
void fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::vector<uint32_t>& indices); void fillLanternVerts(std::vector<glm::vec3>& vertices, std::vector<uint32_t>& indices);
void createLanternModel(); void createLanternModel();
// Used to store lantern model, generated at runtime. // Used to store lantern model, generated at runtime.
@ -598,7 +600,7 @@ auto maxPrimitiveCount = uint32_t(indices.size() / 3);
VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR}; VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR};
triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data. triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data.
triangles.vertexData.deviceAddress = vertexAddress; triangles.vertexData.deviceAddress = vertexAddress;
triangles.vertexStride = sizeof(nvmath::vec3f); triangles.vertexStride = sizeof(glm::vec3);
// Describe index data (32-bit unsigned int) // Describe index data (32-bit unsigned int)
triangles.indexType = VK_INDEX_TYPE_UINT32; triangles.indexType = VK_INDEX_TYPE_UINT32;
triangles.indexData.deviceAddress = indexAddress; triangles.indexData.deviceAddress = indexAddress;
@ -625,7 +627,7 @@ m_lanternBlasInput.asBuildOffsetInfo.emplace_back(offset);
```` ````
The principle difference from before is that the vertex array is now a packed array of The principle difference from before is that the vertex array is now a packed array of
float 3-vectors, hence, we call `triangles.setVertexStride(sizeof(nvmath::vec3f));`. float 3-vectors, hence, we call `triangles.setVertexStride(sizeof(glm::vec3));`.
Then, we add a call to create a lantern model and add the lantern model to the list of Then, we add a call to create a lantern model and add the lantern model to the list of
BLAS to build in `HelloVulkan::createBottomLevelAS`. Since we'll need the index of BLAS to build in `HelloVulkan::createBottomLevelAS`. Since we'll need the index of
@ -701,7 +703,7 @@ void HelloVulkan::createTopLevelAS()
for(int i = 0; i < static_cast<int>(m_lanterns.size()); ++i) for(int i = 0; i < static_cast<int>(m_lanterns.size()); ++i)
{ {
VkAccelerationStructureInstanceKHR lanternInstance; VkAccelerationStructureInstanceKHR lanternInstance;
lanternInstance.transform = nvvk::toTransformMatrixKHR(nvmath::translation_mat4(m_lanterns[i].position)); lanternInstance.transform = nvvk::toTransformMatrixKHR(glm::translate(glm::mat4(1),m_lanterns[i].position));
lanternInstance.instanceCustomIndex = i; lanternInstance.instanceCustomIndex = i;
lanternInstance.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(uint32_t(m_lanternBlasId)); lanternInstance.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(uint32_t(m_lanternBlasId));
lanternInstance.instanceShaderBindingTableRecordOffset = 1; // Next hit group is for lanterns. lanternInstance.instanceShaderBindingTableRecordOffset = 1; // Next hit group is for lanterns.
@ -870,10 +872,10 @@ Modify `m_pcRay` in `hello_vulkan.h`.
struct RtPushConstant struct RtPushConstant
{ {
// Background color // Background color
nvmath::vec4f clearColor; glm::vec4 clearColor;
// Information on the light in the sky used when lanternPassNumber = -1. // Information on the light in the sky used when lanternPassNumber = -1.
nvmath::vec3f lightPosition; glm::vec3 lightPosition;
float lightIntensity; float lightIntensity;
int32_t lightType; int32_t lightType;

View file

@ -1633,7 +1633,7 @@ In the `main` function, we now add the construction of the Shader Binding Table:
Let's create a function that will record commands to call the ray trace shaders. First, add the declaration to the header Let's create a function that will record commands to call the ray trace shaders. First, add the declaration to the header
~~~~ C ~~~~ C
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor); void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
~~~~ ~~~~
We first bind the pipeline and its layout, and set the push constants that will be available throughout the pipeline: We first bind the pipeline and its layout, and set the push constants that will be available throughout the pipeline:
@ -1642,7 +1642,7 @@ We first bind the pipeline and its layout, and set the push constants that will
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values
@ -2132,7 +2132,7 @@ The OBJ model is loaded in `main.cpp` by calling `helloVk.loadModel`. Let's load
Since that model is larger, we can change the `CameraManip.setLookat` call to Since that model is larger, we can change the `CameraManip.setLookat` call to
~~~~ C ~~~~ C
CameraManip.setLookat(nvmath::vec3f(4, 4, 4), nvmath::vec3f(0, 1, 0), nvmath::vec3f(0, 1, 0)); CameraManip.setLookat(glm::vec3(4, 4, 4), glm::vec3(0, 1, 0), glm::vec3(0, 1, 0));
~~~~ ~~~~
![](Images/resultRaytraceLightMatMedieval.png) ![](Images/resultRaytraceLightMatMedieval.png)

View file

@ -66,12 +66,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -199,7 +199,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -208,9 +208,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -466,7 +466,7 @@ void HelloVulkan::initRayTracing()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray trace the scene // 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(); updateFrame();
if(m_pcRaster.frame >= m_maxFrames) if(m_pcRaster.frame >= m_maxFrames)
@ -481,13 +481,13 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float refFov{CameraManip.getFov()}; static float refFov{CameraManip.getFov()};
const auto& m = CameraManip.getMatrix(); const auto& m = CameraManip.getMatrix();
const auto fov = CameraManip.getFov(); const auto fov = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov) if(refCamMatrix != m || refFov != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; 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; ObjImplicit impl;
impl.minimum = center - radius; impl.minimum = center - radius;
@ -512,7 +512,7 @@ void HelloVulkan::addImplSphere(nvmath::vec3f center, float radius, int matId)
m_implObjects.objImpl.push_back(impl); 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; ObjImplicit impl;
impl.minimum = minumum; impl.minimum = minumum;
@ -546,9 +546,9 @@ void HelloVulkan::createImplictBuffers()
auto cmdBuf = cmdGen.createCommandBuffer(); auto cmdBuf = cmdGen.createCommandBuffer();
m_implObjects.implBuf = m_alloc.createBuffer(cmdBuf, m_implObjects.objImpl, 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_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR
| VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR); | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
m_implObjects.implMatBuf = m_alloc.createBuffer(cmdBuf, m_implObjects.implMat, m_implObjects.implMatBuf = m_alloc.createBuffer(cmdBuf, m_implObjects.implMat,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT); VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
cmdGen.submitAndWait(cmdBuf); cmdGen.submitAndWait(cmdBuf);

View file

@ -63,7 +63,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -79,14 +79,14 @@ public:
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
{-1.f, -1.f, -.4f}, // lightDirection; {-1.f, -1.f, -.4f}, // lightDirection;
0.939692621f, // {cos(deg2rad(20.0f))}, // lightSpotCutoff; 0.939692621f, // {cos(glm::radians(20.0f))}, // lightSpotCutoff;
0.866025404f, // {cos(deg2rad(30.0f))}, // lightSpotOuterCutoff; 0.866025404f, // {cos(glm::radians(30.0f))}, // lightSpotOuterCutoff;
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -125,13 +125,13 @@ public:
Raytracer m_raytrace; Raytracer m_raytrace;
void initRayTracing(); void initRayTracing();
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor); void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
// Implicit // Implicit
ImplInst m_implObjects; ImplInst m_implObjects;
void addImplSphere(nvmath::vec3f center, float radius, int matId); void addImplSphere(glm::vec3 center, float radius, int matId);
void addImplCube(nvmath::vec3f minumum, nvmath::vec3f maximum, int matId); void addImplCube(glm::vec3 minumum, glm::vec3 maximum, int matId);
void addImplMaterial(const MaterialObj& mat); void addImplMaterial(const MaterialObj& mat);
void createImplictBuffers(); void createImplictBuffers();
}; };

View file

@ -85,14 +85,14 @@ void renderUI(HelloVulkan& helloVk)
} }
if(pc.lightType == 1) if(pc.lightType == 1)
{ {
float dCutoff = rad2deg(acos(pc.lightSpotCutoff)); float dCutoff = glm::degrees(acos(pc.lightSpotCutoff));
float dOutCutoff = rad2deg(acos(pc.lightSpotOuterCutoff)); float dOutCutoff = glm::degrees(acos(pc.lightSpotOuterCutoff));
changed |= ImGui::SliderFloat("Cutoff", &dCutoff, 0.f, 45.f); changed |= ImGui::SliderFloat("Cutoff", &dCutoff, 0.f, 45.f);
changed |= ImGui::SliderFloat("OutCutoff", &dOutCutoff, 0.f, 45.f); changed |= ImGui::SliderFloat("OutCutoff", &dOutCutoff, 0.f, 45.f);
dCutoff = dCutoff > dOutCutoff ? dOutCutoff : dCutoff; dCutoff = dCutoff > dOutCutoff ? dOutCutoff : dCutoff;
pc.lightSpotCutoff = cos(deg2rad(dCutoff)); pc.lightSpotCutoff = cos(glm::radians(dCutoff));
pc.lightSpotOuterCutoff = cos(deg2rad(dOutCutoff)); 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/Medieval_building.obj", defaultSearchPaths, true));
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true));
helloVk.loadModel(nvh::findFile("media/scenes/wuson.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::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() 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) for(int n = 0; n < 50; ++n)
{ {
ObjInstance inst; ObjInstance inst;
inst.objIndex = wusonIndex; inst.objIndex = wusonIndex;
float scale = fabsf(disn(gen)); float scale = fabsf(disn(gen));
nvmath::mat4f mat = nvmath::translation_mat4(nvmath::vec3f{dis(gen), 0.f, dis(gen) + 6}); glm::mat4 mat = glm::translate(glm::mat4(1), glm::vec3{dis(gen), 0.f, dis(gen) + 6});
// mat = mat * nvmath::rotation_mat4_x(dis(gen)); // mat = mat * glm::rotation_mat4_x(dis(gen));
mat = mat * nvmath::scale_mat4(nvmath::vec3f(scale)); mat = glm::scale(mat, glm::vec3(scale));
inst.transform = mat; inst.transform = mat;
helloVk.m_instances.push_back(inst); helloVk.m_instances.push_back(inst);
@ -219,13 +219,13 @@ int main(int argc, char** argv)
// Creation of implicit geometry // Creation of implicit geometry
MaterialObj mat; MaterialObj mat;
// Reflective // Reflective
mat.diffuse = nvmath::vec3f(0, 0, 0); mat.diffuse = glm::vec3(0, 0, 0);
mat.specular = nvmath::vec3f(1.f); mat.specular = glm::vec3(1.f);
mat.shininess = 0.0; mat.shininess = 0.0;
mat.illum = 3; mat.illum = 3;
helloVk.addImplMaterial(mat); helloVk.addImplMaterial(mat);
// Transparent // Transparent
mat.diffuse = nvmath::vec3f(0.4, 0.4, 1); mat.diffuse = glm::vec3(0.4, 0.4, 1);
mat.illum = 4; mat.illum = 4;
mat.dissolve = 0.5; mat.dissolve = 0.5;
helloVk.addImplMaterial(mat); helloVk.addImplMaterial(mat);
@ -249,8 +249,8 @@ int main(int argc, char** argv)
helloVk.initRayTracing(); helloVk.initRayTracing();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -34,8 +34,8 @@ struct ObjModel
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
@ -48,10 +48,10 @@ enum EObjType
// One single implicit object // One single implicit object
struct ObjImplicit struct ObjImplicit
{ {
nvmath::vec3f minimum{0, 0, 0}; // Aabb glm::vec3 minimum{0, 0, 0}; // Aabb
nvmath::vec3f maximum{0, 0, 0}; // Aabb glm::vec3 maximum{0, 0, 0}; // Aabb
int objType{0}; // 0: Sphere, 1: Cube int objType{0}; // 0: Sphere, 1: Cube
int matId{0}; int matId{0};
}; };
// All implicit objects // All implicit objects
@ -62,5 +62,5 @@ struct ImplInst
nvvk::Buffer implBuf; // Buffer of objects nvvk::Buffer implBuf; // Buffer of objects
nvvk::Buffer implMatBuf; // Buffer of material nvvk::Buffer implMatBuf; // Buffer of material
int blasId{0}; int blasId{0};
nvmath::mat4f transform{1}; glm::mat4 transform{1};
}; };

View file

@ -78,7 +78,7 @@ void Offscreen::createFramebuffer(const VkExtent2D& size)
// Creating the depth buffer // Creating the depth buffer
{ {
auto depthCreateInfo = nvvk::makeImage2DCreateInfo(size, m_depthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); 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}; VkImageViewCreateInfo depthStencilView{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
depthStencilView.viewType = VK_IMAGE_VIEW_TYPE_2D; depthStencilView.viewType = VK_IMAGE_VIEW_TYPE_2D;

View file

@ -180,8 +180,8 @@ void Raytracer::createTopLevelAS(std::vector<ObjInstance>& instances, ImplInst&
rayInst.transform = nvvk::toTransformMatrixKHR(implicitObj.transform); // Position of the instance rayInst.transform = nvvk::toTransformMatrixKHR(implicitObj.transform); // Position of the instance
rayInst.instanceCustomIndex = instances[nbObj].objIndex; rayInst.instanceCustomIndex = instances[nbObj].objIndex;
rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(implicitObj.blasId)); rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(implicitObj.blasId));
rayInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR; rayInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR;
rayInst.mask = 0xFF; // Only be hit if rayMask & instance.mask != 0 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) rayInst.instanceShaderBindingTableRecordOffset = 1; // We will use the same hit group for all objects (the second one)
tlas.emplace_back(rayInst); tlas.emplace_back(rayInst);
} }
@ -209,7 +209,7 @@ void Raytracer::createRtDescriptorSet(const VkImageView& outputImage)
allocateInfo.pSetLayouts = &m_rtDescSetLayout; allocateInfo.pSetLayouts = &m_rtDescSetLayout;
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -405,7 +405,7 @@ void Raytracer::createRtPipeline(VkDescriptorSetLayout& sceneDescLayout)
// Ray Tracing the scene // Ray Tracing the scene
// //
void Raytracer::raytrace(const VkCommandBuffer& cmdBuf, void Raytracer::raytrace(const VkCommandBuffer& cmdBuf,
const nvmath::vec4f& clearColor, const glm::vec4& clearColor,
VkDescriptorSet& sceneDescSet, VkDescriptorSet& sceneDescSet,
VkExtent2D& size, VkExtent2D& size,
PushConstantRaster& sceneConstants) PushConstantRaster& sceneConstants)

View file

@ -18,7 +18,7 @@
*/ */
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
#include "nvvk/sbtwrapper_vk.hpp" #include "nvvk/sbtwrapper_vk.hpp"
@ -39,11 +39,7 @@ public:
void createRtDescriptorSet(const VkImageView& outputImage); void createRtDescriptorSet(const VkImageView& outputImage);
void updateRtDescriptorSet(const VkImageView& outputImage); void updateRtDescriptorSet(const VkImageView& outputImage);
void createRtPipeline(VkDescriptorSetLayout& sceneDescLayout); void createRtPipeline(VkDescriptorSetLayout& sceneDescLayout);
void raytrace(const VkCommandBuffer& cmdBuf, void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor, VkDescriptorSet& sceneDescSet, VkExtent2D& size, PushConstantRaster& sceneConstants);
const nvmath::vec4f& clearColor,
VkDescriptorSet& sceneDescSet,
VkExtent2D& size,
PushConstantRaster& sceneConstants);
private: private:
nvvk::ResourceAllocator* m_alloc{nullptr}; // Allocator for buffer, images, acceleration structures nvvk::ResourceAllocator* m_alloc{nullptr}; // Allocator for buffer, images, acceleration structures
@ -54,11 +50,11 @@ private:
nvvk::SBTWrapper m_sbtWrapper; nvvk::SBTWrapper m_sbtWrapper;
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -61,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -185,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -194,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;

View file

@ -39,7 +39,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -62,18 +62,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene

View file

@ -94,7 +94,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT);
CameraManip.setLookat(nvmath::vec3f(2.0f, 2.0f, 2.0f), nvmath::vec3f(0, 0, 0), nvmath::vec3f(0, 1, 0)); CameraManip.setLookat(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
// Setup Vulkan // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -165,7 +165,7 @@ int main(int argc, char** argv)
helloVk.createPostDescriptor(); helloVk.createPostDescriptor();
helloVk.createPostPipeline(); helloVk.createPostPipeline();
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -60,12 +60,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -184,7 +184,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -193,9 +193,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -698,7 +698,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -852,7 +852,7 @@ void HelloVulkan::createRtShaderBindingTable()
uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment); uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment);
m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member
m_missRegion.stride = handleSizeAligned; m_missRegion.stride = handleSizeAligned;
m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_hitRegion.stride = handleSizeAligned; m_hitRegion.stride = handleSizeAligned;
@ -867,9 +867,9 @@ void HelloVulkan::createRtShaderBindingTable()
// Allocate a buffer for storing the SBT. // Allocate a buffer for storing the SBT.
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size; VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize, m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); 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. m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
// Find the SBT addresses of each group // Find the SBT addresses of each group
@ -911,7 +911,7 @@ void HelloVulkan::createRtShaderBindingTable()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -42,7 +42,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -65,18 +65,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -132,15 +132,15 @@ public:
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void createRtShaderBindingTable(); void createRtShaderBindingTable();
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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -94,7 +94,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -183,8 +183,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -123,8 +123,8 @@ In addition, the pipeline libraries need to have the same pipeline interface. Th
// the built-in triangle intersector) and the maximum payload size (3 floating-point values in this sample). // the built-in triangle intersector) and the maximum payload size (3 floating-point values in this sample).
// Pipeline libraries can be linked into a final pipeline only if their interface matches // Pipeline libraries can be linked into a final pipeline only if their interface matches
VkRayTracingPipelineInterfaceCreateInfoKHR pipelineInterface{VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_INTERFACE_CREATE_INFO_KHR}; VkRayTracingPipelineInterfaceCreateInfoKHR pipelineInterface{VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_INTERFACE_CREATE_INFO_KHR};
pipelineInterface.maxPipelineRayHitAttributeSize = sizeof(nvmath::vec2f); pipelineInterface.maxPipelineRayHitAttributeSize = sizeof(glm::vec2);
pipelineInterface.maxPipelineRayPayloadSize = sizeof(nvmath::vec3f); pipelineInterface.maxPipelineRayPayloadSize = sizeof(glm::vec3);
pipelineLibraryInfo.pLibraryInterface = &pipelineInterface; pipelineLibraryInfo.pLibraryInterface = &pipelineInterface;
~~~~ ~~~~

View file

@ -64,12 +64,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -188,7 +188,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -197,9 +197,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -706,7 +706,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -902,8 +902,8 @@ void HelloVulkan::createRtPipeline()
// the built-in triangle intersector) and the maximum payload size (3 floating-point values in this sample). // the built-in triangle intersector) and the maximum payload size (3 floating-point values in this sample).
// Pipeline libraries can be linked into a final pipeline only if their interface matches // Pipeline libraries can be linked into a final pipeline only if their interface matches
VkRayTracingPipelineInterfaceCreateInfoKHR pipelineInterface{VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_INTERFACE_CREATE_INFO_KHR}; VkRayTracingPipelineInterfaceCreateInfoKHR pipelineInterface{VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_INTERFACE_CREATE_INFO_KHR};
pipelineInterface.maxPipelineRayHitAttributeSize = sizeof(nvmath::vec2f); pipelineInterface.maxPipelineRayHitAttributeSize = sizeof(glm::vec2);
pipelineInterface.maxPipelineRayPayloadSize = sizeof(nvmath::vec3f); pipelineInterface.maxPipelineRayPayloadSize = sizeof(glm::vec3);
pipelineLibraryInfo.pLibraryInterface = &pipelineInterface; pipelineLibraryInfo.pLibraryInterface = &pipelineInterface;
// Shader groups and stages for the library // Shader groups and stages for the library
@ -1003,7 +1003,7 @@ void HelloVulkan::createRtPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -43,7 +43,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -66,18 +66,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
@ -134,15 +134,15 @@ public:
void createRtDescriptorSet(); void createRtDescriptorSet();
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); 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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -104,7 +104,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -193,8 +193,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -22,10 +22,10 @@ and the acceleration structure does not deal with this well.
~~~~ C++ ~~~~ C++
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths), 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)); helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths));
uint32_t wusonId = 1; uint32_t wusonId = 1;
nvmath::mat4f identity{1}; glm::mat4 identity{1};
for(int i = 0; i < 20; i++) for(int i = 0; i < 20; i++)
helloVk.m_instances.push_back({identity, wusonId}); helloVk.m_instances.push_back({identity, wusonId});
~~~~ ~~~~
@ -57,8 +57,8 @@ void HelloVulkan::animationInstances(float time)
{ {
int wusonIdx = i + 1; int wusonIdx = i + 1;
auto& transform = m_instances[wusonIdx].transform; auto& transform = m_instances[wusonIdx].transform;
transform = nvmath::rotation_mat4_y(i * deltaAngle + offset) transform = glm::rotation_mat4_y(i * deltaAngle + offset)
* nvmath::translation_mat4(radius, 0.f, 0.f); * 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++ ~~~~ C++
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true), 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)); helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true));
uint32_t wusonId = 1; uint32_t wusonId = 1;
nvmath::mat4f identity{1}; glm::mat4 identity{1};
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++)
{ {
helloVk.m_instances.push_back({identity, wusonId}); helloVk.m_instances.push_back({identity, wusonId});

View file

@ -61,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -185,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -194,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -708,7 +708,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -844,7 +844,7 @@ void HelloVulkan::createRtPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values
@ -885,9 +885,10 @@ void HelloVulkan::animationInstances(float time)
for(int i = 0; i < nbWuson; i++) for(int i = 0; i < nbWuson; i++)
{ {
int wusonIdx = i + 1; int wusonIdx = i + 1;
auto& transform = m_instances[wusonIdx].transform; glm::mat4 transform = m_instances[wusonIdx].transform;
transform = nvmath::rotation_mat4_y(i * deltaAngle + offset) * nvmath::translation_mat4(radius, 0.f, 0.f); 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]; VkAccelerationStructureInstanceKHR& tinst = m_tlas[wusonIdx];
tinst.transform = nvvk::toTransformMatrixKHR(transform); tinst.transform = nvvk::toTransformMatrixKHR(transform);

View file

@ -43,7 +43,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -66,18 +66,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -132,15 +132,15 @@ public:
void createRtDescriptorSet(); void createRtDescriptorSet();
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); 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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -94,7 +94,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -161,10 +161,10 @@ int main(int argc, char** argv)
// Creation of the example // Creation of the example
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true), 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)); helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true));
uint32_t wusonId = 1; uint32_t wusonId = 1;
nvmath::mat4f identity{1}; glm::mat4 identity{1};
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++)
{ {
helloVk.m_instances.push_back({identity, wusonId}); helloVk.m_instances.push_back({identity, wusonId});
@ -194,9 +194,9 @@ int main(int argc, char** argv)
helloVk.createCompPipelines(); helloVk.createCompPipelines();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -16,7 +16,7 @@
* SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION * SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#version 460 #version 460
#extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_separate_shader_objects : enable
#extension GL_EXT_scalar_block_layout : enable #extension GL_EXT_scalar_block_layout : enable

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -190,8 +190,8 @@ For a more interesting scene, you can replace the `helloVk.loadModel` calls in `
~~~~ C++ ~~~~ C++
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true));
helloVk.loadModel(nvh::findFile("media/scenes/sphere.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/sphere.obj", defaultSearchPaths, true),
nvmath::scale_mat4(nvmath::vec3f(1.5f)) glm::scale(glm::mat4(1.f),glm::vec3(1.5f))
* nvmath::translation_mat4(nvmath::vec3f(0.0f, 1.0f, 0.0f))); * glm::translate(glm::mat4(1),glm::vec3(0.0f, 1.0f, 0.0f)));
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true));
~~~~ ~~~~

View file

@ -60,12 +60,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -185,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -194,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -700,7 +700,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -865,9 +865,9 @@ void HelloVulkan::createRtShaderBindingTable()
// The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned. // The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned.
uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment); uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment);
m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member
m_missRegion.stride = handleSizeAligned; m_missRegion.stride = handleSizeAligned;
m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_hitRegion.stride = handleSizeAligned; m_hitRegion.stride = handleSizeAligned;
@ -878,13 +878,13 @@ void HelloVulkan::createRtShaderBindingTable()
std::vector<uint8_t> handles(dataSize); std::vector<uint8_t> handles(dataSize);
auto result = vkGetRayTracingShaderGroupHandlesKHR(m_device, m_rtPipeline, 0, handleCount, dataSize, handles.data()); auto result = vkGetRayTracingShaderGroupHandlesKHR(m_device, m_rtPipeline, 0, handleCount, dataSize, handles.data());
assert(result == VK_SUCCESS); assert(result == VK_SUCCESS);
// Allocate a buffer for storing the SBT. // Allocate a buffer for storing the SBT.
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size; VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize, m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); 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. m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
// Find the SBT addresses of each group // Find the SBT addresses of each group
@ -926,7 +926,7 @@ void HelloVulkan::createRtShaderBindingTable()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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(); updateFrame();
if(m_pcRay.frame >= m_maxFrames) if(m_pcRay.frame >= m_maxFrames)
@ -960,13 +960,13 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float refFov{CameraManip.getFov()}; static float refFov{CameraManip.getFov()};
const auto& m = CameraManip.getMatrix(); const auto& m = CameraManip.getMatrix();
const auto fov = CameraManip.getFov(); const auto fov = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov) if(refCamMatrix != m || refFov != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -42,7 +42,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -65,18 +65,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -132,16 +132,16 @@ public:
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void createRtShaderBindingTable(); void createRtShaderBindingTable();
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor); void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
void resetFrame(); void resetFrame();
void updateFrame(); void updateFrame();
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -94,7 +94,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -162,7 +162,7 @@ int main(int argc, char** argv)
// Creation of the example // Creation of the example
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true));
helloVk.loadModel(nvh::findFile("media/scenes/sphere.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/sphere.obj", defaultSearchPaths, true),
nvmath::scale_mat4(nvmath::vec3f(1.5f)) * nvmath::translation_mat4(nvmath::vec3f(0.0f, 1.0f, 0.0f))); glm::scale(glm::mat4(1.f), glm::vec3(1.5f)) * glm::translate(glm::mat4(1.f), glm::vec3(0.0f, 1.0f, 0.0f)));
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true));
helloVk.createOffscreenRender(); helloVk.createOffscreenRender();
@ -185,8 +185,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -251,12 +251,12 @@ after modifying the GUI related to the AO.
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float fov = 0; static float fov = 0;
auto& m = CameraManip.getMatrix(); auto& m = CameraManip.getMatrix();
auto f = CameraManip.getFov(); auto f = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || f != fov) if(refCamMatrix != m || f != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -61,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -188,7 +188,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -197,9 +197,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -845,12 +845,12 @@ void HelloVulkan::runCompute(VkCommandBuffer cmdBuf, AoControl& aoControl)
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float fov = 0; static float fov = 0;
auto& m = CameraManip.getMatrix(); auto& m = CameraManip.getMatrix();
auto f = CameraManip.getFov(); auto f = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || f != fov) if(refCamMatrix != m || f != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -53,7 +53,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -76,18 +76,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -144,7 +144,7 @@ public:
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
// #Tuto_animation // #Tuto_animation

View file

@ -95,7 +95,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -161,7 +161,7 @@ int main(int argc, char** argv)
helloVk.initGUI(0); // Using sub-pass 0 helloVk.initGUI(0); // Using sub-pass 0
// Creation of the example // Creation of the example
nvmath::mat4f t = nvmath::translation_mat4(nvmath::vec3f{0, 0.0, 0}); glm::mat4 t = glm::translate(glm::mat4(1), glm::vec3{0, 0.0, 0});
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true), t); helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true), t);
//helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true)); //helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true));
helloVk.loadModel(nvh::findFile("media/scenes/Medieval_building.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/Medieval_building.obj", defaultSearchPaths, true));
@ -190,7 +190,7 @@ int main(int argc, char** argv)
helloVk.createCompPipelines(); helloVk.createCompPipelines();
nvmath::vec4f clearColor = nvmath::vec4f(0, 0, 0, 0); glm::vec4 clearColor = glm::vec4(0, 0, 0, 0);
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);
ImGui_ImplGlfw_InitForVulkan(window, true); ImGui_ImplGlfw_InitForVulkan(window, true);

View file

@ -16,7 +16,7 @@
* SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION * SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#version 460 #version 460
#extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_separate_shader_objects : enable
#extension GL_EXT_nonuniform_qualifier : enable #extension GL_EXT_nonuniform_qualifier : enable

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -61,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -185,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -194,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -702,7 +702,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -864,7 +864,7 @@ void HelloVulkan::createRtPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -43,7 +43,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -66,21 +66,21 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // model identity {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, // Identity matrix
{10.f, 15.f, 8.f}, // lightPosition {10.f, 15.f, 8.f}, // lightPosition
{0}, // instanceId to retrieve the transformation matrix {0}, // instanceId to retrieve the transformation matrix
{-1.f, -1.f, -1.f}, // lightDirection {-1.f, -1.f, -1.f}, // lightDirection
{100.f}, // lightIntensity {100.f}, // lightIntensity
{cos(deg2rad(12.5f))}, // lightSpotCutoff {cos(glm::radians(12.5f))}, // lightSpotCutoff
{cos(deg2rad(17.5f))}, // lightSpotOuterCutoff {cos(glm::radians(17.5f))}, // lightSpotOuterCutoff
{0} // lightType 0: point, 1: infinite {0} // lightType 0: point, 1: infinite
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -135,15 +135,15 @@ public:
void createRtDescriptorSet(); void createRtDescriptorSet();
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); 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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -74,14 +74,14 @@ void renderUI(HelloVulkan& helloVk)
ImGui::SliderFloat("Light Intensity", &helloVk.m_pcRaster.lightIntensity, 0.f, 500.f); ImGui::SliderFloat("Light Intensity", &helloVk.m_pcRaster.lightIntensity, 0.f, 500.f);
if(helloVk.m_pcRaster.lightType == 1) if(helloVk.m_pcRaster.lightType == 1)
{ {
float dCutoff = rad2deg(acos(helloVk.m_pcRaster.lightSpotCutoff)); float dCutoff = glm::degrees(acos(helloVk.m_pcRaster.lightSpotCutoff));
float dOutCutoff = rad2deg(acos(helloVk.m_pcRaster.lightSpotOuterCutoff)); float dOutCutoff = glm::degrees(acos(helloVk.m_pcRaster.lightSpotOuterCutoff));
ImGui::SliderFloat("Cutoff", &dCutoff, 0.f, 45.f); ImGui::SliderFloat("Cutoff", &dCutoff, 0.f, 45.f);
ImGui::SliderFloat("OutCutoff", &dOutCutoff, 0.f, 45.f); ImGui::SliderFloat("OutCutoff", &dOutCutoff, 0.f, 45.f);
dCutoff = dCutoff > dOutCutoff ? dOutCutoff : dCutoff; dCutoff = dCutoff > dOutCutoff ? dOutCutoff : dCutoff;
helloVk.m_pcRaster.lightSpotCutoff = cos(deg2rad(dCutoff)); helloVk.m_pcRaster.lightSpotCutoff = cos(glm::radians(dCutoff));
helloVk.m_pcRaster.lightSpotOuterCutoff = cos(deg2rad(dOutCutoff)); helloVk.m_pcRaster.lightSpotOuterCutoff = cos(glm::radians(dOutCutoff));
} }
} }
} }
@ -112,7 +112,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -200,8 +200,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -223,7 +223,7 @@ auto HelloVulkan::primitiveToGeometry(const nvh::GltfPrimMesh& prim)
VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR}; VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR};
triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data. triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data.
triangles.vertexData.deviceAddress = vertexAddress; triangles.vertexData.deviceAddress = vertexAddress;
triangles.vertexStride = sizeof(nvmath::vec3f); triangles.vertexStride = sizeof(glm::vec3);
// Describe index data (32-bit unsigned int) // Describe index data (32-bit unsigned int)
triangles.indexType = VK_INDEX_TYPE_UINT32; triangles.indexType = VK_INDEX_TYPE_UINT32;
triangles.indexData.deviceAddress = indexAddress; triangles.indexData.deviceAddress = indexAddress;
@ -337,7 +337,7 @@ Small other changes were done, a different scene, different camera and light pos
Camera position Camera position
~~~~C ~~~~C
CameraManip.setLookat(nvmath::vec3f(0, 0, 15), nvmath::vec3f(0, 0, 0), nvmath::vec3f(0, 1, 0)); CameraManip.setLookat(glm::vec3(0, 0, 15), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
~~~~ ~~~~
Scene Scene
@ -347,7 +347,7 @@ Scene
Light Position Light Position
~~~~C ~~~~C
nvmath::vec3f lightPosition{0.f, 4.5f, 0.f}; glm::vec3 lightPosition{0.f, 4.5f, 0.f};
~~~~ ~~~~
# Simple Path Tracing # Simple Path Tracing
@ -368,13 +368,13 @@ Add the following two functions in `hello_vulkan.cpp`:
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float refFov{CameraManip.getFov()}; static float refFov{CameraManip.getFov()};
const auto& m = CameraManip.getMatrix(); const auto& m = CameraManip.getMatrix();
const auto fov = CameraManip.getFov(); const auto fov = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov) if(refCamMatrix != m || refFov != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -64,12 +64,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -171,7 +171,7 @@ void HelloVulkan::createGraphicsPipeline()
gpb.depthStencilState.depthTestEnable = true; gpb.depthStencilState.depthTestEnable = true;
gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), VK_SHADER_STAGE_VERTEX_BIT); gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), VK_SHADER_STAGE_VERTEX_BIT);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), VK_SHADER_STAGE_FRAGMENT_BIT); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), VK_SHADER_STAGE_FRAGMENT_BIT);
gpb.addBindingDescriptions({{0, sizeof(nvmath::vec3f)}, {1, sizeof(nvmath::vec3f)}, {2, sizeof(nvmath::vec2f)}}); gpb.addBindingDescriptions({{0, sizeof(glm::vec3)}, {1, sizeof(glm::vec3)}, {2, sizeof(glm::vec2)}});
gpb.addAttributeDescriptions({ gpb.addAttributeDescriptions({
{0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0}, // Position {0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0}, // Position
{1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0}, // Normal {1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0}, // Normal
@ -211,14 +211,14 @@ void HelloVulkan::loadScene(const std::string& filename)
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR); | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
m_indexBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_indices, m_indexBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_indices,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR); | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
m_normalBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_normals, m_normalBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_normals,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
| VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT); | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
m_uvBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_texcoords0, m_uvBuffer = m_alloc.createBuffer(cmdBuf, m_gltfScene.m_texcoords0,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
| VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT); | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
// Copying all materials, only the elements we need // Copying all materials, only the elements we need
std::vector<GltfShadeMaterial> shadeMaterials; std::vector<GltfShadeMaterial> shadeMaterials;
@ -246,7 +246,7 @@ void HelloVulkan::loadScene(const std::string& filename)
sceneDesc.materialAddress = nvvk::getBufferDeviceAddress(m_device, m_materialBuffer.buffer); sceneDesc.materialAddress = nvvk::getBufferDeviceAddress(m_device, m_materialBuffer.buffer);
sceneDesc.primInfoAddress = nvvk::getBufferDeviceAddress(m_device, m_primInfo.buffer); sceneDesc.primInfoAddress = nvvk::getBufferDeviceAddress(m_device, m_primInfo.buffer);
m_sceneDesc = m_alloc.createBuffer(cmdBuf, sizeof(SceneDesc), &sceneDesc, m_sceneDesc = m_alloc.createBuffer(cmdBuf, sizeof(SceneDesc), &sceneDesc,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT); VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
// Creates all textures found // Creates all textures found
createTextureImages(cmdBuf, tmodel); createTextureImages(cmdBuf, tmodel);
@ -600,7 +600,7 @@ auto HelloVulkan::primitiveToVkGeometry(const nvh::GltfPrimMesh& prim)
VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR}; VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR};
triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data. triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data.
triangles.vertexData.deviceAddress = vertexAddress; triangles.vertexData.deviceAddress = vertexAddress;
triangles.vertexStride = sizeof(nvmath::vec3f); triangles.vertexStride = sizeof(glm::vec3);
// Describe index data (32-bit unsigned int) // Describe index data (32-bit unsigned int)
triangles.indexType = VK_INDEX_TYPE_UINT32; triangles.indexType = VK_INDEX_TYPE_UINT32;
triangles.indexData.deviceAddress = indexAddress; triangles.indexData.deviceAddress = indexAddress;
@ -688,7 +688,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -830,7 +830,7 @@ void HelloVulkan::createRtPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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(); updateFrame();
@ -864,13 +864,13 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float refFov{CameraManip.getFov()}; static float refFov{CameraManip.getFov()};
const auto& m = CameraManip.getMatrix(); const auto& m = CameraManip.getMatrix();
const auto fov = CameraManip.getFov(); const auto fov = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov) if(refCamMatrix != m || refFov != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -66,12 +66,12 @@ public:
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, // Identity matrix
{0.f, 4.5f, 0.f}, // light position {0.f, 4.5f, 0.f}, // light position
0, // instance Id 0, // instance Id
10.f, // light intensity 10.f, // light intensity
0, // light type 0, // light type
0 // material id 0 // material id
}; };
// Graphic pipeline // Graphic pipeline
@ -117,16 +117,16 @@ public:
void createRtDescriptorSet(); void createRtDescriptorSet();
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor); void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
void updateFrame(); void updateFrame();
void resetFrame(); void resetFrame();
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -93,7 +93,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT);
CameraManip.setLookat(nvmath::vec3f(0, 0, 15), nvmath::vec3f(0, 0, 0), nvmath::vec3f(0, 1, 0)); CameraManip.setLookat(glm::vec3(0, 0, 15), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
// Setup Vulkan // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -183,8 +183,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,13 +22,13 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
#include <stdint.h> /* for uint64_t */ #include <stdint.h> /* for uint64_t */
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -37,6 +37,8 @@
#include "nvvk/shaders_vk.hpp" #include "nvvk/shaders_vk.hpp"
#include "nvvk/buffers_vk.hpp" #include "nvvk/buffers_vk.hpp"
#include <glm/gtc/matrix_access.hpp>
extern std::vector<std::string> defaultSearchPaths; extern std::vector<std::string> defaultSearchPaths;
@ -61,12 +63,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -185,7 +187,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -194,9 +196,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -245,7 +247,7 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
} }
// Add a light-emitting colored lantern to the scene. May only be called before TLAS build. // Add a light-emitting colored lantern to the scene. May only be called before TLAS build.
void HelloVulkan::addLantern(nvmath::vec3f pos, nvmath::vec3f color, float brightness, float radius) void HelloVulkan::addLantern(glm::vec3 pos, glm::vec3 color, float brightness, float radius)
{ {
assert(m_lanternCount == 0); // Indicates TLAS build has not happened yet. assert(m_lanternCount == 0); // Indicates TLAS build has not happened yet.
@ -656,13 +658,13 @@ auto HelloVulkan::objectToVkGeometryKHR(const ObjModel& model)
// Tesselate a sphere as a list of triangles; return its // Tesselate a sphere as a list of triangles; return its
// vertices and indices as reference arguments. // vertices and indices as reference arguments.
void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::vector<uint32_t>& indices) void HelloVulkan::fillLanternVerts(std::vector<glm::vec3>& vertices, std::vector<uint32_t>& indices)
{ {
// Create a spherical lantern model by recursively tesselating an octahedron. // Create a spherical lantern model by recursively tesselating an octahedron.
struct VertexIndex struct VertexIndex
{ {
nvmath::vec3f vertex; glm::vec3 vertex;
uint32_t index; // Keep track of this vert's _eventual_ index in vertices. uint32_t index; // Keep track of this vert's _eventual_ index in vertices.
}; };
struct Triangle struct Triangle
{ {
@ -691,9 +693,9 @@ void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::ve
// Split each of three edges in half, then fixup the // Split each of three edges in half, then fixup the
// length of the midpoint to match m_lanternModelRadius. // length of the midpoint to match m_lanternModelRadius.
// Record the index the new vertices will eventually have in vertices. // Record the index the new vertices will eventually have in vertices.
VertexIndex v01{m_lanternModelRadius * nvmath::normalize(t.vert0.vertex + t.vert1.vertex), vertexCount++}; VertexIndex v01{m_lanternModelRadius * glm::normalize(t.vert0.vertex + t.vert1.vertex), vertexCount++};
VertexIndex v12{m_lanternModelRadius * nvmath::normalize(t.vert1.vertex + t.vert2.vertex), vertexCount++}; VertexIndex v12{m_lanternModelRadius * glm::normalize(t.vert1.vertex + t.vert2.vertex), vertexCount++};
VertexIndex v02{m_lanternModelRadius * nvmath::normalize(t.vert0.vertex + t.vert2.vertex), vertexCount++}; VertexIndex v02{m_lanternModelRadius * glm::normalize(t.vert0.vertex + t.vert2.vertex), vertexCount++};
// Old triangle becomes 4 new triangles. // Old triangle becomes 4 new triangles.
new_triangles.push_back({t.vert0, v01, v02}); new_triangles.push_back({t.vert0, v01, v02});
@ -731,8 +733,8 @@ void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::ve
// concept of intersection shaders here. // concept of intersection shaders here.
void HelloVulkan::createLanternModel() void HelloVulkan::createLanternModel()
{ {
std::vector<nvmath::vec3f> vertices; std::vector<glm::vec3> vertices;
std::vector<uint32_t> indices; std::vector<uint32_t> indices;
fillLanternVerts(vertices, indices); fillLanternVerts(vertices, indices);
// Upload vertex and index data to buffers. // Upload vertex and index data to buffers.
@ -761,7 +763,7 @@ void HelloVulkan::createLanternModel()
VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR}; VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR};
triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data. triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data.
triangles.vertexData.deviceAddress = vertexAddress; triangles.vertexData.deviceAddress = vertexAddress;
triangles.vertexStride = sizeof(nvmath::vec3f); triangles.vertexStride = sizeof(glm::vec3);
// Describe index data (32-bit unsigned int) // Describe index data (32-bit unsigned int)
triangles.indexType = VK_INDEX_TYPE_UINT32; triangles.indexType = VK_INDEX_TYPE_UINT32;
triangles.indexData.deviceAddress = indexAddress; triangles.indexData.deviceAddress = indexAddress;
@ -849,8 +851,8 @@ void HelloVulkan::createTopLevelAS()
for(int i = 0; i < static_cast<int>(m_lanterns.size()); ++i) for(int i = 0; i < static_cast<int>(m_lanterns.size()); ++i)
{ {
VkAccelerationStructureInstanceKHR lanternInstance; VkAccelerationStructureInstanceKHR lanternInstance;
lanternInstance.transform = nvvk::toTransformMatrixKHR(nvmath::translation_mat4(m_lanterns[i].position)); lanternInstance.transform = nvvk::toTransformMatrixKHR(glm::translate(glm::mat4(1), m_lanterns[i].position));
lanternInstance.instanceCustomIndex = i; lanternInstance.instanceCustomIndex = i;
lanternInstance.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(uint32_t(m_lanternBlasId)); lanternInstance.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(uint32_t(m_lanternBlasId));
lanternInstance.instanceShaderBindingTableRecordOffset = 1; // Next hit group is for lanterns. lanternInstance.instanceShaderBindingTableRecordOffset = 1; // Next hit group is for lanterns.
lanternInstance.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR; lanternInstance.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR;
@ -887,7 +889,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -1126,9 +1128,9 @@ void HelloVulkan::createRtShaderBindingTable()
// The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned. // The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned.
uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment); uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment);
m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member
m_missRegion.stride = handleSizeAligned; m_missRegion.stride = handleSizeAligned;
m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_hitRegion.stride = handleSizeAligned; m_hitRegion.stride = handleSizeAligned;
@ -1143,9 +1145,9 @@ void HelloVulkan::createRtShaderBindingTable()
// Allocate a buffer for storing the SBT. // Allocate a buffer for storing the SBT.
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size; VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize, m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); 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. m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
// Find the SBT addresses of each group // Find the SBT addresses of each group
@ -1284,7 +1286,7 @@ void HelloVulkan::createLanternIndirectBuffer()
// effect. This is stored in m_lanternIndirectBuffer. Then an indirect trace rays command // effect. This is stored in m_lanternIndirectBuffer. Then an indirect trace rays command
// is run for every lantern within its scissor rectangle. The lanterns' light // is run for every lantern within its scissor rectangle. The lanterns' light
// contribution is additively blended into the output image. // contribution is additively blended into the output image.
void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor) void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor)
{ {
// Before tracing rays, we need to dispatch the compute shaders that // Before tracing rays, we need to dispatch the compute shaders that
// fill in the ray trace indirect parameters for each lantern pass. // fill in the ray trace indirect parameters for each lantern pass.
@ -1306,10 +1308,10 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
// Bind compute shader, update push constant and descriptors, dispatch compute. // Bind compute shader, update push constant and descriptors, dispatch compute.
vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, m_lanternIndirectCompPipeline); vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, m_lanternIndirectCompPipeline);
nvmath::mat4f view = getViewMatrix(); glm::mat4 view = getViewMatrix();
m_lanternIndirectPushConstants.viewRowX = view.row(0); m_lanternIndirectPushConstants.viewRowX = glm::row(view, 0);
m_lanternIndirectPushConstants.viewRowY = view.row(1); m_lanternIndirectPushConstants.viewRowY = glm::row(view, 1);
m_lanternIndirectPushConstants.viewRowZ = view.row(2); m_lanternIndirectPushConstants.viewRowZ = glm::row(view, 2);
m_lanternIndirectPushConstants.proj = getProjMatrix(); m_lanternIndirectPushConstants.proj = getProjMatrix();
m_lanternIndirectPushConstants.nearZ = nearZ; m_lanternIndirectPushConstants.nearZ = nearZ;
m_lanternIndirectPushConstants.screenX = m_size.width; m_lanternIndirectPushConstants.screenX = m_size.width;
@ -1360,7 +1362,7 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
for(int i = 0; i < static_cast<int>(m_lanternCount); ++i) for(int i = 0; i < static_cast<int>(m_lanternCount); ++i)
{ {
// Barrier to ensure previous pass finished. // Barrier to ensure previous pass finished.
VkImage offscreenImage{m_offscreenColor.image}; VkImage offscreenImage{m_offscreenColor.image};
VkImageSubresourceRange colorRange{VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS}; VkImageSubresourceRange colorRange{VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
VkImageMemoryBarrier imageBarrier{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; VkImageMemoryBarrier imageBarrier{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
imageBarrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL; imageBarrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;

View file

@ -42,20 +42,22 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 addLantern(nvmath::vec3f pos, nvmath::vec3f color, float brightness, float radius); void addLantern(glm::vec3 pos, glm::vec3 color, float brightness, float radius);
void updateDescriptorSet(); void updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
void createTextureImages(const VkCommandBuffer& cmdBuf, const std::vector<std::string>& textures); void createTextureImages(const VkCommandBuffer& cmdBuf, const std::vector<std::string>& textures);
nvmath::mat4f getViewMatrix() { return CameraManip.getMatrix(); } glm::mat4 getViewMatrix() { return CameraManip.getMatrix(); }
static constexpr float nearZ = 0.1f; static constexpr float nearZ = 0.1f;
nvmath::mat4f getProjMatrix() glm::mat4 getProjMatrix()
{ {
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
return nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, nearZ, 1000.0f); glm::mat4 proj = glm::perspectiveRH_ZO(glm::radians(CameraManip.getFov()), aspectRatio, nearZ, 1000.0f);
proj[1][1] *= -1;
return proj;
} }
void updateUniformBuffer(const VkCommandBuffer& cmdBuf); void updateUniformBuffer(const VkCommandBuffer& cmdBuf);
@ -76,27 +78,27 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Information on each colored lantern illuminating the scene. // Information on each colored lantern illuminating the scene.
struct Lantern struct Lantern
{ {
nvmath::vec3f position; glm::vec3 position;
nvmath::vec3f color; glm::vec3 color;
float brightness{0}; float brightness{0};
float radius{0}; // Max world-space distance that light illuminates. float radius{0}; // Max world-space distance that light illuminates.
}; };
// Information on each colored lantern, plus the info needed for dispatching the // Information on each colored lantern, plus the info needed for dispatching the
@ -166,7 +168,7 @@ public:
auto objectToVkGeometryKHR(const ObjModel& model); auto objectToVkGeometryKHR(const ObjModel& model);
private: private:
void fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::vector<uint32_t>& indices); void fillLanternVerts(std::vector<glm::vec3>& vertices, std::vector<uint32_t>& indices);
void createLanternModel(); void createLanternModel();
public: public:
@ -180,7 +182,7 @@ public:
void createRtShaderBindingTable(); void createRtShaderBindingTable();
void createLanternIndirectBuffer(); void createLanternIndirectBuffer();
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor); void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
// Used to store lantern model, generated at runtime. // Used to store lantern model, generated at runtime.
const float m_lanternModelRadius = 0.125; const float m_lanternModelRadius = 0.125;
@ -192,11 +194,11 @@ public:
size_t m_lanternBlasId; size_t m_lanternBlasId;
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;
@ -233,12 +235,12 @@ public:
// Barely fits in 128-byte push constant limit guaranteed by spec. // Barely fits in 128-byte push constant limit guaranteed by spec.
struct LanternIndirectPushConstants struct LanternIndirectPushConstants
{ {
nvmath::vec4f viewRowX; // First 3 rows of view matrix. glm::vec4 viewRowX; // First 3 rows of view matrix.
nvmath::vec4f viewRowY; // Set w=1 implicitly in shader. glm::vec4 viewRowY; // Set w=1 implicitly in shader.
nvmath::vec4f viewRowZ; glm::vec4 viewRowZ;
nvmath::mat4f proj{}; // Perspective matrix glm::mat4 proj{}; // Perspective matrix
float nearZ{}; // Near plane used to create projection matrix. float nearZ{}; // Near plane used to create projection matrix.
// Pixel dimensions of output image (needed to scale NDC to screen coordinates). // Pixel dimensions of output image (needed to scale NDC to screen coordinates).
int32_t screenX{}; int32_t screenX{};

View file

@ -95,7 +95,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -197,8 +197,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -16,7 +16,7 @@
* SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION * SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#version 460 #version 460
#extension GL_GOOGLE_include_directive : enable #extension GL_GOOGLE_include_directive : enable
@ -32,18 +32,22 @@ layout(local_size_x = LOCAL_SIZE, local_size_y = 1, local_size_z = 1) in;
#include "LanternIndirectEntry.glsl" #include "LanternIndirectEntry.glsl"
layout(binding = 0, set = 0) buffer LanternArray { LanternIndirectEntry lanterns[]; } lanterns; layout(binding = 0, set = 0) buffer LanternArray
{
LanternIndirectEntry lanterns[];
}
lanterns;
layout(push_constant) uniform Constants layout(push_constant) uniform Constants
{ {
vec4 viewRowX; vec4 viewRowX;
vec4 viewRowY; vec4 viewRowY;
vec4 viewRowZ; vec4 viewRowZ;
mat4 proj; mat4 proj;
float nearZ; float nearZ;
int screenX; int screenX;
int screenY; int screenY;
int lanternCount; int lanternCount;
} }
pushC; pushC;
@ -60,123 +64,118 @@ void getScreenCoordBox(in LanternIndirectEntry lantern, out ivec2 lower, out ive
void fillIndirectEntry(int i) void fillIndirectEntry(int i)
{ {
LanternIndirectEntry lantern = lanterns.lanterns[i]; LanternIndirectEntry lantern = lanterns.lanterns[i];
ivec2 lower, upper; ivec2 lower, upper;
getScreenCoordBox(lantern, lower, upper); getScreenCoordBox(lantern, lower, upper);
lanterns.lanterns[i].indirectWidth = max(0, upper.x - lower.x); lanterns.lanterns[i].indirectWidth = max(0, upper.x - lower.x);
lanterns.lanterns[i].indirectHeight = max(0, upper.y - lower.y); lanterns.lanterns[i].indirectHeight = max(0, upper.y - lower.y);
lanterns.lanterns[i].indirectDepth = 1; lanterns.lanterns[i].indirectDepth = 1;
lanterns.lanterns[i].offsetX = lower.x; lanterns.lanterns[i].offsetX = lower.x;
lanterns.lanterns[i].offsetY = lower.y; lanterns.lanterns[i].offsetY = lower.y;
} }
void main() void main()
{ {
for (int i = int(gl_LocalInvocationID.x); i < pushC.lanternCount; i += LOCAL_SIZE) for(int i = int(gl_LocalInvocationID.x); i < pushC.lanternCount; i += LOCAL_SIZE)
{ {
fillIndirectEntry(i); fillIndirectEntry(i);
} }
} }
// Functions below modified from the paper. // Functions below modified from the paper.
float square(float a) { return a*a; } float square(float a)
{
return a * a;
}
void getBoundsForAxis( void getBoundsForAxis(in bool xAxis, in vec3 center, in float radius, in float nearZ, in mat4 projMatrix, out vec3 U, out vec3 L)
in bool xAxis, {
in vec3 center, bool trivialAccept = (center.z + radius) < nearZ; // Entirely in back of nearPlane (Trivial Accept)
in float radius, vec3 a = xAxis ? vec3(1, 0, 0) : vec3(0, 1, 0);
in float nearZ,
in mat4 projMatrix,
out vec3 U,
out vec3 L) {
bool trivialAccept = (center.z + radius) < nearZ; // Entirely in back of nearPlane (Trivial Accept)
vec3 a = xAxis ? vec3(1, 0, 0) : vec3(0, 1, 0);
// given in coordinates (a,z), where a is in the direction of the vector a, and z is in the standard z direction // given in coordinates (a,z), where a is in the direction of the vector a, and z is in the standard z direction
vec2 projectedCenter = vec2(dot(a, center), center.z); vec2 projectedCenter = vec2(dot(a, center), center.z);
vec2 bounds_az[2]; vec2 bounds_az[2];
float tSquared = dot(projectedCenter, projectedCenter) - square(radius); float tSquared = dot(projectedCenter, projectedCenter) - square(radius);
float t, cLength, costheta = 0, sintheta = 0; float t, cLength, costheta = 0, sintheta = 0;
if(tSquared > 0) { // Camera is outside sphere if(tSquared > 0)
// Distance to the tangent points of the sphere (points where a vector from the camera are tangent to the sphere) (calculated a-z space) { // Camera is outside sphere
t = sqrt(tSquared); // Distance to the tangent points of the sphere (points where a vector from the camera are tangent to the sphere) (calculated a-z space)
cLength = length(projectedCenter); t = sqrt(tSquared);
cLength = length(projectedCenter);
// Theta is the angle between the vector from the camera to the center of the sphere and the vectors from the camera to the tangent points // Theta is the angle between the vector from the camera to the center of the sphere and the vectors from the camera to the tangent points
costheta = t / cLength; costheta = t / cLength;
sintheta = radius / cLength; sintheta = radius / cLength;
}
float sqrtPart = 0.0f;
if(!trivialAccept)
sqrtPart = sqrt(square(radius) - square(nearZ - projectedCenter.y));
for(int i = 0; i < 2; ++i)
{
if(tSquared > 0)
{
float x = costheta * projectedCenter.x + -sintheta * projectedCenter.y;
float y = sintheta * projectedCenter.x + costheta * projectedCenter.y;
bounds_az[i] = costheta * vec2(x, y);
} }
float sqrtPart = 0.0f;
if(!trivialAccept) sqrtPart = sqrt(square(radius) - square(nearZ - projectedCenter.y));
for(int i = 0; i < 2; ++i){ if(!trivialAccept && (tSquared <= 0 || bounds_az[i].y > nearZ))
if(tSquared > 0) { {
float x = costheta * projectedCenter.x + -sintheta * projectedCenter.y; bounds_az[i].x = projectedCenter.x + sqrtPart;
float y = sintheta * projectedCenter.x + costheta * projectedCenter.y; bounds_az[i].y = nearZ;
bounds_az[i] = costheta * vec2(x, y);
}
if(!trivialAccept && (tSquared <= 0 || bounds_az[i].y > nearZ)) {
bounds_az[i].x = projectedCenter.x + sqrtPart;
bounds_az[i].y = nearZ;
}
sintheta *= -1; // negate theta for B
sqrtPart *= -1; // negate sqrtPart for B
} }
U = bounds_az[0].x * a; sintheta *= -1; // negate theta for B
U.z = bounds_az[0].y; sqrtPart *= -1; // negate sqrtPart for B
L = bounds_az[1].x * a; }
L.z = bounds_az[1].y; U = bounds_az[0].x * a;
U.z = bounds_az[0].y;
L = bounds_az[1].x * a;
L.z = bounds_az[1].y;
} }
/** Center is in camera space */ /** Center is in camera space */
void getBoundingBox( void getBoundingBox(in vec3 center, in float radius, in float nearZ, in mat4 projMatrix, out vec2 ndc_low, out vec2 ndc_high)
in vec3 center, {
in float radius, vec3 maxXHomogenous, minXHomogenous, maxYHomogenous, minYHomogenous;
in float nearZ, getBoundsForAxis(true, center, radius, nearZ, projMatrix, maxXHomogenous, minXHomogenous);
in mat4 projMatrix, getBoundsForAxis(false, center, radius, nearZ, projMatrix, maxYHomogenous, minYHomogenous);
out vec2 ndc_low,
out vec2 ndc_high) {
vec3 maxXHomogenous, minXHomogenous, maxYHomogenous, minYHomogenous;
getBoundsForAxis(true, center, radius, nearZ, projMatrix, maxXHomogenous, minXHomogenous);
getBoundsForAxis(false, center, radius, nearZ, projMatrix, maxYHomogenous, minYHomogenous);
vec4 projRow0 = vec4(projMatrix[0][0], projMatrix[1][0], projMatrix[2][0], projMatrix[3][0]); vec4 projRow0 = vec4(projMatrix[0][0], projMatrix[1][0], projMatrix[2][0], projMatrix[3][0]);
vec4 projRow1 = vec4(projMatrix[0][1], projMatrix[1][1], projMatrix[2][1], projMatrix[3][1]); vec4 projRow1 = vec4(projMatrix[0][1], projMatrix[1][1], projMatrix[2][1], projMatrix[3][1]);
vec4 projRow3 = vec4(projMatrix[0][3], projMatrix[1][3], projMatrix[2][3], projMatrix[3][3]); vec4 projRow3 = vec4(projMatrix[0][3], projMatrix[1][3], projMatrix[2][3], projMatrix[3][3]);
// We only need one coordinate for each point, so we save computation by only calculating x(or y) and w // We only need one coordinate for each point, so we save computation by only calculating x(or y) and w
float maxX_w = dot(vec4(maxXHomogenous, 1.0f), projRow3); float maxX_w = dot(vec4(maxXHomogenous, 1.0f), projRow3);
float minX_w = dot(vec4(minXHomogenous, 1.0f), projRow3); float minX_w = dot(vec4(minXHomogenous, 1.0f), projRow3);
float maxY_w = dot(vec4(maxYHomogenous, 1.0f), projRow3); float maxY_w = dot(vec4(maxYHomogenous, 1.0f), projRow3);
float minY_w = dot(vec4(minYHomogenous, 1.0f), projRow3); float minY_w = dot(vec4(minYHomogenous, 1.0f), projRow3);
float maxX = dot(vec4(maxXHomogenous, 1.0f), projRow0) / maxX_w; float maxX = dot(vec4(maxXHomogenous, 1.0f), projRow0) / maxX_w;
float minX = dot(vec4(minXHomogenous, 1.0f), projRow0) / minX_w; float minX = dot(vec4(minXHomogenous, 1.0f), projRow0) / minX_w;
float maxY = dot(vec4(maxYHomogenous, 1.0f), projRow1) / maxY_w; float maxY = dot(vec4(maxYHomogenous, 1.0f), projRow1) / maxY_w;
float minY = dot(vec4(minYHomogenous, 1.0f), projRow1) / minY_w; float minY = dot(vec4(minYHomogenous, 1.0f), projRow1) / minY_w;
// Paper minX, etc. names are misleading, not necessarily min. Fix here. // Paper minX, etc. names are misleading, not necessarily min. Fix here.
ndc_low = vec2(min(minX, maxX), min(minY, maxY)); ndc_low = vec2(min(minX, maxX), min(minY, maxY));
ndc_high = vec2(max(minX, maxX), max(minY, maxY)); ndc_high = vec2(max(minX, maxX), max(minY, maxY));
} }
void getScreenCoordBox(in LanternIndirectEntry lantern, out ivec2 lower, out ivec2 upper) void getScreenCoordBox(in LanternIndirectEntry lantern, out ivec2 lower, out ivec2 upper)
{ {
vec4 lanternWorldCenter = vec4(lantern.x, lantern.y, lantern.z, 1); vec4 lanternWorldCenter = vec4(lantern.x, lantern.y, lantern.z, 1);
vec3 center = vec3( vec3 center = vec3(dot(pushC.viewRowX, lanternWorldCenter), dot(pushC.viewRowY, lanternWorldCenter),
dot(pushC.viewRowX, lanternWorldCenter), dot(pushC.viewRowZ, lanternWorldCenter));
dot(pushC.viewRowY, lanternWorldCenter), vec2 ndc_low, ndc_high;
dot(pushC.viewRowZ, lanternWorldCenter)); float paperNearZ = -abs(pushC.nearZ); // Paper expected negative nearZ, took 2 days to figure out!
vec2 ndc_low, ndc_high;
float paperNearZ = -abs(pushC.nearZ); // Paper expected negative nearZ, took 2 days to figure out!
getBoundingBox(center, lantern.radius, paperNearZ, pushC.proj, ndc_low, ndc_high); getBoundingBox(center, lantern.radius, paperNearZ, pushC.proj, ndc_low, ndc_high);
// Convert NDC [-1,+1]^2 coordinates to screen coordinates, and clamp to stay in bounds. // Convert NDC [-1,+1]^2 coordinates to screen coordinates, and clamp to stay in bounds.
lower.x = clamp(int((ndc_low.x * 0.5 + 0.5) * pushC.screenX), 0, pushC.screenX); lower.x = clamp(int((ndc_low.x * 0.5 + 0.5) * pushC.screenX), 0, pushC.screenX);
lower.y = clamp(int((ndc_low.y * 0.5 + 0.5) * pushC.screenY), 0, pushC.screenY); lower.y = clamp(int((ndc_low.y * 0.5 + 0.5) * pushC.screenY), 0, pushC.screenY);
upper.x = clamp(int((ndc_high.x * 0.5 + 0.5) * pushC.screenX), 0, pushC.screenX); upper.x = clamp(int((ndc_high.x * 0.5 + 0.5) * pushC.screenX), 0, pushC.screenX);
upper.y = clamp(int((ndc_high.y * 0.5 + 0.5) * pushC.screenY), 0, pushC.screenY); upper.y = clamp(int((ndc_high.y * 0.5 + 0.5) * pushC.screenY), 0, pushC.screenY);
} }

View file

@ -42,10 +42,10 @@ Then replace the calls to `helloVk.loadModel` in `main()` by following, which wi
for(uint32_t n = 0; n < 2000; ++n) for(uint32_t n = 0; n < 2000; ++n)
{ {
float scale = fabsf(disn(gen)); float scale = fabsf(disn(gen));
nvmath::mat4f mat = glm::mat4 mat =
nvmath::translation_mat4(nvmath::vec3f{dis(gen), 2.0f + dis(gen), dis(gen)}); glm::translate(glm::mat4(1),glm::vec3{dis(gen), 2.0f + dis(gen), dis(gen)});
mat = mat * nvmath::rotation_mat4_x(dis(gen)); mat = mat * glm::rotation_mat4_x(dis(gen));
mat = mat * nvmath::scale_mat4(nvmath::vec3f(scale)); mat = mat * glm::scale(glm::mat4(1.f),glm::vec3(scale));
helloVk.m_instances.push_back({mat, n % 2}); helloVk.m_instances.push_back({mat, n % 2});
} }
~~~~ ~~~~
@ -69,9 +69,9 @@ Remove the previous code and replace it with the following
for(int n = 0; n < 2000; ++n) for(int n = 0; n < 2000; ++n)
{ {
float scale = fabsf(disn(gen)); float scale = fabsf(disn(gen));
nvmath::mat4f mat = nvmath::translation_mat4(nvmath::vec3f{dis(gen), 2.0f + dis(gen), dis(gen)}); glm::mat4 mat = glm::translate(glm::mat4(1),glm::vec3{dis(gen), 2.0f + dis(gen), dis(gen)});
mat = mat * nvmath::rotation_mat4_x(dis(gen)); mat = mat * glm::rotation_mat4_x(dis(gen));
mat = mat * nvmath::scale_mat4(nvmath::vec3f(scale)); mat = mat * glm::scale(glm::mat4(1.f),glm::vec3(scale));
helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true), mat); helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true), mat);
} }

View file

@ -63,12 +63,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -187,7 +187,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -196,9 +196,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -703,7 +703,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -845,7 +845,7 @@ void HelloVulkan::createRtPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -60,7 +60,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -83,18 +83,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -150,15 +150,15 @@ public:
void createRtDescriptorSet(); void createRtDescriptorSet();
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); 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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -121,7 +121,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -195,10 +195,10 @@ int main(int argc, char** argv)
std::normal_distribution<float> disn(0.05f, 0.05f); std::normal_distribution<float> disn(0.05f, 0.05f);
for(uint32_t n = 0; n < 2000; ++n) for(uint32_t n = 0; n < 2000; ++n)
{ {
float scale = fabsf(disn(gen)); float scale = fabsf(disn(gen));
nvmath::mat4f mat = nvmath::translation_mat4(nvmath::vec3f{dis(gen), 2.0f + dis(gen), dis(gen)}); glm::mat4 mat = glm::translate(glm::mat4(1), glm::vec3{dis(gen), 2.0f + dis(gen), dis(gen)});
mat = mat * nvmath::rotation_mat4_x(dis(gen)); mat = mat * glm::rotate(glm::mat4(1.f), dis(gen), glm::vec3(1.f, 0.f, 0.f));
mat = mat * nvmath::scale_mat4(nvmath::vec3f(scale)); mat = mat * glm::scale(glm::mat4(1.f), glm::vec3(scale));
helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true), mat); helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true), mat);
} }
@ -227,8 +227,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -92,7 +92,7 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
for(uint32_t i = 0; i < nbSpheres; i++) for(uint32_t i = 0; i < nbSpheres; i++)
{ {
Sphere s; 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); s.radius = radd(gen);
m_spheres[i] = std::move(s); m_spheres[i] = std::move(s);
} }
@ -103,18 +103,18 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
for(const auto& s : m_spheres) for(const auto& s : m_spheres)
{ {
Aabb aabb; Aabb aabb;
aabb.minimum = s.center - nvmath::vec3f(s.radius); aabb.minimum = s.center - glm::vec3(s.radius);
aabb.maximum = s.center + nvmath::vec3f(s.radius); aabb.maximum = s.center + glm::vec3(s.radius);
aabbs.emplace_back(aabb); aabbs.emplace_back(aabb);
} }
// Creating two materials // Creating two materials
MaterialObj mat; MaterialObj mat;
mat.diffuse = nvmath::vec3f(0, 1, 1); mat.diffuse = glm::vec3(0, 1, 1);
std::vector<MaterialObj> materials; std::vector<MaterialObj> materials;
std::vector<int> matIdx(nbSpheres); std::vector<int> matIdx(nbSpheres);
materials.emplace_back(mat); materials.emplace_back(mat);
mat.diffuse = nvmath::vec3f(1, 1, 0); mat.diffuse = glm::vec3(1, 1, 0);
materials.emplace_back(mat); materials.emplace_back(mat);
// Assign a material to each sphere // Assign a material to each sphere
@ -214,7 +214,7 @@ In `main.cpp`, where we are loading the OBJ model, we can replace it with
The scene will be large, better to move the camera out The scene will be large, better to move the camera out
~~~~ C++ ~~~~ C++
CameraManip.setLookat(nvmath::vec3f(20, 20, 20), nvmath::vec3f(0, 1, 0), nvmath::vec3f(0, 1, 0)); CameraManip.setLookat(glm::vec3(20, 20, 20), glm::vec3(0, 1, 0), glm::vec3(0, 1, 0));
~~~~ ~~~~
## Acceleration Structures ## Acceleration Structures
@ -272,7 +272,7 @@ Just after the loop and before building the TLAS, we need to add the following.
// Add the blas containing all implicit objects // Add the blas containing all implicit objects
{ {
VkAccelerationStructureInstanceKHR rayInst{}; VkAccelerationStructureInstanceKHR rayInst{};
rayInst.transform = nvvk::toTransformMatrixKHR(nvmath::mat4f(1)); // Position of the instance (identity) rayInst.transform = nvvk::toTransformMatrixKHR(glm::mat4(1)); // Position of the instance (identity)
rayInst.instanceCustomIndex = nbObj; // nbObj == last object == implicit rayInst.instanceCustomIndex = nbObj; // nbObj == last object == implicit
rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(m_objModel.size())); rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(m_objModel.size()));
rayInst.instanceShaderBindingTableRecordOffset = 1; // We will use the same hit group for all objects rayInst.instanceShaderBindingTableRecordOffset = 1; // We will use the same hit group for all objects

View file

@ -62,12 +62,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -192,7 +192,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -201,9 +201,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -698,7 +698,7 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
for(uint32_t i = 0; i < nbSpheres; i++) for(uint32_t i = 0; i < nbSpheres; i++)
{ {
Sphere s; 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); s.radius = radd(gen);
m_spheres[i] = std::move(s); m_spheres[i] = std::move(s);
} }
@ -709,18 +709,18 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
for(const auto& s : m_spheres) for(const auto& s : m_spheres)
{ {
Aabb aabb; Aabb aabb;
aabb.minimum = s.center - nvmath::vec3f(s.radius); aabb.minimum = s.center - glm::vec3(s.radius);
aabb.maximum = s.center + nvmath::vec3f(s.radius); aabb.maximum = s.center + glm::vec3(s.radius);
aabbs.emplace_back(aabb); aabbs.emplace_back(aabb);
} }
// Creating two materials // Creating two materials
MaterialObj mat; MaterialObj mat;
mat.diffuse = nvmath::vec3f(0, 1, 1); mat.diffuse = glm::vec3(0, 1, 1);
std::vector<MaterialObj> materials; std::vector<MaterialObj> materials;
std::vector<int> matIdx(nbSpheres); std::vector<int> matIdx(nbSpheres);
materials.emplace_back(mat); materials.emplace_back(mat);
mat.diffuse = nvmath::vec3f(1, 1, 0); mat.diffuse = glm::vec3(1, 1, 0);
materials.emplace_back(mat); materials.emplace_back(mat);
// Assign a material to each sphere // Assign a material to each sphere
@ -735,8 +735,8 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
auto cmdBuf = genCmdBuf.createCommandBuffer(); auto cmdBuf = genCmdBuf.createCommandBuffer();
m_spheresBuffer = m_alloc.createBuffer(cmdBuf, m_spheres, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); m_spheresBuffer = m_alloc.createBuffer(cmdBuf, m_spheres, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
m_spheresAabbBuffer = m_alloc.createBuffer(cmdBuf, aabbs, m_spheresAabbBuffer = m_alloc.createBuffer(cmdBuf, aabbs,
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR); | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
m_spheresMatIndexBuffer = m_spheresMatIndexBuffer =
m_alloc.createBuffer(cmdBuf, matIdx, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT); m_alloc.createBuffer(cmdBuf, matIdx, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
m_spheresMatColorBuffer = m_spheresMatColorBuffer =
@ -812,7 +812,7 @@ void HelloVulkan::createTopLevelAS()
// Add the blas containing all implicit objects // Add the blas containing all implicit objects
{ {
VkAccelerationStructureInstanceKHR rayInst{}; 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.instanceCustomIndex = nbObj; // nbObj == last object == implicit
rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(m_objModel.size())); rayInst.accelerationStructureReference = m_rtBuilder.getBlasDeviceAddress(static_cast<uint32_t>(m_objModel.size()));
rayInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR; rayInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR;
@ -846,7 +846,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -1025,9 +1025,9 @@ void HelloVulkan::createRtShaderBindingTable()
// Allocate a buffer for storing the SBT. // Allocate a buffer for storing the SBT.
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size; VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize, m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); 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. m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
// Find the SBT addresses of each group // Find the SBT addresses of each group
@ -1069,7 +1069,7 @@ void HelloVulkan::createRtShaderBindingTable()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -42,7 +42,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -65,18 +65,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, // Identity matrix
{10.f, 55.f, 8.f}, // light position {10.f, 55.f, 8.f}, // light position
0, // instance Id 0, // instance Id
1000.f, // light intensity 1000.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -132,15 +132,15 @@ public:
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void createRtShaderBindingTable(); void createRtShaderBindingTable();
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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -94,7 +94,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT);
CameraManip.setLookat(nvmath::vec3f(20, 20, 20), nvmath::vec3f(0, 1, 0), nvmath::vec3f(0, 1, 0)); CameraManip.setLookat(glm::vec3(20, 20, 20), glm::vec3(0, 1, 0), glm::vec3(0, 1, 0));
// Setup Vulkan // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -186,8 +186,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -69,7 +69,8 @@ void main()
vec3 absN = abs(worldNrm); vec3 absN = abs(worldNrm);
float maxC = max(max(absN.x, absN.y), absN.z); float maxC = max(max(absN.x, absN.y), absN.z);
worldNrm = (maxC == absN.x) ? vec3(sign(worldNrm.x), 0, 0) : worldNrm = (maxC == absN.x) ? vec3(sign(worldNrm.x), 0, 0) :
(maxC == absN.y) ? vec3(0, sign(worldNrm.y), 0) : vec3(0, 0, sign(worldNrm.z)); (maxC == absN.y) ? vec3(0, sign(worldNrm.y), 0) :
vec3(0, 0, sign(worldNrm.z));
} }
// Vector toward the light // Vector toward the light

View file

@ -138,13 +138,13 @@ The implementation of `updateFrame` resets the frame counter if the camera has c
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float refFov{CameraManip.getFov()}; static float refFov{CameraManip.getFov()};
const auto& m = CameraManip.getMatrix(); const auto& m = CameraManip.getMatrix();
const auto fov = CameraManip.getFov(); const auto fov = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov) if(refCamMatrix != m || refFov != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -61,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -185,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -194,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -701,7 +701,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -853,9 +853,9 @@ void HelloVulkan::createRtShaderBindingTable()
// The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned. // The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned.
uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment); uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment);
m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member
m_missRegion.stride = handleSizeAligned; m_missRegion.stride = handleSizeAligned;
m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_hitRegion.stride = handleSizeAligned; m_hitRegion.stride = handleSizeAligned;
@ -870,9 +870,9 @@ void HelloVulkan::createRtShaderBindingTable()
// Allocate a buffer for storing the SBT. // Allocate a buffer for storing the SBT.
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size; VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize, m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); 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. m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
// Find the SBT addresses of each group // Find the SBT addresses of each group
@ -914,7 +914,7 @@ void HelloVulkan::createRtShaderBindingTable()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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(); updateFrame();
if(m_pcRay.frame >= m_maxFrames) if(m_pcRay.frame >= m_maxFrames)
@ -950,13 +950,13 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float refFov{CameraManip.getFov()}; static float refFov{CameraManip.getFov()};
const auto& m = CameraManip.getMatrix(); const auto& m = CameraManip.getMatrix();
const auto fov = CameraManip.getFov(); const auto fov = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov) if(refCamMatrix != m || refFov != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -42,7 +42,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -65,18 +65,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -132,16 +132,16 @@ public:
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void createRtShaderBindingTable(); void createRtShaderBindingTable();
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor); void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
void resetFrame(); void resetFrame();
void updateFrame(); void updateFrame();
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -100,7 +100,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT);
CameraManip.setLookat(nvmath::vec3f(4, 4, 4), nvmath::vec3f(0, 1, 0), nvmath::vec3f(0, 1, 0)); CameraManip.setLookat(glm::vec3(4, 4, 4), glm::vec3(0, 1, 0), glm::vec3(0, 1, 0));
// Setup Vulkan // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -189,8 +189,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -19,9 +19,9 @@ Then you can change the `helloVk.loadModel` calls to the following:
~~~~ C++ ~~~~ C++
// Creation of the example // Creation of the example
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(-1, 0, 0))); glm::translate(glm::mat4(1),glm::vec3(-1, 0, 0)));
helloVk.m_instances.push_back({nvmath::translation_mat4(nvmath::vec3f(1, 0, 0)), 0}); // Adding an instance of the Wuson helloVk.m_instances.push_back({glm::translate(glm::mat4(1),glm::vec3(1, 0, 0)), 0}); // Adding an instance of the Wuson
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true));
~~~~ ~~~~
@ -98,7 +98,7 @@ In the `ObjInstance` structure, we will add a new member `hitgroup` variable tha
~~~~ C++ ~~~~ C++
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
int hitgroup{0}; // Hit group of the instance int hitgroup{0}; // Hit group of the instance
}; };
@ -145,7 +145,7 @@ In the HelloVulkan class, we will add a structure to hold the hit group data.
~~~~ C++ ~~~~ C++
struct HitRecordBuffer struct HitRecordBuffer
{ {
nvmath::vec4f color; glm::vec4 color;
}; };
std::vector<HitRecordBuffer> m_hitShaderRecord; std::vector<HitRecordBuffer> m_hitShaderRecord;
~~~~ ~~~~
@ -176,7 +176,7 @@ In `main`, after we set which hit group an instance will use, we can add the dat
~~~~ C++ ~~~~ C++
helloVk.m_hitShaderRecord.resize(1); helloVk.m_hitShaderRecord.resize(1);
helloVk.m_hitShaderRecord[0].color = nvmath::vec4f(1, 1, 0, 0); // Yellow helloVk.m_hitShaderRecord[0].color = glm::vec4(1, 1, 0, 0); // Yellow
~~~~ ~~~~
### `HelloVulkan::createRtShaderBindingTable` ### `HelloVulkan::createRtShaderBindingTable`
@ -244,8 +244,8 @@ In the description of the scene in `main`, we will tell the `wuson` models to us
~~~~ C++ ~~~~ C++
// Hit shader record info // Hit shader record info
helloVk.m_hitShaderRecord.resize(2); helloVk.m_hitShaderRecord.resize(2);
helloVk.m_hitShaderRecord[0].color = nvmath::vec4f(0, 1, 0, 0); // Green helloVk.m_hitShaderRecord[0].color = glm::vec4(0, 1, 0, 0); // Green
helloVk.m_hitShaderRecord[1].color = nvmath::vec4f(0, 1, 1, 0); // Cyan helloVk.m_hitShaderRecord[1].color = glm::vec4(0, 1, 1, 0); // Cyan
helloVk.m_instances[0].hitgroup = 1; // wuson 0 helloVk.m_instances[0].hitgroup = 1; // wuson 0
helloVk.m_instances[1].hitgroup = 2; // wuson 1 helloVk.m_instances[1].hitgroup = 2; // wuson 1
~~~~ ~~~~

View file

@ -61,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -185,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -194,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -708,7 +708,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -901,9 +901,9 @@ void HelloVulkan::createRtShaderBindingTable()
// Allocate a buffer for storing the SBT. // Allocate a buffer for storing the SBT.
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size; VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize, m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); 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. m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
// Find the SBT addresses of each group // Find the SBT addresses of each group
@ -956,7 +956,7 @@ void HelloVulkan::createRtShaderBindingTable()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -48,7 +48,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -71,19 +71,19 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
int hitgroup{0}; // Hit group of the instance int hitgroup{0}; // Hit group of the instance
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -139,15 +139,15 @@ public:
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void createRtShaderBindingTable(); void createRtShaderBindingTable();
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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;
@ -167,7 +167,7 @@ public:
struct HitRecordBuffer struct HitRecordBuffer
{ {
nvmath::vec4f color; glm::vec4 color;
}; };
std::vector<HitRecordBuffer> m_hitShaderRecord; std::vector<HitRecordBuffer> m_hitShaderRecord;
}; };

View file

@ -160,20 +160,20 @@ int main(int argc, char** argv)
// Creation of the example // Creation of the example
helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/wuson.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(-1, 0, 0))); glm::translate(glm::mat4(1), glm::vec3(-1, 0, 0)));
helloVk.m_instances.push_back({nvmath::translation_mat4(nvmath::vec3f(1, 0, 0)), 0}); // Adding an instance of the Wuson helloVk.m_instances.push_back({glm::translate(glm::mat4(1), glm::vec3(1, 0, 0)), 0}); // Adding an instance of the Wuson
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true));
// Hit shader record info // Hit shader record info
helloVk.m_hitShaderRecord.resize(2); helloVk.m_hitShaderRecord.resize(2);
helloVk.m_hitShaderRecord[0].color = nvmath::vec4f(0, 1, 0, 0); // Green helloVk.m_hitShaderRecord[0].color = glm::vec4(0, 1, 0, 0); // Green
helloVk.m_hitShaderRecord[1].color = nvmath::vec4f(0, 1, 1, 0); // Cyan helloVk.m_hitShaderRecord[1].color = glm::vec4(0, 1, 1, 0); // Cyan
helloVk.m_instances[0].hitgroup = 1; // Wuson 0 helloVk.m_instances[0].hitgroup = 1; // Wuson 0
helloVk.m_instances[1].hitgroup = 2; // Wuson 1 helloVk.m_instances[1].hitgroup = 2; // Wuson 1
helloVk.m_instances[2].hitgroup = 0; // Plane helloVk.m_instances[2].hitgroup = 0; // Plane
helloVk.createOffscreenRender(); helloVk.createOffscreenRender();
helloVk.createDescriptorSetLayout(); helloVk.createDescriptorSetLayout();
@ -195,8 +195,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -142,8 +142,8 @@ The motion matrix must fill the structure [`VkAccelerationStructureMatrixMotionI
objId = 0; objId = 0;
{ {
// Position of the instance at T0 and T1 // Position of the instance at T0 and T1
nvmath::mat4f matT0 = m_instances[0].transform; glm::mat4 matT0 = m_instances[0].transform;
nvmath::mat4f matT1 = nvmath::translation_mat4(nvmath::vec3f(0.30f, 0.0f, 0.0f)) * matT0; glm::mat4 matT1 = glm::translate(glm::mat4(1),glm::vec3(0.30f, 0.0f, 0.0f)) * matT0;
VkAccelerationStructureMatrixMotionInstanceNV data; VkAccelerationStructureMatrixMotionInstanceNV data;
data.transformT0 = nvvk::toTransformMatrixKHR(matT0); data.transformT0 = nvvk::toTransformMatrixKHR(matT0);
@ -169,7 +169,7 @@ where it interpolates between two structures [`VkSRTDataNV`](https://www.khronos
// Cube (moving/SRT rotation) // Cube (moving/SRT rotation)
objId = 0; objId = 0;
{ {
nvmath::quatf rot; glm::quatf rot;
rot.from_euler_xyz({0, 0, 0}); rot.from_euler_xyz({0, 0, 0});
// Position of the instance at T0 and T1 // Position of the instance at T0 and T1
VkSRTDataNV matT0{}; // Translated to 0,0,2 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.qz = rot.z;
matT0.qw = rot.w; matT0.qw = rot.w;
VkSRTDataNV matT1 = matT0; // Setting a rotation 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.qx = rot.x;
matT1.qy = rot.y; matT1.qy = rot.y;
matT1.qz = rot.z; matT1.qz = rot.z;
@ -213,7 +213,7 @@ First the plane is not moving at all
// Plane (static) // Plane (static)
objId = 1; objId = 1;
{ {
nvmath::mat4f matT0 = m_instances[1].transform; glm::mat4 matT0 = m_instances[1].transform;
VkAccelerationStructureInstanceKHR data{}; VkAccelerationStructureInstanceKHR data{};
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance 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) // Cube+Cubemodif (static)
objId = 2; objId = 2;
{ {
nvmath::mat4f matT0 = m_instances[2].transform; glm::mat4 matT0 = m_instances[2].transform;
VkAccelerationStructureInstanceKHR data{}; VkAccelerationStructureInstanceKHR data{};
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance

View file

@ -20,6 +20,7 @@
#include <sstream> #include <sstream>
#include <glm/gtc/quaternion.hpp>
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "obj_loader.h" #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); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -184,7 +185,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -193,9 +194,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -684,8 +685,8 @@ void HelloVulkan::createTopLevelAS()
objId = 0; objId = 0;
{ {
// Position of the instance at T0 and T1 // Position of the instance at T0 and T1
nvmath::mat4f matT0 = m_instances[0].transform; glm::mat4 matT0 = m_instances[0].transform;
nvmath::mat4f matT1 = nvmath::translation_mat4(nvmath::vec3f(0.30f, 0.0f, 0.0f)) * matT0; glm::mat4 matT1 = glm::translate(glm::mat4(1), glm::vec3(0.30f, 0.0f, 0.0f)) * matT0;
VkAccelerationStructureMatrixMotionInstanceNV data; VkAccelerationStructureMatrixMotionInstanceNV data;
data.transformT0 = nvvk::toTransformMatrixKHR(matT0); data.transformT0 = nvvk::toTransformMatrixKHR(matT0);
@ -705,24 +706,25 @@ void HelloVulkan::createTopLevelAS()
objId = 0; objId = 0;
{ {
// m_instance[3].transform -> no matrix to SRT // m_instance[3].transform -> no matrix to SRT
nvmath::quatf rot; glm::quat rot = {};
rot.from_euler_xyz({0, 0, 0});
// Position of the instance at T0 and T1 // Position of the instance at T0 and T1
VkSRTDataNV matT0{}; // Translated to 0,0,2 VkSRTDataNV matT0{}; // Translated to 0,0,2
matT0.sx = 1.0f; matT0.sx = 1.0f;
matT0.sy = 1.0f; matT0.sy = 1.0f;
matT0.sz = 1.0f; matT0.sz = 1.0f;
matT0.tz = 2.0f; matT0.tz = 2.0f;
matT0.qx = rot.x; matT0.qx = rot.x;
matT0.qy = rot.y; matT0.qy = rot.y;
matT0.qz = rot.z; matT0.qz = rot.z;
matT0.qw = rot.w; matT0.qw = rot.w;
VkSRTDataNV matT1 = matT0; // Setting a rotation VkSRTDataNV matT1 = matT0; // Setting a rotation
rot.from_euler_xyz({deg2rad(10.0f), deg2rad(30.0f), 0.0f}); rot = glm::quat(glm::vec3(glm::radians(10.0f), glm::radians(30.0f), 0.0f));
matT1.qx = rot.x; matT1.qx = rot.x;
matT1.qy = rot.y; matT1.qy = rot.y;
matT1.qz = rot.z; matT1.qz = rot.z;
matT1.qw = rot.w; matT1.qw = rot.w;
VkAccelerationStructureSRTMotionInstanceNV data{}; VkAccelerationStructureSRTMotionInstanceNV data{};
data.transformT0 = matT0; data.transformT0 = matT0;
@ -741,7 +743,7 @@ void HelloVulkan::createTopLevelAS()
// Plane (static) // Plane (static)
objId = 1; objId = 1;
{ {
nvmath::mat4f matT0 = m_instances[1].transform; glm::mat4 matT0 = m_instances[1].transform;
VkAccelerationStructureInstanceKHR data{}; VkAccelerationStructureInstanceKHR data{};
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance
@ -760,7 +762,7 @@ void HelloVulkan::createTopLevelAS()
// Cube+Cubemodif (static) // Cube+Cubemodif (static)
objId = 2; objId = 2;
{ {
nvmath::mat4f matT0 = m_instances[2].transform; glm::mat4 matT0 = m_instances[2].transform;
VkAccelerationStructureInstanceKHR data{}; VkAccelerationStructureInstanceKHR data{};
data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance data.transform = nvvk::toTransformMatrixKHR(matT0); // Position of the instance
@ -800,7 +802,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; 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. // 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. // The order of handles follow the stage entry.
std::vector<uint8_t> shaderHandleStorage(sbtSize); 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); assert(result == VK_SUCCESS);
@ -984,7 +986,7 @@ void HelloVulkan::createRtShaderBindingTable()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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(); updateFrame();
if(m_pcRay.frame >= m_maxFrames) if(m_pcRay.frame >= m_maxFrames)
@ -1032,13 +1034,13 @@ void HelloVulkan::raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& c
// //
void HelloVulkan::updateFrame() void HelloVulkan::updateFrame()
{ {
static nvmath::mat4f refCamMatrix; static glm::mat4 refCamMatrix;
static float refFov{CameraManip.getFov()}; static float refFov{CameraManip.getFov()};
const auto& m = CameraManip.getMatrix(); const auto& m = CameraManip.getMatrix();
const auto fov = CameraManip.getFov(); const auto fov = CameraManip.getFov();
if(memcmp(&refCamMatrix.a00, &m.a00, sizeof(nvmath::mat4f)) != 0 || refFov != fov) if(refCamMatrix != m || refFov != fov)
{ {
resetFrame(); resetFrame();
refCamMatrix = m; refCamMatrix = m;

View file

@ -42,7 +42,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -66,18 +66,18 @@ public:
// Instance of the OBJ // Instance of the OBJ
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {9.5f, 5.5f, -6.5f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -133,17 +133,17 @@ public:
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void createRtShaderBindingTable(); void createRtShaderBindingTable();
void raytrace(const VkCommandBuffer& cmdBuf, const nvmath::vec4f& clearColor); void raytrace(const VkCommandBuffer& cmdBuf, const glm::vec4& clearColor);
void updateFrame(); void updateFrame();
void resetFrame(); void resetFrame();
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -183,10 +183,10 @@ int main(int argc, char** argv)
helloVk.loadModel(nvh::findFile("media/scenes/cube_modif.obj", defaultSearchPaths, true)); 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 // 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[1].transform = glm::translate(glm::mat4(1), glm::vec3(0, -1, 0));
helloVk.m_instances[2].transform = nvmath::translation_mat4(nvmath::vec3f(2, 0, 2)); 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].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(); helloVk.createOffscreenRender();
@ -209,8 +209,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -61,12 +61,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -145,7 +145,7 @@ void HelloVulkan::updateDescriptorSet()
} }
writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, SceneBindings::eTextures, diit.data())); writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, SceneBindings::eTextures, diit.data()));
VkAccelerationStructureKHR tlas = m_rtBuilder.getAccelerationStructure(); VkAccelerationStructureKHR tlas = m_rtBuilder.getAccelerationStructure();
VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -194,7 +194,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -203,9 +203,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;

View file

@ -42,7 +42,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -65,18 +65,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -130,5 +130,5 @@ public:
void createTopLevelAS(); void createTopLevelAS();
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
}; };

View file

@ -93,7 +93,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -181,7 +181,7 @@ int main(int argc, char** argv)
helloVk.createPostPipeline(); helloVk.createPostPipeline();
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -13,14 +13,14 @@ First, we will create a scene with two reflective planes and a multicolored cube
~~~~ C++ ~~~~ C++
// Creation of the example // Creation of the example
helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(-2, 0, 0)) glm::translate(glm::mat4(1),glm::vec3(-2, 0, 0))
* nvmath::scale_mat4(nvmath::vec3f(.1f, 5.f, 5.f))); * glm::scale(glm::mat4(1.f),glm::vec3(.1f, 5.f, 5.f)));
helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(2, 0, 0)) glm::translate(glm::mat4(1),glm::vec3(2, 0, 0))
* nvmath::scale_mat4(nvmath::vec3f(.1f, 5.f, 5.f))); * glm::scale(glm::mat4(1.f),glm::vec3(.1f, 5.f, 5.f)));
helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true));
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(0, -1, 0))); glm::translate(glm::mat4(1),glm::vec3(0, -1, 0)));
~~~~ ~~~~
Then find `cube.mtl` in `media/scenes` and modify the material to be 95% reflective, without any diffuse Then find `cube.mtl` in `media/scenes` and modify the material to be 95% reflective, without any diffuse

View file

@ -60,12 +60,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -184,7 +184,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -193,9 +193,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -698,7 +698,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -844,9 +844,9 @@ void HelloVulkan::createRtShaderBindingTable()
// The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned. // The SBT (buffer) need to have starting groups to be aligned and handles in the group to be aligned.
uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment); uint32_t handleSizeAligned = nvh::align_up(handleSize, m_rtProperties.shaderGroupHandleAlignment);
m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_rgenRegion.stride = nvh::align_up(handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member m_rgenRegion.size = m_rgenRegion.stride; // The size member of pRayGenShaderBindingTable must be equal to its stride member
m_missRegion.stride = handleSizeAligned; m_missRegion.stride = handleSizeAligned;
m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment); m_missRegion.size = nvh::align_up(missCount * handleSizeAligned, m_rtProperties.shaderGroupBaseAlignment);
m_hitRegion.stride = handleSizeAligned; m_hitRegion.stride = handleSizeAligned;
@ -861,9 +861,9 @@ void HelloVulkan::createRtShaderBindingTable()
// Allocate a buffer for storing the SBT. // Allocate a buffer for storing the SBT.
VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size; VkDeviceSize sbtSize = m_rgenRegion.size + m_missRegion.size + m_hitRegion.size + m_callRegion.size;
m_rtSBTBuffer = m_alloc.createBuffer(sbtSize, m_rtSBTBuffer = m_alloc.createBuffer(sbtSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); 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. m_debug.setObjectName(m_rtSBTBuffer.buffer, std::string("SBT")); // Give it a debug name for NSight.
// Find the SBT addresses of each group // Find the SBT addresses of each group
@ -905,7 +905,7 @@ void HelloVulkan::createRtShaderBindingTable()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -42,7 +42,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -65,18 +65,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -132,15 +132,15 @@ public:
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); void createRtPipeline();
void createRtShaderBindingTable(); void createRtShaderBindingTable();
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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -93,7 +93,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -160,12 +160,12 @@ int main(int argc, char** argv)
// Creation of the example // Creation of the example
helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(-2, 0, 0)) * nvmath::scale_mat4(nvmath::vec3f(.1f, 5.f, 5.f))); glm::translate(glm::mat4(1), glm::vec3(-2, 0, 0)) * glm::scale(glm::mat4(1.f), glm::vec3(.1f, 5.f, 5.f)));
helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/cube.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(2, 0, 0)) * nvmath::scale_mat4(nvmath::vec3f(.1f, 5.f, 5.f))); glm::translate(glm::mat4(1), glm::vec3(2, 0, 0)) * glm::scale(glm::mat4(1.f), glm::vec3(.1f, 5.f, 5.f)));
helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true)); helloVk.loadModel(nvh::findFile("media/scenes/cube_multi.obj", defaultSearchPaths, true));
helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true), helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths, true),
nvmath::translation_mat4(nvmath::vec3f(0, -1, 0))); glm::translate(glm::mat4(1), glm::vec3(0, -1, 0)));
helloVk.createOffscreenRender(); helloVk.createOffscreenRender();
helloVk.createDescriptorSetLayout(); helloVk.createDescriptorSetLayout();
@ -187,8 +187,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif

View file

@ -62,12 +62,12 @@ void HelloVulkan::updateUniformBuffer(const VkCommandBuffer& cmdBuf)
const float aspectRatio = m_size.width / static_cast<float>(m_size.height); const float aspectRatio = m_size.width / static_cast<float>(m_size.height);
GlobalUniforms hostUBO = {}; GlobalUniforms hostUBO = {};
const auto& view = CameraManip.getMatrix(); const auto& view = CameraManip.getMatrix();
const auto& proj = nvmath::perspectiveVK(CameraManip.getFov(), aspectRatio, 0.1f, 1000.0f); 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). proj[1][1] *= -1; // Inverting Y for Vulkan (not needed with perspectiveVK).
hostUBO.viewProj = proj * view; hostUBO.viewProj = proj * view;
hostUBO.viewInverse = nvmath::invert(view); hostUBO.viewInverse = glm::inverse(view);
hostUBO.projInverse = nvmath::invert(proj); hostUBO.projInverse = glm::inverse(proj);
// UBO on the device, and what stages access it. // UBO on the device, and what stages access it.
VkBuffer deviceUBO = m_bGlobals.buffer; VkBuffer deviceUBO = m_bGlobals.buffer;
@ -186,7 +186,7 @@ void HelloVulkan::createGraphicsPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Loading the OBJ file and setting up all buffers // 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()); LOGI("Loading File: %s \n", filename.c_str());
ObjLoader loader; ObjLoader loader;
@ -195,9 +195,9 @@ void HelloVulkan::loadModel(const std::string& filename, nvmath::mat4f transform
// Converting from Srgb to linear // Converting from Srgb to linear
for(auto& m : loader.m_materials) for(auto& m : loader.m_materials)
{ {
m.ambient = nvmath::pow(m.ambient, 2.2f); m.ambient = glm::pow(m.ambient, glm::vec3(2.2f));
m.diffuse = nvmath::pow(m.diffuse, 2.2f); m.diffuse = glm::pow(m.diffuse, glm::vec3(2.2f));
m.specular = nvmath::pow(m.specular, 2.2f); m.specular = glm::pow(m.specular, glm::vec3(2.2f));
} }
ObjModel model; ObjModel model;
@ -702,7 +702,7 @@ void HelloVulkan::createRtDescriptorSet()
vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet); 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}; VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
descASInfo.accelerationStructureCount = 1; descASInfo.accelerationStructureCount = 1;
descASInfo.pAccelerationStructures = &tlas; descASInfo.pAccelerationStructures = &tlas;
@ -902,7 +902,7 @@ void HelloVulkan::createRtPipeline()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// Ray Tracing the scene // 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"); m_debug.beginLabel(cmdBuf, "Ray trace");
// Initializing push constant values // Initializing push constant values

View file

@ -43,7 +43,7 @@ public:
void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override; void setup(const VkInstance& instance, const VkDevice& device, const VkPhysicalDevice& physicalDevice, uint32_t queueFamily) override;
void createDescriptorSetLayout(); void createDescriptorSetLayout();
void createGraphicsPipeline(); 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 updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createObjDescriptionBuffer(); void createObjDescriptionBuffer();
@ -66,18 +66,18 @@ public:
struct ObjInstance struct ObjInstance
{ {
nvmath::mat4f transform; // Matrix of the instance glm::mat4 transform; // Matrix of the instance
uint32_t objIndex{0}; // Model index reference uint32_t objIndex{0}; // Model index reference
}; };
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1}, // Identity matrix {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 {10.f, 15.f, 8.f}, // light position
0, // instance Id 0, // instance Id
100.f, // light intensity 100.f, // light intensity
0 // light type 0 // light type
}; };
// Array of objects and instances in the scene // Array of objects and instances in the scene
@ -132,15 +132,15 @@ public:
void createRtDescriptorSet(); void createRtDescriptorSet();
void updateRtDescriptorSet(); void updateRtDescriptorSet();
void createRtPipeline(); 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}; VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
nvvk::RaytracingBuilderKHR m_rtBuilder; nvvk::RaytracingBuilderKHR m_rtBuilder;
nvvk::DescriptorSetBindings m_rtDescSetLayoutBind; nvvk::DescriptorSetBindings m_rtDescSetLayoutBind;
VkDescriptorPool m_rtDescPool; VkDescriptorPool m_rtDescPool;
VkDescriptorSetLayout m_rtDescSetLayout; VkDescriptorSetLayout m_rtDescSetLayout;
VkDescriptorSet m_rtDescSet; VkDescriptorSet m_rtDescSet;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups; std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_rtShaderGroups;
VkPipelineLayout m_rtPipelineLayout; VkPipelineLayout m_rtPipelineLayout;
VkPipeline m_rtPipeline; VkPipeline m_rtPipeline;

View file

@ -105,7 +105,7 @@ int main(int argc, char** argv)
// Setup camera // Setup camera
CameraManip.setWindowSize(SAMPLE_WIDTH, SAMPLE_HEIGHT); 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 // Setup Vulkan
if(!glfwVulkanSupported()) if(!glfwVulkanSupported())
@ -193,8 +193,8 @@ int main(int argc, char** argv)
helloVk.updatePostDescriptorSet(); helloVk.updatePostDescriptorSet();
nvmath::vec4f clearColor = nvmath::vec4f(1, 1, 1, 1.00f); glm::vec4 clearColor = glm::vec4(1, 1, 1, 1.00f);
bool useRaytracer = true; bool useRaytracer = true;
helloVk.setupGlfwCallbacks(window); helloVk.setupGlfwCallbacks(window);

View file

@ -22,12 +22,12 @@
#define COMMON_HOST_DEVICE #define COMMON_HOST_DEVICE
#ifdef __cplusplus #ifdef __cplusplus
#include "nvmath/nvmath.h" #include <glm/glm.hpp>
// GLSL Type // GLSL Type
using vec2 = nvmath::vec2f; using vec2 = glm::vec2;
using vec3 = nvmath::vec3f; using vec3 = glm::vec3;
using vec4 = nvmath::vec4f; using vec4 = glm::vec4;
using mat4 = nvmath::mat4f; using mat4 = glm::mat4;
using uint = unsigned int; using uint = unsigned int;
#endif #endif