-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBVH.hpp
72 lines (56 loc) · 1.63 KB
/
BVH.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Created by LEI XU on 5/16/19.
//
#ifndef RAYTRACING_BVH_H
#define RAYTRACING_BVH_H
#include <atomic>
#include <vector>
#include <memory>
#include <ctime>
#include "Object.hpp"
#include "Ray.hpp"
#include "Bounds3.hpp"
#include "Intersection.hpp"
#include "Vector.hpp"
struct BVHBuildNode;
// BVHAccel Forward Declarations
struct BVHPrimitiveInfo;
// BVHAccel Declarations
inline int leafNodes, totalLeafNodes, totalPrimitives, interiorNodes;
class BVHAccel {
public:
// BVHAccel Public Types
enum class SplitMethod { NAIVE, SAH };
// BVHAccel Public Methods
BVHAccel(std::vector<Object*> p, int maxPrimsInNode = 1, SplitMethod splitMethod = SplitMethod::NAIVE);
Bounds3 WorldBound() const;
~BVHAccel();
Intersection Intersect(const Ray &ray) const;
Intersection getIntersection(BVHBuildNode* node, const Ray& ray)const;
bool IntersectP(const Ray &ray) const;
BVHBuildNode* root;
// BVHAccel Private Methods
BVHBuildNode* recursiveBuild(std::vector<Object*>objects);
// BVHAccel Private Data
const int maxPrimsInNode;
const SplitMethod splitMethod;
std::vector<Object*> primitives;
void getSample(BVHBuildNode* node, float p, Intersection &pos, float &pdf);
void Sample(Intersection &pos, float &pdf);
};
struct BVHBuildNode {
Bounds3 bounds;
BVHBuildNode *left;
BVHBuildNode *right;
Object* object;
float area;
public:
int splitAxis=0, firstPrimOffset=0, nPrimitives=0;
// BVHBuildNode Public Methods
BVHBuildNode(){
bounds = Bounds3();
left = nullptr;right = nullptr;
object = nullptr;
}
};
#endif //RAYTRACING_BVH_H