Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TWideBvhNode.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/constant.h"
5#include "Utility/TSpan.h"
6
7#include <Common/primitive_type.h>
8#include <Common/utility.h>
9#include <Common/compiler.h>
10#include <Common/memory.h>
11
12#include <cstddef>
13#include <type_traits>
14#include <array>
15#include <algorithm>
16
17namespace ph::math
18{
19
24template<std::size_t N, typename Index>
25class TWideBvhNode final
26{
27 static_assert(N >= 2);
28 static_assert(std::is_unsigned_v<Index>);
29
30 inline static constexpr std::size_t NUM_ITEMS_BITS = 5;
31
32 inline static constexpr uint8 X_AXIS_FLAG = 0b00;
33 inline static constexpr uint8 Y_AXIS_FLAG = 0b01;
34 inline static constexpr uint8 Z_AXIS_FLAG = 0b10;
35 inline static constexpr uint8 NO_AXIS_FLAG = 0b11;
36
37 static_assert(constant::X_AXIS == X_AXIS_FLAG);
38 static_assert(constant::Y_AXIS == Y_AXIS_FLAG);
39 static_assert(constant::Z_AXIS == Z_AXIS_FLAG);
40
41public:
43 inline static constexpr std::size_t MAX_NODE_ITEMS = (std::size_t(1) << NUM_ITEMS_BITS) - 1;
44
48 inline static constexpr std::size_t SOA_VIEW_ALIGNMENT = std::clamp(
49 N * 4, std::size_t(16), std::size_t(64));
50
54
55 AABB3D getAABB(std::size_t childIdx) const;
56 bool isLeaf(std::size_t childIdx) const;
57 bool isInternal(std::size_t childIdx) const;
58 std::size_t getChildOffset(std::size_t childIdx) const;
59
66 TSpanView<real, N> getMinVerticesOnAxis(std::size_t axis) const;
67 TSpanView<real, N> getMaxVerticesOnAxis(std::size_t axis) const;
69
77 std::size_t getSplitAxis(std::size_t childIdx) const;
78
79 std::size_t getItemOffset(std::size_t childIdx) const;
80 std::size_t numItems(std::size_t childIdx) const;
81
83 std::size_t childIdx,
84 const AABB3D& childAABB,
85 std::size_t childOffset,
86 std::size_t splitAxis);
87
89 std::size_t childIdx,
90 const AABB3D& childAABB,
91 std::size_t itemOffset,
92 std::size_t splitAxis,
93 std::size_t numItems);
94
96 std::size_t childIdx,
97 std::size_t splitAxis);
98
99private:
100 struct ChildData
101 {
102 uint8 isLeaf : 1 = true;
103 uint8 splitAxis : 2 = NO_AXIS_FLAG;
104 uint8 numItems : NUM_ITEMS_BITS = 0;
105 };
106
107 static_assert(sizeof(ChildData) == sizeof(uint8));
108
109 TAlignedArray<std::array<real, N>, 3, SOA_VIEW_ALIGNMENT> m_aabbMins;
110 TAlignedArray<std::array<real, N>, 3, SOA_VIEW_ALIGNMENT> m_aabbMaxs;
111
119 std::array<Index, N> m_offsets;
120
128 std::array<ChildData, N> m_childrenData;
129};
130
131}// end namespace ph::math
132
Definition TWideBvhNode.h:26
TWideBvhNode()
Creates a node that contains N empty leaves.
Definition TWideBvhNode.ipp:10
static constexpr std::size_t MAX_NODE_ITEMS
Definition TWideBvhNode.h:43
bool isInternal(std::size_t childIdx) const
Definition TWideBvhNode.ipp:70
std::size_t getSplitAxis(std::size_t childIdx) const
Definition TWideBvhNode.ipp:87
bool isLeaf(std::size_t childIdx) const
Definition TWideBvhNode.ipp:61
TWideBvhNode & setLeaf(std::size_t childIdx, const AABB3D &childAABB, std::size_t itemOffset, std::size_t splitAxis, std::size_t numItems)
Definition TWideBvhNode.ipp:142
std::size_t getChildOffset(std::size_t childIdx) const
Definition TWideBvhNode.ipp:77
TSpanView< real, N > getMaxVerticesOnAxis(std::size_t axis) const
Definition TWideBvhNode.ipp:51
TWideBvhNode & setInternal(std::size_t childIdx, const AABB3D &childAABB, std::size_t childOffset, std::size_t splitAxis)
Definition TWideBvhNode.ipp:115
std::size_t getItemOffset(std::size_t childIdx) const
Definition TWideBvhNode.ipp:95
TSpanView< real, N > getMinVerticesOnAxis(std::size_t axis) const
Obtain a view to min. and max. vertices of the child AABBs in SoA layout.
Definition TWideBvhNode.ipp:41
std::size_t numItems(std::size_t childIdx) const
Definition TWideBvhNode.ipp:105
AABB3D getAABB(std::size_t childIdx) const
Definition TWideBvhNode.ipp:29
TWideBvhNode & setEmptyLeaf(std::size_t childIdx, std::size_t splitAxis)
Definition TWideBvhNode.ipp:171
static constexpr std::size_t SOA_VIEW_ALIGNMENT
Definition TWideBvhNode.h:48
constexpr std::size_t Y_AXIS
Definition constant.h:91
constexpr std::size_t Z_AXIS
Definition constant.h:92
constexpr std::size_t X_AXIS
Definition constant.h:90
Math functions and utilities.
Definition TransformInfo.h:10
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19