Top Related Projects
One stop solution for all Vulkan samples
C++ examples for the Vulkan graphics API
A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Quick Overview
The nvpro-samples/vk_raytracing_tutorial_KHR repository is a comprehensive tutorial for implementing ray tracing using Vulkan and the KHR ray tracing extension. It provides step-by-step guidance on setting up a ray tracing pipeline, creating acceleration structures, and implementing various ray tracing techniques in Vulkan.
Pros
- Detailed, step-by-step tutorial for learning Vulkan ray tracing
- Includes practical examples and explanations for each concept
- Covers advanced topics like multi-level acceleration structures and denoising
- Regularly updated to incorporate the latest Vulkan ray tracing features
Cons
- Requires a solid understanding of Vulkan and graphics programming
- May be overwhelming for beginners due to the complexity of ray tracing concepts
- Limited to Vulkan-specific implementation, not applicable to other graphics APIs
- Requires compatible hardware with ray tracing support
Code Examples
- Creating a ray tracing pipeline:
void HelloVulkan::createRtPipeline()
{
vk::ShaderModule raygenSM = nvvk::createShaderModule(m_device, nvh::loadFile("spv/raygen.rgen.spv", true, defaultSearchPaths, true));
vk::ShaderModule missSM = nvvk::createShaderModule(m_device, nvh::loadFile("spv/miss.rmiss.spv", true, defaultSearchPaths, true));
std::vector<vk::PipelineShaderStageCreateInfo> stages;
stages.push_back({{}, vk::ShaderStageFlagBits::eRaygenKHR, raygenSM, "main"});
stages.push_back({{}, vk::ShaderStageFlagBits::eMissKHR, missSM, "main"});
vk::RayTracingPipelineCreateInfoKHR rayPipelineInfo;
rayPipelineInfo.setStages(stages);
// ... (set other pipeline properties)
m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
}
- Building an acceleration structure:
void HelloVulkan::buildAccelerationStructures()
{
// Bottom-level acceleration structure
vk::AccelerationStructureGeometryKHR asGeom;
asGeom.setGeometryType(vk::GeometryTypeKHR::eTriangles);
asGeom.geometry.triangles.setVertexFormat(vk::Format::eR32G32B32Sfloat);
asGeom.geometry.triangles.setVertexData(m_vertexBuffer.buffer);
asGeom.geometry.triangles.setIndexType(vk::IndexType::eUint32);
asGeom.geometry.triangles.setIndexData(m_indexBuffer.buffer);
vk::AccelerationStructureBuildGeometryInfoKHR asBuildInfo;
asBuildInfo.setType(vk::AccelerationStructureTypeKHR::eBottomLevel);
asBuildInfo.setFlags(vk::BuildAccelerationStructureFlagBitsKHR::ePreferFastTrace);
asBuildInfo.setGeometries(asGeom);
// ... (build acceleration structure)
}
- Tracing rays:
void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf)
{
cmdBuf.bindPipeline(vk::PipelineBindPoint::eRayTracingKHR, m_rtPipeline);
cmdBuf.bindDescriptorSets(vk::PipelineBindPoint::eRayTracingKHR, m_rtPipelineLayout, 0, {m_rtDescSet}, {});
vk::DeviceSize rayGenOffset = 0;
cmdBuf.traceRaysKHR(&m_rgenRegion, &m_missRegion, &
Competitor Comparisons
One stop solution for all Vulkan samples
Pros of Vulkan-Samples
- Comprehensive collection of Vulkan samples covering various aspects of the API
- Regularly updated with new features and best practices
- Well-documented and maintained by the Khronos Group
Cons of Vulkan-Samples
- Focuses on general Vulkan features, not specifically on ray tracing
- May be overwhelming for beginners due to its extensive coverage
Code Comparison
vk_raytracing_tutorial_KHR:
void createBottomLevelAS()
{
// Create the bottom-level acceleration structure
nvvk::RaytracingBuilderKHR::BottomLevelInput bottomLevelInput;
bottomLevelInput.flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR;
// ... (specific ray tracing setup)
}
Vulkan-Samples:
void create_acceleration_structure()
{
VkAccelerationStructureCreateInfoKHR create_info{};
create_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR;
create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
// ... (general Vulkan acceleration structure setup)
}
The vk_raytracing_tutorial_KHR code is more focused on ray tracing specifics, while Vulkan-Samples provides a more general Vulkan implementation. The former uses NVIDIA's nvvk helper library, while the latter uses standard Vulkan calls.
C++ examples for the Vulkan graphics API
Pros of Vulkan
- Comprehensive collection of Vulkan examples covering a wide range of features and techniques
- Well-documented and organized codebase with clear explanations for each example
- Regularly updated to include new Vulkan features and best practices
Cons of Vulkan
- Focuses on general Vulkan usage rather than specializing in ray tracing
- May be overwhelming for beginners due to the large number of examples and advanced topics
Code Comparison
vk_raytracing_tutorial_KHR:
void HelloVulkan::createBottomLevelAS()
{
// ... (ray tracing specific code)
}
Vulkan:
void VulkanExample::prepareUniformBuffers()
{
// ... (general Vulkan setup code)
}
Summary
Vulkan provides a broader overview of Vulkan capabilities, making it suitable for developers looking to explore various aspects of the API. vk_raytracing_tutorial_KHR, on the other hand, offers a more focused approach to ray tracing in Vulkan, making it ideal for those specifically interested in implementing ray tracing techniques.
While Vulkan covers a wide range of topics, vk_raytracing_tutorial_KHR delves deeper into ray tracing specifics, providing more detailed examples and explanations for this particular use case. Developers should choose based on their specific needs and level of expertise in Vulkan programming.
A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.
Pros of vk_mini_path_tracer
- More compact and focused implementation, easier for beginners to grasp
- Includes a complete path tracing algorithm, demonstrating advanced rendering techniques
- Utilizes modern C++ features and coding practices
Cons of vk_mini_path_tracer
- Less comprehensive in covering Vulkan ray tracing features compared to vk_raytracing_tutorial_KHR
- May not be as suitable for learning the full range of Vulkan ray tracing capabilities
- Limited to a specific rendering technique (path tracing) rather than exploring various ray tracing applications
Code Comparison
vk_mini_path_tracer:
void createRayTracingPipeline()
{
vk::RayTracingPipelineCreateInfoKHR rayPipelineInfo;
rayPipelineInfo.setStages(stages);
rayPipelineInfo.setGroups(groups);
rayPipelineInfo.setMaxPipelineRayRecursionDepth(10);
rayPipelineInfo.setLayout(pipelineLayout);
m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo);
}
vk_raytracing_tutorial_KHR:
void createRayTracingPipeline()
{
VkRayTracingPipelineCreateInfoKHR rayPipelineInfo{VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR};
rayPipelineInfo.stageCount = static_cast<uint32_t>(stages.size());
rayPipelineInfo.pStages = stages.data();
rayPipelineInfo.groupCount = static_cast<uint32_t>(groups.size());
rayPipelineInfo.pGroups = groups.data();
rayPipelineInfo.maxPipelineRayRecursionDepth = 1;
rayPipelineInfo.layout = pipelineLayout;
vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayPipelineInfo, nullptr, &pipeline);
}
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Pros of Filament
- Comprehensive real-time rendering engine with support for multiple platforms
- Extensive documentation and examples for easier adoption
- Active development and maintenance by Google
Cons of Filament
- Steeper learning curve due to its broader scope and feature set
- May be overkill for simple ray tracing projects
- Less focused on Vulkan-specific ray tracing techniques
Code Comparison
vk_raytracing_tutorial_KHR:
void createRayTracingPipeline()
{
vk::ShaderModule rayGenShader = createShaderModule(loadFile("shaders/raygen.rgen.spv"));
vk::ShaderModule missShader = createShaderModule(loadFile("shaders/miss.rmiss.spv"));
vk::ShaderModule chitShader = createShaderModule(loadFile("shaders/chit.rchit.spv"));
// ... (pipeline creation code)
}
Filament:
FilamentApp& app = FilamentApp::get();
auto& engine = app.getEngine();
auto scene = engine.createScene();
auto& view = app.getGuiView();
view.setScene(scene);
// ... (scene setup and rendering code)
The vk_raytracing_tutorial_KHR focuses on low-level Vulkan ray tracing setup, while Filament provides a higher-level abstraction for scene management and rendering across multiple platforms.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME

NVIDIA Vulkan Ray Tracing Tutorials (v2.0)

Convert a modern Vulkan 1.4 rasterization application into a fully functional ray tracer through 8 progressive, compilable phases, then explore 18+ focused samples covering reflections, motion blur, ray queries, callable shaders, opacity micro-maps, and more. Built on the VK_KHR_acceleration_structure, VK_KHR_ray_tracing_pipeline, and VK_KHR_ray_query extensions.
Start the Progressive Tutorial · Browse Samples · Documentation
| Before (rasterization) | After (ray tracing) |
|---|---|
![]() | ![]() |
Quick Start
Prerequisites
- nvpro_core2 (Vulkan helpers)
- Vulkan 1.4+ SDK â select Volk headers during installation
- CMake 3.18+
- A GPU and driver supporting Vulkan ray tracing
Build
From an empty parent directory that will hold both repos side-by-side:
git clone https://github.com/nvpro-samples/nvpro_core2.git
git clone https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR.git
cd vk_raytracing_tutorial_KHR
cmake -B build -S .
cmake --build build -j 8
Compiled binaries are placed in the _bin directory.
Looking for the Original?
The legacy pre-v2.0 tutorial is on the master branch.
Related Projects
- vk_gltf_renderer â Production-ready Vulkan ray/path tracer with full glTF 2.0 support, IBL, denoising, and post-processing.
- vk_mini_samples â Comprehensive collection of focused Vulkan samples beyond ray tracing.
Top Related Projects
One stop solution for all Vulkan samples
C++ examples for the Vulkan graphics API
A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot
