Refactoring
This commit is contained in:
parent
3e399adf0a
commit
d90ce79135
222 changed files with 9045 additions and 5734 deletions
|
|
@ -1,23 +1,21 @@
|
|||
# Ray Query - Tutorial
|
||||
|
||||
|
||||

|
||||
|
||||
## Tutorial ([Setup](../docs/setup.md))
|
||||
|
||||
This is an extension of the Vulkan ray tracing [tutorial](https://nvpro-samples.github.io/vk_raytracing_tutorial_KHR).
|
||||
|
||||
|
||||
This extension is allowing to execute ray intersection queries in any shader stages. In this example, we will add
|
||||
This extension is allowing to execute ray intersection queries in any shader stages. In this example, we will add
|
||||
ray queries [(GLSL_EXT_ray_query)](https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_query.txt) to the fragment shader to cast shadow rays.
|
||||
|
||||
In the contrary to all other examples, with this one, we are removing code. There are no need to have a SBT and a raytracing pipeline, the only thing that
|
||||
In the contrary to all other examples, with this one, we are removing code. There are no need to have a SBT and a raytracing pipeline, the only thing that
|
||||
will matter, is the creation of the acceleration structure.
|
||||
|
||||
Starting from the end of the tutorial, [ray_tracing__simple](https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR/tree/master/ray_tracing__simple) we will remove
|
||||
Starting from the end of the tutorial, [ray_tracing__simple](https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR/tree/master/ray_tracing__simple) we will remove
|
||||
all functions that were dedicated to ray tracing and keep only the construction of the BLAS and TLAS.
|
||||
|
||||
## Cleanup
|
||||
## Cleanup
|
||||
|
||||
First, let's remove all extra code
|
||||
|
||||
|
|
@ -34,7 +32,7 @@ Remove most functions and members to keep only what is need to create the accele
|
|||
|
||||
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
|
||||
nvvk::RaytracingBuilderKHR m_rtBuilder;
|
||||
~~~~
|
||||
~~~~
|
||||
|
||||
### hello_vulkan (source)
|
||||
|
||||
|
|
@ -42,8 +40,7 @@ From the source code, remove the code for all functions that was previously remo
|
|||
|
||||
### Shaders
|
||||
|
||||
You can safely remove all raytrace.* shaders
|
||||
|
||||
You can safely remove all raytrace.* shaders
|
||||
|
||||
## Support for Fragment shader
|
||||
|
||||
|
|
@ -51,8 +48,17 @@ In `HelloVulkan::createDescriptorSetLayout`, add the acceleration structure to t
|
|||
|
||||
~~~~ C++
|
||||
// The top level acceleration structure
|
||||
m_descSetLayoutBind.addBinding(3, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
~~~~
|
||||
m_descSetLayoutBind.addBinding(eTlas, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
~~~~
|
||||
|
||||
But since we will use only one descriptor set, change the binding value or `eTlas` to 3, such that binding will look like this
|
||||
|
||||
~~~~ C++
|
||||
eGlobals = 0, // Global uniform containing camera matrices
|
||||
eObjDescs = 1, // Access to the object descriptions
|
||||
eTextures = 2, // Access to textures
|
||||
eTlas = 3 // Top-level acceleration structure
|
||||
~~~~
|
||||
|
||||
In `HelloVulkan::updateDescriptorSet`, write the value to the descriptor set.
|
||||
|
||||
|
|
@ -61,11 +67,10 @@ In `HelloVulkan::updateDescriptorSet`, write the value to the descriptor set.
|
|||
VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
|
||||
descASInfo.accelerationStructureCount = 1;
|
||||
descASInfo.pAccelerationStructures = &tlas;
|
||||
writes.emplace_back(m_descSetLayoutBind.makeWrite(m_descSet, 3, &descASInfo));
|
||||
~~~~
|
||||
writes.emplace_back(m_descSetLayoutBind.makeWrite(m_descSet, eTlas, &descASInfo));
|
||||
~~~~
|
||||
|
||||
|
||||
### Shader
|
||||
### Shader
|
||||
|
||||
The last modification is in the fragment shader, where we will add the ray intersection query to trace shadow rays.
|
||||
|
||||
|
|
@ -73,7 +78,7 @@ First, the version has bumpped to 460
|
|||
|
||||
~~~~ C++
|
||||
#version 460
|
||||
~~~~
|
||||
~~~~
|
||||
|
||||
Then we need to add new extensions
|
||||
|
||||
|
|
@ -85,24 +90,22 @@ Then we need to add new extensions
|
|||
We have to add the layout to access the top level acceleration structure.
|
||||
|
||||
~~~~ C++
|
||||
layout(binding = 3, set = 0) uniform accelerationStructureEXT topLevelAS;
|
||||
layout(binding = eTlas) uniform accelerationStructureEXT topLevelAS;
|
||||
~~~~
|
||||
|
||||
|
||||
Ad the end of the shader, add the following code to initiate the ray query. As we are only interested to know if the ray
|
||||
At the end of the shader, add the following code to initiate the ray query. As we are only interested to know if the ray
|
||||
has hit something, we can keep the minimal.
|
||||
|
||||
~~~~ C++
|
||||
// Ray Query for shadow
|
||||
vec3 origin = worldPos;
|
||||
vec3 origin = i_worldPos;
|
||||
vec3 direction = L; // vector to light
|
||||
float tMin = 0.01f;
|
||||
float tMax = lightDistance;
|
||||
|
||||
// Initializes a ray query object but does not start traversal
|
||||
rayQueryEXT rayQuery;
|
||||
rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, origin, tMin,
|
||||
direction, tMax);
|
||||
rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, origin, tMin, direction, tMax);
|
||||
|
||||
// Start traversal: return false if traversal is complete
|
||||
while(rayQueryProceedEXT(rayQuery))
|
||||
|
|
@ -113,7 +116,6 @@ while(rayQueryProceedEXT(rayQuery))
|
|||
if(rayQueryGetIntersectionTypeEXT(rayQuery, true) != gl_RayQueryCommittedIntersectionNoneEXT)
|
||||
{
|
||||
// Got an intersection == Shadow
|
||||
outColor *= 0.1;
|
||||
o_color *= 0.1;
|
||||
}
|
||||
~~~~
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue