用于基于集群的连续细节水平光栅化或光线追踪的样本
This sample is demonstrating the NVIDIA RTX Mega Geometry technology with a continuous level of detail (LoD) technique using mesh clusters that
leverages VK_NV_cluster_acceleration_structure for ray tracing. It can also rasterize the content
using VK_EXT/NV_mesh_shader. Furthermore, the sample implements an on-demand streaming system from RAM to VRAM for the geometry.
In rasterization continuous LoD techniques can help performance as they reduce the impact of sub-pixel triangles. For both ray tracing and rasterization these techniques can be combined with streaming the geometry data at the required detail level and work within a memory budget.
This work was inspired by the Nanite rendering system for Unreal Engine by Epic Games. We highly recommend having a look at A Deep Dive into Nanite Virtualized Geometry, Karis et al. 2021.
Please have a look at the vk_animated_clusters to familiarize yourself with the new ray tracing cluster extension. There are some similarities in the organization of this sample with the vk_tessellated_clusters sample.
The sample makes use of the meshoptimizer library to process the model and generate the required cluster and LoD data. The LoD system is organized in groups of clusters whose meshes were simplified together.
For some basic description what data structures the continuous LoD system uses and how it works please look here.
In principle the rendering loop is similar for rasterization and ray tracing. The traversal of the LoD hierarchy and the interaction with the streaming system are the same.
One key difference is that for ray tracing the cluster level acceleration structures (CLAS) need to be built, as well as the bottom level acceleration structure (BLAS) that reflects which clusters are used in an instance. Rasterization can render directly from the original geometry data and can render from the global list of clusters of any instance.
To allow easing into the topic, the sample has options to disable streaming as well as simplifying the CLAS allocation or switch between rasterization and ray tracing. In the next sections we will go over how the sample is organized and the key operations, what functions and files to look at.
Data structures that are shared between host and device are within the shaderio namespace:
The scene can be rendered with or without streaming:
The full logic of the renderers is implemented in:
VK_NV_mesh_shader or VK_EXT_mesh_shaderVK_NV_cluster_acceleration_structure. Enabled by default if available.The sample also showcases a ray tracing specific optimization for BLAS Sharing.
This sample uses a custom fork of meshoptimizer's single header clusterlod.h to support "inner" parallelism.
Inside scene_cluster_lod.cpp the Scene:buildGeometryLod(...) function covers the usage of the libraries and what data we need to extract from them. The Scene::storeGroup(...) function takes the resulting cluster group and packs it into a binary blob used for the runtime representation. The geometry data is later saved into the cache file for faster loading and streaming.
The cluster group can be compressed using a lossless compression scheme. However, we recommend the dropping of mantissa bits for both vertex positions and UV coordinates.
The compression is done in the Scene::compressGroup(...) function inside scene_cluster_compression.cpp.
In the UI you can influence the size of clusters and the LoD grouping of them in "Clusters & LoDs generation".
[!WARNING] The processing of larger scenes can take a while, even on CPUs with many cores. Therefore the application will save an uncompressed cache file of the results automatically. This file is a simple memory mappable binary file that can take a lot of space and is placed next to the original file with a
.nvsngeofile ending. During processing existing cache files will be overwritten without warning.With the
--processingonly 1command-line option one can reduce peak memory consumption during processing of scenes with many geometries. In this mode saving to the cache file is interleaved with the processing and resources are deallocated immediately once saved. At the end of the processing the app closes automatically. In combination with the--processingpartial 1command-line option, the processing only mode can resume partial results. So one can terminate the app during processing and continue at a later time. There is no consistency checking of settings or input meshes for this. To reduce system resource usage during processing use:--processingthreadpct(default is 0.5, half the systems supported concurrency) and--processingmemorygigabytes 0 is absolute >If system memory usage after loading a cached file is a concern, then
--mappedcache 1can be used to load data through memory mapping directly (forced for caches that are >= 2 GiB). However, we still have to improve the streaming logic a bit to avoid IO related hitches.Be aware, there are currently only few compatibility checks for these cache files, therefore we recommend deleting if changes were made to the original input mesh.
The model loader can make use of these glTF 2.0 Extensions:
The key operation for rendering is to traverse the LoD hierarchy and build the list of renderable clusters. For ray tracing we need to build BLAS based on that list as well. When streaming is active, then CLAS have to be built for the clusters of the newly loaded groups (dashed outlines). They are built into scratch space first, so the allocation logic can use their accurate build sizes and move them to a persistent location.
All operations are performed indirectly on the device and do not require any readbacks to host.
Use "Traversal" settings within the UI to influence it.
Relevant files to traversal in their usage order:
SceneBuildingSceneBuilding::traversalNodeInfos. Implements a shortcut to directly insert the low detail cluster into SceneBuilding::renderClusterInfos if only the furthest LoD would be traversed (also skips BLAS building for ray tracing).SceneBuilding::renderClusterInfos.SceneBuilding::blasBuildInfos) from the render cluster list. The actual BLAS build is triggered in RendererRayTraceClustersLod::render (look for "BLAS Build").Rasterization:
Does not need the BLAS and TLAS build steps and can render directly from SceneBuilding::renderClusterInfos.
Frustum and occlusion culling can be done to reduce the number of rendered clusters during traversal.
When USE_DLSS is enabled at build time, rasterization supports DLSS Super Resolution (DLSS-SR) to upscale a lower-resolution render target (requires --renderer 0 or the rasterizer UI option). The motion-vector render target stays bound whenever DLSS-SR is active; only shaded hardware rasterization writes motion vectors (SW-raster and other non-shaded modes disable color writes on that attachment and clear it each frame).
In some conditions (visualize == visibility buffer, culling on) one can enable the usage of a basic compute-shader based rasterizer. However it hasn't been tuned yet and in typical usage scenarios is not faster than the mesh-shader because clusters tend to have larger than single pixel triangles. You can look for USE_SW_RASTER in the code where it does affect traversal.
Ray Tracing: After the BLAS are built, also runs the TLAS build or update and then traces rays. Frustum and occlusion culling only influence the LoD factors per-instance through a simple heuristic. Ray tracing will render more clusters even with culling than raster.
Use the "Mirror Box" effect (double right-click or M key) to investigate the impact on geometry that is outside the frustum or otherwise occluded.
There is two sets of shaders, and their usage depends on whether Path Tracing is enabled. They have a slightly different configuration. The default / basic set of shaders do shading in the hit-shader, whilst path-tracing does shading in the ray generation shader. Overall the material complexity in this sample is intentionally kept low and we recommend to have a look at vk_gltf_renderer for more fidelity. Path tracing uses the physical sky model, whilst the other options use a simplified version.
Basic shaders:
暂无开放 Issues,或尚未同步最近议题。