This repository provides a comprehensive learning resource for Vulkan ray tracing, featuring a progressive step-by-step tutorial that transforms a rasterization application into a fully functional ray tracing implementation. The tutorial demonstrates practical integration of ray tracing
and ray traversal
using the VK_KHR_acceleration_structure
, VK_KHR_ray_tracing_pipeline
and VK_KHR_ray_query
extensions.
Looking for the original version?
Check out the legacy Vulkan ray tracing tutorial (pre-v2.0).
- nvpro_core2: Vulkan helper classes and utilities
- See Clone instructions below
- Vulkan 1.4+: Compatible GPU and drivers
- Select Volk headers during installation for better compatibility
- CMake 3.18+
# Clone repositories
git clone https://github.com/nvpro-samples/nvpro_core2.git
git clone https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR.git
# Build
cmake -B build -S .
cmake --build build -j 8
Compiled files will be under the _bin
directory.
This repository provides a comprehensive, step-by-step tutorial that demonstrates how to convert a modern Vulkan rasterization application into a fully functional ray tracing implementation. The tutorial takes a hands-on approach, ensuring developers understand both the theoretical concepts and practical implementation details.
- Progressive Conversion: Transform
01_foundation
(raster-based) into02_basic
(ray tracing) through 8 carefully designed phases - Compilable Checkpoints: Each phase results in a working, testable application
- Industry Implementation: Learn standard practices for acceleration structures, shader binding tables, and ray tracing pipelines
- Modern Vulkan 1.4: Utilize current features including shader objects, push descriptors, and ray tracing extensions
🚀 BEGIN THE TUTORIAL 🚀
This tutorial is designed for developers with basic Vulkan knowledge who want to add ray tracing to their skillset. Each phase builds upon the previous one, ensuring a solid foundation for advanced ray tracing development.
This repository provides comprehensive documentation covering the core concepts and implementation details of Vulkan ray tracing. These documents serve as essential reference material for understanding the theoretical foundations and advanced techniques used throughout the tutorial series.
-
Acceleration Structures
Comprehensive guide to building and managing acceleration structures (BLAS and TLAS) in Vulkan. Covers construction algorithms, memory management, update strategies, and performance optimization techniques. Includes detailed coverage of utilities likenvvk::AccelerationStructureHelper
andnvvk::AccelerationStructureBuilder
. -
Shader Binding Table (SBT)
Detailed explanation of the Shader Binding Table structure, alignment requirements, and management techniques. Covers thenvvk::SBTGenerator
utility for efficient SBT creation and advanced patterns for custom data and multiple shader groups.
Note: The Acceleration Structures and SBT documentation should be read alongside the tutorial for complete understanding of the implementation details.
This comprehensive collection of focused tutorials builds upon the foundation established in the progressive tutorial, exploring specific ray tracing concepts and advanced techniques:
Tutorial | Features |
---|---|
01_foundation![]() |
Rasterization-Only Foundation - Sets up a modern Vulkan 1.4 rasterization pipeline (no ray tracing yet) - Loads and displays glTF objects using vertex and fragment shaders - Demonstrates use of Shader Objects and Push Descriptors for flexible resource binding - Establishes the application and rendering framework that all ray tracing samples will build upon - Provides a clean, minimal starting point for transitioning to ray tracing in later steps |
02_basic![]() |
Basic Ray Tracing (Direct Vulkan) - Transitions from rasterization to a minimal ray tracing pipeline using Vulkan 1.4. - Sets up acceleration structures (BLAS/TLAS) for the loaded glTF scene. - Implements a ray generation shader, closest hit shader, and miss shader. - Renders the scene using ray tracing: primary rays are cast from the camera, and the closest intersection is shaded. - Introduces a simple material system for basic surface color and lighting. - Demonstrates how to bind acceleration structures and shader tables. - Uses direct Vulkan calls for educational purposes - shows complete implementation without helper libraries. - Provides a clear, minimal foundation for all subsequent ray tracing features. |
02_basic_nvvk![]() |
Basic Ray Tracing (Helper Libraries) - Same functionality as 02_basic but uses nvpro-core2 helper libraries for simplified development. - Uses nvvk::AccelerationStructureHelper for automatic scratch buffer management and batch building.- Uses nvvk::SBTGenerator for automatic shader binding table creation and alignment handling.- Production-ready approach with reduced code complexity and better performance. - Used as foundation for all subsequent tutorials in the series (03_any_hit, 04_jitter_camera, etc.). - Demonstrates the recommended approach for real-world ray tracing applications. |
03_any_hit![]() |
Any-Hit Shaders and Transparency - Introduces the any-hit shader stage to the ray tracing pipeline. - Demonstrates how any-hit shaders can be used for: - Transparency: Ignoring intersections to create cutouts or alpha-tested materials. - Alpha Testing: Discarding hits based on texture alpha values. - Custom Intersection Logic: Procedural cutouts and complex intersection behavior. - Implements a circular cutout in a plane using the any-hit shader and a user-adjustable radius. - Adds a UI slider to control the cutout radius in real time. - Shows how to attach the any-hit shader to the hit group in the pipeline. - Explains the use of IgnoreHit() in HLSL to skip intersections. |
04_jitter_camera![]() |
Camera Jitter and Anti-Aliasing - Introduces camera jitter to implement temporal anti-aliasing (TAA) in ray tracing. - Offsets the camera's projection matrix each frame using a sub-pixel jitter pattern (e.g., Halton sequence). - Demonstrates how jittered camera rays reduce aliasing and improve image quality over multiple frames. - Accumulates frames in a history buffer to blend results and achieve smooth anti-aliased output. - Adds a UI toggle to enable/disable jitter and control the accumulation reset. - Explains how to update the camera and accumulation logic in both the application and shaders. |
05_shadow_miss![]() |
Shadow Miss Shader and Efficient Shadow Rays - Introduces a dedicated miss shader for shadow rays, separate from the main miss shader. - Demonstrates why using the same miss shader for both primary and shadow rays is inefficient: - Shadow rays only need to know if they hit something (occlusion), not full color/lighting. - The main miss shader may perform expensive sky/lighting calculations unnecessary for shadows. - Implements a minimal payload ( ShadowPayload ) for shadow rays, reducing memory and register usage.- Shows how to set up the ray tracing pipeline with multiple miss shader groups: - Group 0: Main miss shader for primary rays. - Group 1: Lightweight miss shader for shadow rays. - Updates the shadow tracing code to use the new miss shader group and minimal payload. - Results in improved performance, especially in scenes with many shadow rays. |
06_reflection ![]() |
Reflections with Ray Tracing - Introduces reflection rays to simulate mirror-like surfaces using ray tracing. - Demonstrates how to trace secondary rays from hit points to compute reflections. - Adds a new closest hit shader that spawns reflection rays and blends their results with the surface color. - Shows how to limit reflection recursion depth for performance and to avoid infinite loops. - Implements a simple material system to control reflectivity per object. - Updates the shader binding table and descriptor sets to support reflection rays. - Explains how to accumulate and denoise reflections for improved visual quality. |
07_multi_closest_hit![]() |
Multiple Closest Hit Shaders - Introduces multiple closest hit shaders to the ray tracing pipeline. - Demonstrates how different objects can use different closest hit shaders: - Default shader: Standard PBR lighting for the plane. - Second shader: First wuson instance with shader record data for color. - Third shader: Second wuson instance with shader record data for color. - Implements shader record data to pass instance-specific information through the Shader Binding Table (SBT). - Shows how to set up multiple hit groups in the ray tracing pipeline. - Adds a UI to dynamically change the colors of the wuson instances in real-time. - Explains the benefits of using multiple closest hit shaders for performance and flexibility. |
08_intersection![]() |
Intersection Shaders for Implicit Primitives - Demonstrates the use of intersection shaders to render implicit primitives (spheres and cubes) alongside traditional triangle geometry. - Shows how to define custom geometry (spheres/cubes) in the shader and intersect rays with them at runtime. - Implements a buffer of 2,000,000 implicit objects, alternating between spheres and cubes, each with different materials. - Explains how to: - Define implicit object structures and types in the shader interface. - Build and upload buffers for implicit objects and their AABBs. - Register custom intersection shaders in the ray tracing pipeline. - Use a single closest hit shader for all implicit objects, with logic to distinguish between spheres and cubes. - Alternate materials and colors procedurally for visual variety. - Illustrates how to combine triangle and procedural geometry in the same acceleration structure and render pass. |
09_motion_blur ![]() |
Advanced Motion Blur with Ray Tracing - Demonstrates three types of motion blur using the VK_NV_ray_tracing_motion_blur extension:- Matrix Motion: Object transformation interpolation (translation/rotation) using motion matrices. - SRT Motion: Scale-Rotate-Translate transformation with separate motion data structures. - Vertex Motion: Morphing geometry where vertex positions interpolate between T0 and T1 states. - Implements temporal ray tracing with varying ray time parameters for smooth motion blur effects. - Features multi-sample accumulation with user-controllable sample count for motion blur quality. - Uses low-level acceleration structure building with motion-enabled BLAS and TLAS construction. - Includes random time generation in shaders for consistent temporal sampling across primary and shadow rays. - Demonstrates advanced pipeline setup with motion blur flags and specialized instance data structures. |
10_position_fetch ![]() |
Position fetch extension Demonstrates the use of VK_KHR_ray_tracing_position_fetch extension to retrieve vertex positions directly from the acceleration structure during ray traversal. This reduces memory usage by eliminating the need for additional vertex buffers during rendering.Key Features: - Direct position access using HitTriangleVertexPosition() - Memory-efficient rendering without separate vertex buffers - Geometric normal calculation from fetched positions - BLAS configuration with VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_DATA_ACCESS_KHR Extension Requirements: - VK_KHR_ray_tracing_position_fetch - Hardware support (RTX 20 series and newer) |
11_shading_execution_reorder ![]() |
Shading Execution Reorder (SER) for Performance Optimization - Introduces Shading Execution Reorder (SER) using the VK_NV_ray_tracing_invocation_reorder extension to reduce execution divergence in ray tracing shaders.- Implements path tracing (first in the series) with multiple bounces, Russian roulette, and physically-based lighting. - Uses specialization constants (first in the series) for runtime toggling of SER without pipeline recreation. - Features a hollow box of spheres scene with real-time heatmap visualization showing execution divergence. - Demonstrates SER benefits through artificial divergence and performance comparison controls. |
12_infinite_plane ![]() |
Infinite Ground Plane with Interactive Toggle - Shows how to add an infinite plane to your ray tracing scene using a custom intersection function. - Implements a UI toggle to enable/disable the infinite plane in real time. - Demonstrates proper hit state management and how to distinguish plane hits from scene geometry. - Explains the importance of checking the plane intersection after TraceRay() for correct compositing.- Includes adjustable plane color, height, and material parameters via the UI. - Serves as a foundation for procedural environment effects and further extensions (multiple planes, procedural textures, etc.). |
13_callable_shader ![]() |
Callable Shaders for Modular Material Systems - Introduces callable shaders to create modular, reusable shader functions that can be invoked from other ray tracing shaders. - Demonstrates a material system with four different materials (diffuse, plastic, glass, constant) implemented as separate callable shaders. - Implements procedural textures (noise, checker, voronoi) as callable shaders with different payload structures. - Shows how to avoid expensive branching by using instanceCustomIndex in the TLAS for material selection.- Features dynamic material assignment with UI controls that trigger TLAS recreation when materials change. - Explains the performance trade-offs: material changes require TLAS rebuild, texture changes use push constants. - Demonstrates payload flexibility with different structures for materials vs. textures. - Includes animation support for procedural textures with time-based effects. |
14_animation![]() |
Real-Time Animation in Ray Tracing - Demonstrates two types of animation in ray tracing environments: - Instance Animation: Multiple Wuson models rotating in a circle using transformation matrix updates - Geometry Animation: Sphere deformation using compute shaders with radial wave effects - Implements acceleration structure updates with VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR :- TLAS updates for instance animation (transformation changes) - BLAS updates for geometry animation (vertex modifications) - Features compute shader vertex animation that modifies vertex positions and normals in-place on the GPU - Uses sine wave mathematics for realistic wave deformation with proper normal recalculation - Includes real-time UI controls for toggling animations and adjusting speed - Demonstrates proper synchronization between compute operations and ray tracing with memory barriers - Shows efficient update strategies using cmdUpdateAccelerationStructure instead of full rebuilds |
15_micro_maps_opacity ![]() |
Opacity Micro-Maps in Ray Tracing - Demonstrates Opacity Micro-Maps implementation in Vulkan for efficient ray tracing - Implements selective AnyHit shader invocation based on opacity state - Features radius-based opacity testing with real-time UI controls - Uses VkMicromapEXT structures for triangle subdivision and opacity encoding - Supports 2-state and 4-state micro-map formats with dynamic switching - Includes 6x6 triangle plane geometry for micro-maps demonstration - Provides real-time radius adjustment without acceleration structure rebuilds - Shows hardware-accelerated opacity testing with dedicated micro-map support |
xx_ray_query | comming soon |
xx_ray_indirect | comming soon |
xx_swept_spheres | comming soon |
xx_wireframe | comming soon |
xx_partition_tlas | comming soon |
xx_clusters | comming soon |
- Progressive Learning Path: Each tutorial builds naturally on the previous one with minimal, focused changes
- Industry-Standard Practices: Learn the same techniques used in professional ray tracing applications
- Modern Vulkan 1.4: Utilize current features including shader objects, push descriptors, and advanced ray tracing extensions
- Real-World Content: glTF scene support enables integration with existing 3D content pipelines
- Performance-Focused: Every implementation prioritizes efficiency and real-time performance
- Cross-Platform Compatibility: Slang shaders ensure compatibility across different platforms and hardware
For developers ready to explore a complete, production-ready Vulkan ray/path tracer implementation:
A comprehensive, full-featured Vulkan renderer showcasing advanced ray tracing, path tracing, and physically based rendering with robust glTF 2.0 support:
-
Production-Quality Features:
- Physically Based Rendering (PBR) with image-based lighting
- Real-time and offline path tracing modes
- Ray-traced reflections, shadows, and global illumination
- Complete glTF 2.0 support including animations and cameras
- Advanced post-processing: denoising, tone mapping, and effects
- Interactive UI for scene and renderer configuration
- Extensive Vulkan 1.3+ and ray tracing extension usage
-
Reference Implementation:
Well-documented and modular architecture provides an excellent reference for studying complete Vulkan ray/path tracer implementations and building production renderers.
This tutorial series is inspired by the vk_raytracing_tutorial_KHR but focuses on modern Vulkan 1.4 implementation rather than educational content.
A comprehensive collection covering all aspects of Vulkan development beyond ray tracing:
-
Comprehensive Coverage:
- Basic rendering, compute shaders, and graphics pipelines
- Advanced features like mesh shading, ray queries, and shader objects
- Performance analysis, debugging, and optimization techniques
- Real-time rendering, post-processing, and modern Vulkan features
-
Learning-Focused Design:
- Extensive collection of focused samples with clear documentation
- Progressive complexity from basic to advanced concepts
- Consistent architecture using the nvpro_core2 framework
- Complements the ray tracing tutorials