Zgragselus

BVH8 Structure

Sep 9th, 2025
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. /// <summary>
  2. /// 8-ary Bounding Volume Hierarchy node
  3. ///
  4. /// The storage is deon in a way where base point (origin) of the local grid is used and bounds
  5. /// for all 8 children are stored in quantized form. With 8 bits per plane. The scale of grid
  6. /// is defined using exponent for each axis.
  7. /// </summary>
  8. struct ALIGN(16) BVH8Node
  9. {
  10.     /// <summary>
  11.     /// Origin point of the local grid
  12.     /// </summary>
  13.     Engine::float3 mPoint;
  14.  
  15.     /// <summary>
  16.     /// Exponent for each axis (8-bit)
  17.     /// </summary>
  18.     unsigned char mExponent[3];
  19.  
  20.     /// <summary>
  21.     /// Mask to determine which child is leaf and which is interior node
  22.     /// </summary>
  23.     unsigned char mMask;
  24.  
  25.     /// <summary>
  26.     /// Index to first referenced child node
  27.     /// </summary>
  28.     unsigned int mBaseChild;
  29.  
  30.     /// <summary>
  31.     /// Index to first referenced triangle
  32.     /// </summary>
  33.     unsigned int mBaseTriangle;
  34.  
  35.     /// <summary>
  36.     /// Per-child meta information encoding the indexing information required to find corresponding
  37.     /// triangle range or node in the corresponding array
  38.     ///
  39.     /// Empty child slot - encoded as 00000000
  40.     /// Internal node - encoded as high 3-bits 001 and low 5-bits store child slot index plus 24
  41.     /// Leaf node - encoded as high 3-bitss storing number of triangles using unary encoding and
  42.     ///             low 5 bits store inde of first triangle relative to triangle base index
  43.     /// </summary>
  44.     unsigned char mMeta[8];
  45.  
  46.     /// <summary>
  47.     /// Quantized bounding box min on X axis for all 8 children
  48.     /// </summary>
  49.     unsigned char mQuantizedMinX[8];
  50.  
  51.     /// <summary>
  52.     /// Quantized bounding box max on X axis for all 8 children
  53.     /// </summary>
  54.     unsigned char mQuantizedMaxX[8];
  55.  
  56.     /// <summary>
  57.     /// Quantized bounding box min on Y axis for all 8 children
  58.     /// </summary>
  59.     unsigned char mQuantizedMinY[8];
  60.  
  61.     /// <summary>
  62.     /// Quantized bounding box max on Y axis for all 8 children
  63.     /// </summary>
  64.     unsigned char mQuantizedMaxY[8];
  65.  
  66.     /// <summary>
  67.     /// Quantized bounding box min on Z axis for all 8 children
  68.     /// </summary>
  69.     unsigned char mQuantizedMinZ[8];
  70.  
  71.     /// <summary>
  72.     /// Quantized bounding box max on Z axis for all 8 children
  73.     /// </summary>
  74.     unsigned char mQuantizedMaxZ[8];
  75.  
  76.     /// <summary>
  77.     /// Is child node a leaf?
  78.     /// </summary>
  79.     /// <param name="childIndex">Nth child node</param>
  80.     /// <returns>True when leaf, false otherwise</returns>
  81.     inline bool IsLeaf(int childIndex)
  82.     {
  83.         return (mMeta[childIndex] & 0b00011111) << 24;
  84.     }
  85. };
  86.  
Advertisement
Add Comment
Please, Sign In to add comment