This sample is a glTF scene renderer with is using both the Vulkan rasterizer and ray tracer. The functionality is minimal, but offers enough to be a starting point for many other examples.
Loading a scene can be done using an argument: vk_base_sample.exe -f path_to_scene\a_scene.gltf
Or, after start up, drag&drop a .gltf
scene in the main window.
Rendering Mode
Select raster or ray tracing, and ray tracing settings
Cameras
Position and camera manipulation style. Double click set the center of interest.
Environment
Clear color, tone mapping and 2 default lights.
- The initialization of Vulkan and enabling extensions is done in
main.cpp
using thenvvk::Context
- Loading the glTF scene uses tinygltf and
nvh::GltfScene
to get teh data in an abstracted form.- Each primitive has its own allocated buffer of
Vertex
and indices. (createVertexBuffer
) - Materials are only a subset of glTF and are in a separated buffer. (
createMaterialBuffer
) - Textures are loaded and mipmap are generated. (
createTextureImages
) - Array of matrices for each node are stored in a separate buffer. (
createInstanceInfoBuffer
)
- Each primitive has its own allocated buffer of
- The infinite rendering loop is done in
main.cpp
, and define the following rendering loop skeleton. - Ray tracing uses the RTX pipeline, in addition to the scene descriptor set, it adds the top-level-acceleration-structure (TLAS) and a reference to the offscreen image for writing the result.
- The raster is rendering in an offscreen framebuffer, sharing the same image as for the raytracer. It loops over all node and render each primitives. This loop is recorded in a secondary command buffer, to be more rapidely executed (no CPU overhead) on the next frames.
- The resulted image is then rendered in the swapchain frame buffer, using a fullscreen quad. A fragment program will also apply tonemapping.
- In the same last render pass, the Ui from Dear Imgui is rendered on top.
Note: This example is a modification of the ray_tracing_gltf tutorial.
- Scene Geometry
- Rendering Loop
- Resource Allocator