The focus of this repository and the provided code is to showcase a basic integration of
ray tracing
and ray traversal
within an existing Vulkan sample, using the
VK_KHR_acceleration_structure
, VK_KHR_ray_tracing_pipeline
and VK_KHR_ray_query
extensions.
To be able to compile and run those examples, please follow the setup instructions. Find more over nvpro-samples setup at: https://github.com/nvpro-samples/build_all.
The first tutorial starts from a very simple Vulkan application. It loads a OBJ file and uses the rasterizer to render it. The tutorial then adds, step-by-step, all that is needed to be able to ray trace the scene.
Ray Tracing Tutorial: ▶️ Start Here ◀️
All other tutorials start from the end of the first ray tracing tutorial and also provide step-by-step instructions to modify and add methods and functions for that extra section.
Tutorial | Details |
---|---|
Any Hit Shader Implements transparent materials by adding a new shader to the Hit group and using the material information to discard hits over time. Adds an anyhit (.ahit) shader to the ray tracing pipeline. Creates simple transparency by randomly letting the ray hit or not. |
|
Jitter Camera Anti-aliases the image by accumulating small variations of rays over time. Generates random ray directions. Read/write/accumulates the final image. |
|
Thousands of Objects The current example allocates memory for each object, each of which has several buffers. This shows how to get around Vulkan's limits on the total number of memory allocations by using a memory allocator. Extends the limit of 4096 memory allocations. Uses these memory allocators: DMA, VMA. |
|
Reflections Reflections can be implemented by shooting new rays from the closest hit shader, or by iteratively shooting them from the raygen shader. This example shows the limitations and differences of these implementations. Calls traceRayEXT() from the closest hit shader (recursive). Adds more data to the ray payload to continue the ray from the raygen shader. |
|
Multiple Closest Hits Shader and Shader Records Explains how to add more closest hit shaders, choose which instance uses which shader, add data per SBT that can be retrieved in the shader, and more. One closest hit shader per object. Sharing closest hit shaders for some objects. Passing a shader record to the closest hit shader. |
|
Animation This tutorial shows how animating the transformation matrices of the instances (TLAS) and animating the vertices of an object (BLAS) in a compute shader could be done. Refitting top level acceleration structures. Refitting bottom level acceleration structures. |
|
Intersection Shader Adds thousands of implicit primitives and uses an intersection shader to render spheres and cubes. Explains what is needed to get procedural hit group working. Intersection Shaders. Sphere intersection. Axis aligned bounding box intersection. |
|
Callable Shader Replacing if/else by callable shaders. The code to execute the lighting is done in separate callable shaders instead of being part of the main code. Adding multiple callable shaders. Calling ExecuteCallableEXT from the closest hit shader. |
|
Ray Query Invokes ray intersection queries directly from the fragment shader to cast shadow rays. Ray tracing directly from the fragment shader. |
|
glTF Scene Instead of loading separate OBJ objects, the example was modified to load glTF scene files containing multiple objects. This example is not about shading, but using more complex data than OBJ. However, it also shows a basic path tracer implementation. |
|
Advance An example combining most of the above samples in a single application. |
|
Trace Rays Indirect Teaches the use of vkCmdTraceRaysIndirectKHR , which sources width/height/depth from a buffer. As a use case, we add lanterns to the scene and use a compute shader to calculate scissor rectangles for each of them. |
|
AO Raytracing This extension to the tutorial is showing how G-Buffers from the fragment shader, can be used in a compute shader to cast ambient occlusion rays using ray queries (GLSL_EXT_ray_query). |
|
Specialization Constants Showing how to use specialization constant and using interactively different specialization. |
|
Advanced Compilation Shows how to create reusable pipeline libraries and compile pipelines on multiple threads. |
|
Motion Blur Using vertex motion and instance motion: matrix and SRT. |
At this point, if you have followed the tutorials, the other ray tracing examples should be quite easy to follow.
The Vulkan Mini-Samples contain many interesting ray tracing examples:
Micro-Mesh Displacement | |
Micromap Opacity | |
Raytrace | |
Shading Execution Reorder |
vk_shaded_gltfscene This sample loads glTF (.gltf/.glb) scenes and will ray trace or rasterize it using glTF 2.0 PBR material and textures. It can display an HDR image in the background and be lit by that HDR or use a built-in Sun&Sky. It renders in multiple passes, background, scene, and then tone maps the result. It shows how multiple resources (geometry, materials and textures) can be shared between the two rendering systems. | |
vk_raytrace This project is a glTF 2.0 sample viewer using Vulkan ray tracing. It follows the ray tracing tutorial and combines all chapters into a single example. Supports both glTF PBR and Disney PBR material, uses the RTX pipeline or the Ray Query in a single compute shader. Many glTF extensions are supported, such as KHR_materials_clearcoat, KHR_materials_transmission, KHR_texture_transform, and a few more. |