-
Notifications
You must be signed in to change notification settings - Fork 6
BVH Code Structure
BVH is an important acceleration structure used before cluster culling stage. Different from classical BVH acceleration in raytracing, which usually stores the bounding box of world coordinate of enclosed primitives, BVH in Nanite(and Vulcanite) stores more information.
NaniteBVHNode is used across the entire CPU-side BVH constructing, serializing, deserializing, and loading.
struct NaniteBVHNode
{
... // NaniteBVHNode constructor
std::vector<std::shared_ptr<NaniteBVHNode>> children; // should be a fixed size
double normalizedlodError = -FLT_MAX;
double parentNormalizedError = -FLT_MAX;
glm::vec4 parentBoundingSphere;
int index = -1;
glm::vec3 pMin = glm::vec3(FLT_MAX);
glm::vec3 pMax = glm::vec3(-FLT_MAX);
NaniteBVHNodeStatus nodeStatus = NaniteBVHNodeStatus::INVALID;
uint32_t start = -1;
uint32_t end = -1;
uint32_t depth = 0;
// Only leaf node will have `clusterIndices` filled
//std::vector<uint32_t> clusterIndices;
std::array<int, CLUSTER_GROUP_MAX_SIZE> clusterIndices; // should try to assert index overflow
int lodLevel = -1;
int objectIdx = -1; // Only useful in instancing
int meshIdx = -1; // Only useful in instancing
};-
children: stores the children node of one BVH node.- Parent-child relationship here is defined by previous cluster grouping process.
-
normalizedlodError: LOD error from current lod to next-level lod. -
parentNormalizedlodError:normalizedlodErrorof parent node. -
parentBoundingSphere: bounding sphere of parent node. -
index: index of current node when flattened in future. -
pMin&pMax: twoglm::vec3representing bounding box. -
nodeStatus: anenum NaniteBVHNodeStatusrepresenting node status.NaniteBVHNodeStatuscan be set to following values-
INVALID: Default value when uninitialized. -
VIRTUAL_NODE: Virtual node. Do not store actual mesh information. Used as a dummy node for a more convenient node traversal implementation.-
VIRTUAL_NODEwill be used as the root node for LOD mesh, mesh, and scene.
-
SceneNode(VIRTUAL_NODE) | |- MeshNode(VIRTUAL_NODE) | |- LOD0Node(VIRTUAL_NODE) | |- Node0(NODE) ...-
NODE: Any non-leaf, non-virtual, and initialized node. -
LEAF: Node that does not have any children nodes.
-
-
start&end: denotes the start and end primitive index that current node contains. -
depth: denotes the depth of current node. -
clusterIndices: stores all indices of clusters that current node contains. A fixed-length array. Only valid forLEAFnode. -
lodLevel: stores the LOD level of current node. -
objectIdx: stores the object index. This is valid when current mesh has multiple instances. Object index is basically just the instance index of current mesh. -
meshIdx: stores the mesh index.