Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// 8-ary Bounding Volume Hierarchy node
- ///
- /// The storage is deon in a way where base point (origin) of the local grid is used and bounds
- /// for all 8 children are stored in quantized form. With 8 bits per plane. The scale of grid
- /// is defined using exponent for each axis.
- /// </summary>
- struct ALIGN(16) BVH8Node
- {
- /// <summary>
- /// Origin point of the local grid
- /// </summary>
- Engine::float3 mPoint;
- /// <summary>
- /// Exponent for each axis (8-bit)
- /// </summary>
- unsigned char mExponent[3];
- /// <summary>
- /// Mask to determine which child is leaf and which is interior node
- /// </summary>
- unsigned char mMask;
- /// <summary>
- /// Index to first referenced child node
- /// </summary>
- unsigned int mBaseChild;
- /// <summary>
- /// Index to first referenced triangle
- /// </summary>
- unsigned int mBaseTriangle;
- /// <summary>
- /// Per-child meta information encoding the indexing information required to find corresponding
- /// triangle range or node in the corresponding array
- ///
- /// Empty child slot - encoded as 00000000
- /// Internal node - encoded as high 3-bits 001 and low 5-bits store child slot index plus 24
- /// Leaf node - encoded as high 3-bitss storing number of triangles using unary encoding and
- /// low 5 bits store inde of first triangle relative to triangle base index
- /// </summary>
- unsigned char mMeta[8];
- /// <summary>
- /// Quantized bounding box min on X axis for all 8 children
- /// </summary>
- unsigned char mQuantizedMinX[8];
- /// <summary>
- /// Quantized bounding box max on X axis for all 8 children
- /// </summary>
- unsigned char mQuantizedMaxX[8];
- /// <summary>
- /// Quantized bounding box min on Y axis for all 8 children
- /// </summary>
- unsigned char mQuantizedMinY[8];
- /// <summary>
- /// Quantized bounding box max on Y axis for all 8 children
- /// </summary>
- unsigned char mQuantizedMaxY[8];
- /// <summary>
- /// Quantized bounding box min on Z axis for all 8 children
- /// </summary>
- unsigned char mQuantizedMinZ[8];
- /// <summary>
- /// Quantized bounding box max on Z axis for all 8 children
- /// </summary>
- unsigned char mQuantizedMaxZ[8];
- /// <summary>
- /// Is child node a leaf?
- /// </summary>
- /// <param name="childIndex">Nth child node</param>
- /// <returns>True when leaf, false otherwise</returns>
- inline bool IsLeaf(int childIndex)
- {
- return (mMeta[childIndex] & 0b00011111) << 24;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment