nvpro-samples/vk_mini_path_tracer

A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.

C++

1,284

53 commits

updated Oct 15, 2024

See the code

README

logo

vk_mini_path_tracer

A relatively small, beginner-friendly path tracing tutorial.

▶️ Load the tutorial! ◀️

This tutorial is a beginner-friendly introduction to writing your own fast, photorealistic path tracer in less than 300 lines of C++ code and 250 lines of GLSL shader code using Vulkan. Here's an example of what you'll render at the end of this tutorial!

Vulkan is a low-level API for programming GPUs – fast, highly parallel processors. It works on a wide variety of platforms – everything from workstations, to gaming consoles, to tablets and mobile phones, to edge devices.

Vulkan is usually known as a complex API, but I believe that when presented in the right way, it's possible to make learning Vulkan accessible to people of all skill levels, whether they're never programmed graphics before or whether they're a seasoned rendering engineer. Perhaps surprisingly, one of the best ways to introduce Vulkan may be with GPU path tracing, because the API involved is relatively small.

We'll show how to write a small path tracer, using the NVVK helpers, included in the nvpro-samples framework, to help with some Vulkan calls when needed. For advanced readers, we'll also optionally talk about performance tips and some of the implementation details inside the helpers and Vulkan itself.

The final program uses less than 300 lines of C++ and less than 250 lines of GLSL shader code, including comments. You can find it here.

Here are all the Vulkan functions, and NVVK functions and objects, that we'll use in the main tutorial:

Vulkan Functions
vkAllocateCommandBuffersvkBeginCommandBuffervkCmdBindDescriptorSets
vkCmdBindPipelinevkCmdDispatchvkCmdFillBuffer
vkCmdPipelineBarriervkCreateCommandPoolvkCreateComputePipelines
vkDestroyCommandPoolvkDestroyPipelinevkDestroyShaderModule
vkFreeCommandBuffersvkGetBufferDeviceAddressvkQueueSubmit
vkQueueWaitIdlevkUpdateDescriptorSets
NVVK Functions and Objects
nvvk::BufferNVVK_CHECKnvvk::Context
nvvk::ContextCreateInfonvvk::createShaderModulenvvk::DescriptorSetContainer
nvvk::RayTracingBuilderKHRnvvk::ResourceAllocatorDedicated

Chapters

Extra Chapters

These are optional, extra tutorials that show how to polish and add new features to the main tutorial's path tracer. Make sure to check out the list of further Vulkan and ray tracing resources at the end of the main tutorial as well!

Building and Running

Please see the instructions here.

raytracing
vulkan

nvpro-samples/vk_mini_path_tracer

A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.

C++

1,284

53 commits

updated Oct 15, 2024

See the code

README

logo

vk_mini_path_tracer

A relatively small, beginner-friendly path tracing tutorial.

▶️ Load the tutorial! ◀️

This tutorial is a beginner-friendly introduction to writing your own fast, photorealistic path tracer in less than 300 lines of C++ code and 250 lines of GLSL shader code using Vulkan. Here's an example of what you'll render at the end of this tutorial!

Vulkan is a low-level API for programming GPUs – fast, highly parallel processors. It works on a wide variety of platforms – everything from workstations, to gaming consoles, to tablets and mobile phones, to edge devices.

Vulkan is usually known as a complex API, but I believe that when presented in the right way, it's possible to make learning Vulkan accessible to people of all skill levels, whether they're never programmed graphics before or whether they're a seasoned rendering engineer. Perhaps surprisingly, one of the best ways to introduce Vulkan may be with GPU path tracing, because the API involved is relatively small.

We'll show how to write a small path tracer, using the NVVK helpers, included in the nvpro-samples framework, to help with some Vulkan calls when needed. For advanced readers, we'll also optionally talk about performance tips and some of the implementation details inside the helpers and Vulkan itself.

The final program uses less than 300 lines of C++ and less than 250 lines of GLSL shader code, including comments. You can find it here.

Here are all the Vulkan functions, and NVVK functions and objects, that we'll use in the main tutorial:

Vulkan Functions
vkAllocateCommandBuffersvkBeginCommandBuffervkCmdBindDescriptorSets
vkCmdBindPipelinevkCmdDispatchvkCmdFillBuffer
vkCmdPipelineBarriervkCreateCommandPoolvkCreateComputePipelines
vkDestroyCommandPoolvkDestroyPipelinevkDestroyShaderModule
vkFreeCommandBuffersvkGetBufferDeviceAddressvkQueueSubmit
vkQueueWaitIdlevkUpdateDescriptorSets
NVVK Functions and Objects
nvvk::BufferNVVK_CHECKnvvk::Context
nvvk::ContextCreateInfonvvk::createShaderModulenvvk::DescriptorSetContainer
nvvk::RayTracingBuilderKHRnvvk::ResourceAllocatorDedicated

Chapters

Extra Chapters

These are optional, extra tutorials that show how to polish and add new features to the main tutorial's path tracer. Make sure to check out the list of further Vulkan and ray tracing resources at the end of the main tutorial as well!

Building and Running

Please see the instructions here.

raytracing
vulkan

Significant stargazers

Stephan Seitz

261 followers · starred Nov 2023

Shockingly Good

66 followers · starred Dec 2022

Maik Klein

361 followers · starred Dec 2020

Shawn Walker-Salas

46 followers · starred Dec 2020