Blender  V3.3
bvh2.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011-2022 Blender Foundation. */
4 
5 #ifndef __BVH2_H__
6 #define __BVH2_H__
7 
8 #include "bvh/bvh.h"
9 #include "bvh/params.h"
10 
11 #include "util/types.h"
12 #include "util/vector.h"
13 
15 
16 #define BVH_NODE_SIZE 4
17 #define BVH_NODE_LEAF_SIZE 1
18 #define BVH_UNALIGNED_NODE_SIZE 7
19 
20 /* Pack Utility */
21 struct BVHStackEntry {
22  const BVHNode *node;
23  int idx;
24 
25  BVHStackEntry(const BVHNode *n = 0, int i = 0);
26  int encodeIdx() const;
27 };
28 
29 /* BVH2
30  *
31  * Typical BVH with each node having two children.
32  */
33 class BVH2 : public BVH {
34  public:
35  void build(Progress &progress, Stats *stats);
36  void refit(Progress &progress);
37 
39 
40  protected:
41  /* constructor */
42  friend class BVH;
43  BVH2(const BVHParams &params,
45  const vector<Object *> &objects);
46 
47  /* Building process. */
48  virtual BVHNode *widen_children_nodes(const BVHNode *root);
49 
50  /* pack */
51  void pack_nodes(const BVHNode *root);
52 
53  void pack_leaf(const BVHStackEntry &e, const LeafNode *leaf);
54  void pack_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1);
55 
57  const BVHStackEntry &e0,
58  const BVHStackEntry &e1);
59  void pack_aligned_node(int idx,
60  const BoundBox &b0,
61  const BoundBox &b1,
62  int c0,
63  int c1,
64  uint visibility0,
65  uint visibility1);
66 
68  const BVHStackEntry &e0,
69  const BVHStackEntry &e1);
70  void pack_unaligned_node(int idx,
71  const Transform &aligned_space0,
72  const Transform &aligned_space1,
73  const BoundBox &b0,
74  const BoundBox &b1,
75  int c0,
76  int c1,
77  uint visibility0,
78  uint visibility1);
79 
80  /* refit */
81  void refit_nodes();
82  void refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility);
83 
84  /* Refit range of primitives. */
85  void refit_primitives(int start, int end, BoundBox &bbox, uint &visibility);
86 
87  /* triangles and strands */
88  void pack_primitives();
89  void pack_triangle(int idx, float4 storage[3]);
90 
91  /* merge instance BVH's */
92  void pack_instances(size_t nodes_size, size_t leaf_nodes_size);
93 };
94 
96 
97 #endif /* __BVH2_H__ */
unsigned int uint
Definition: BLI_sys_types.h:67
float float4[4]
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
Definition: bvh2.h:33
void pack_instances(size_t nodes_size, size_t leaf_nodes_size)
Definition: bvh2.cpp:475
void pack_aligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition: bvh2.cpp:139
void refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility)
Definition: bvh2.cpp:313
void pack_triangle(int idx, float4 storage[3])
void pack_leaf(const BVHStackEntry &e, const LeafNode *leaf)
Definition: bvh2.cpp:106
void refit_primitives(int start, int end, BoundBox &bbox, uint &visibility)
Definition: bvh2.cpp:363
void pack_aligned_node(int idx, const BoundBox &b0, const BoundBox &b1, int c0, int c1, uint visibility0, uint visibility1)
Definition: bvh2.cpp:152
PackedBVH pack
Definition: bvh2.h:38
void pack_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition: bvh2.cpp:129
virtual BVHNode * widen_children_nodes(const BVHNode *root)
Definition: bvh2.cpp:101
void pack_unaligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition: bvh2.cpp:184
void pack_primitives()
Definition: bvh2.cpp:454
void pack_nodes(const BVHNode *root)
Definition: bvh2.cpp:231
void refit(Progress &progress)
Definition: bvh2.cpp:89
void pack_unaligned_node(int idx, const Transform &aligned_space0, const Transform &aligned_space1, const BoundBox &b0, const BoundBox &b1, int c0, int c1, uint visibility0, uint visibility1)
Definition: bvh2.cpp:199
BVH2(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition: bvh2.cpp:30
void refit_nodes()
Definition: bvh2.cpp:304
void build(Progress &progress, Stats *stats)
Definition: bvh2.cpp:37
Definition: bvh/bvh.h:63
vector< Geometry * > geometry
Definition: bvh/bvh.h:66
BVHParams params
Definition: bvh/bvh.h:65
vector< Object * > objects
Definition: bvh/bvh.h:67
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
const BVHNode * node
Definition: bvh2.h:22
BVHStackEntry(const BVHNode *n=0, int i=0)
Definition: bvh2.cpp:21
int idx
Definition: bvh2.h:23
int encodeIdx() const
Definition: bvh2.cpp:25