Working on triangle BVH
parent
205946925b
commit
8961919bcc
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "engine/util/std.h"
|
#include "engine/util/std.h"
|
||||||
#include "engine/types.h"
|
#include "engine/types.h"
|
||||||
|
#include "engine/util/models.h"
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ifdef COMPILE_GUI
|
#ifdef COMPILE_GUI
|
||||||
|
@ -40,11 +41,11 @@ namespace Raytracing {
|
||||||
inline bool operator==(const BVHPartitionedSpace& left, const BVHPartitionedSpace& right) {
|
inline bool operator==(const BVHPartitionedSpace& left, const BVHPartitionedSpace& right) {
|
||||||
if (left.left.size() != right.left.size() || left.right.size() != right.right.size())
|
if (left.left.size() != right.left.size() || left.right.size() != right.right.size())
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < left.left.size(); i++){
|
for (int i = 0; i < left.left.size(); i++) {
|
||||||
if (left.left[i].aabb != right.left[i].aabb)
|
if (left.left[i].aabb != right.left[i].aabb)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < left.right.size(); i++){
|
for (int i = 0; i < left.right.size(); i++) {
|
||||||
if (left.right[i].aabb != right.right[i].aabb)
|
if (left.right[i].aabb != right.right[i].aabb)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -62,12 +63,8 @@ namespace Raytracing {
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
BVHNode* left;
|
BVHNode* left;
|
||||||
BVHNode* right;
|
BVHNode* right;
|
||||||
int index;
|
|
||||||
int hit = 0;
|
|
||||||
BVHNode(std::vector<BVHObject> objs, AABB aabb, BVHNode* left, BVHNode* right): objs(std::move(objs)), aabb(std::move(aabb)),
|
BVHNode(std::vector<BVHObject> objs, AABB aabb, BVHNode* left, BVHNode* right): objs(std::move(objs)), aabb(std::move(aabb)),
|
||||||
left(left), right(right) {
|
left(left), right(right) {}
|
||||||
index = count++;
|
|
||||||
}
|
|
||||||
BVHHitData firstHitRayIntersectTraversal(const Ray& r, PRECISION_TYPE min, PRECISION_TYPE max);
|
BVHHitData firstHitRayIntersectTraversal(const Ray& r, PRECISION_TYPE min, PRECISION_TYPE max);
|
||||||
~BVHNode() {
|
~BVHNode() {
|
||||||
delete (left);
|
delete (left);
|
||||||
|
@ -101,6 +98,35 @@ namespace Raytracing {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TriangleBVHObject {
|
||||||
|
Triangle* ptr = nullptr;
|
||||||
|
AABB aabb;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TriangleBVHPartitionedSpace {
|
||||||
|
std::vector<TriangleBVHObject> left;
|
||||||
|
std::vector<TriangleBVHObject> right;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TriangleBVHNode {
|
||||||
|
struct BVHHitData {
|
||||||
|
TriangleBVHNode* ptr{};
|
||||||
|
AABBHitData data{};
|
||||||
|
bool hit = false;
|
||||||
|
};
|
||||||
|
std::vector<TriangleBVHObject> objs;
|
||||||
|
AABB aabb;
|
||||||
|
TriangleBVHNode* left;
|
||||||
|
TriangleBVHNode* right;
|
||||||
|
|
||||||
|
TriangleBVHNode(std::vector<TriangleBVHObject> objs, AABB aabb, TriangleBVHNode* left, TriangleBVHNode* right)
|
||||||
|
: objs(std::move(objs)), aabb(std::move(aabb)), left(left), right(right) {}
|
||||||
|
~TriangleBVHNode() {
|
||||||
|
delete (left);
|
||||||
|
delete (right);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //STEP_2_BVH_H
|
#endif //STEP_2_BVH_H
|
||||||
|
|
Loading…
Reference in New Issue