-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06669ee
commit d912ce9
Showing
7 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
#include "Acceleration.h" | ||
|
||
// MAX_LEAF_SIZE表示叶节点中至多包含的shape的个数 | ||
// 若构建时,某个节点的Shape个数多于MAX_LEAF_SIZE,那么就会对该节点继续划分 | ||
|
||
#define MAX_LEAF_SIZE 64 | ||
|
||
struct OctreeNode { | ||
AABB boundingBox; // 该节点的包围盒 | ||
|
||
std::shared_ptr<OctreeNode> subNodes[8]; // 该节点的八个子节点 | ||
|
||
// primCount设为-1时表示该节点不是叶节点,primCount为正值时表示叶节点有多少个shape | ||
int primCount = -1; | ||
|
||
int primIdxBuffer[MAX_LEAF_SIZE]; | ||
}; | ||
|
||
//* 八叉树 Octree | ||
|
||
class OctreeAcceleration : public Acceleration { | ||
public: | ||
OctreeAcceleration(); | ||
|
||
virtual ~OctreeAcceleration(); | ||
|
||
virtual void build() override; | ||
|
||
virtual bool rayIntersect(Ray &ray, int *geomID, int *primID, float *u, | ||
float *v) const override; | ||
|
||
protected: | ||
std::shared_ptr<OctreeNode> | ||
recursiveBuild(const AABB &aabb, const std::vector<int> &primIdxBuffer); | ||
|
||
protected: | ||
std::shared_ptr<OctreeNode> root; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters