Cycles: Make BVH wider prior to packing
[blender.git] / intern / cycles / bvh / bvh2.h
1 /*
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011, Blender Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef __BVH2_H__
19 #define __BVH2_H__
20
21 #include "bvh/bvh.h"
22 #include "bvh/bvh_params.h"
23
24 #include "util/util_types.h"
25 #include "util/util_vector.h"
26
27 CCL_NAMESPACE_BEGIN
28
29 class BVHNode;
30 struct BVHStackEntry;
31 class BVHParams;
32 class BoundBox;
33 class LeafNode;
34 class Object;
35 class Progress;
36
37 #define BVH_NODE_SIZE           4
38 #define BVH_NODE_LEAF_SIZE      1
39 #define BVH_UNALIGNED_NODE_SIZE 7
40
41 /* BVH2
42  *
43  * Typical BVH with each node having two children.
44  */
45 class BVH2 : public BVH {
46 protected:
47         /* constructor */
48         friend class BVH;
49         BVH2(const BVHParams& params, const vector<Object*>& objects);
50
51         /* Building process. */
52         virtual BVHNode *widen_children_nodes(const BVHNode *root) override;
53
54         /* pack */
55         void pack_nodes(const BVHNode *root);
56
57         void pack_leaf(const BVHStackEntry& e,
58                        const LeafNode *leaf);
59         void pack_inner(const BVHStackEntry& e,
60                         const BVHStackEntry& e0,
61                         const BVHStackEntry& e1);
62
63         void pack_aligned_inner(const BVHStackEntry& e,
64                                 const BVHStackEntry& e0,
65                                 const BVHStackEntry& e1);
66         void pack_aligned_node(int idx,
67                                const BoundBox& b0,
68                                const BoundBox& b1,
69                                int c0, int c1,
70                                uint visibility0, uint visibility1);
71
72         void pack_unaligned_inner(const BVHStackEntry& e,
73                                   const BVHStackEntry& e0,
74                                   const BVHStackEntry& e1);
75         void pack_unaligned_node(int idx,
76                                  const Transform& aligned_space0,
77                                  const Transform& aligned_space1,
78                                  const BoundBox& b0,
79                                  const BoundBox& b1,
80                                  int c0, int c1,
81                                  uint visibility0, uint visibility1);
82
83         /* refit */
84         void refit_nodes();
85         void refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility);
86 };
87
88 CCL_NAMESPACE_END
89
90 #endif  /* __BVH2_H__ */