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