Blender V5.0
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#pragma once
9
10#include "bvh/bvh.h"
11#include "bvh/params.h"
12
13#include "util/types.h"
14#include "util/unique_ptr.h"
15#include "util/vector.h"
16
18
19// NOLINTBEGIN
20#define BVH_NODE_SIZE 4
21#define BVH_NODE_LEAF_SIZE 1
22#define BVH_UNALIGNED_NODE_SIZE 7
23// NOLINTEND
24
25/* Pack Utility */
27 const BVHNode *node;
28 int idx;
29
30 BVHStackEntry(const BVHNode *n = nullptr, const int i = 0);
31 int encodeIdx() const;
32};
33
34/* BVH2
35 *
36 * Typical BVH with each node having two children.
37 */
38class BVH2 : public BVH {
39 public:
40 BVH2(const BVHParams &params,
43
44 void build(Progress &progress, Stats *stats);
45 void refit(Progress &progress);
46
48
49 protected:
50 /* Building process. */
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(const 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(const 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(const int idx, bool leaf, BoundBox &bbox, uint &visibility);
86
87 /* Refit range of primitives. */
88 void refit_primitives(const int start, const int end, BoundBox &bbox, uint &visibility);
89
90 /* triangles and strands */
91 void pack_primitives();
92 void pack_triangle(const int idx, const float4 storage[3]);
93
94 /* merge instance BVH's */
95 void pack_instances(const size_t nodes_size, const size_t leaf_nodes_size);
96};
97
unsigned int uint
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void pack_aligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition bvh2.cpp:129
void pack_unaligned_node(const 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:189
void refit_node(const int idx, bool leaf, BoundBox &bbox, uint &visibility)
Definition bvh2.cpp:302
virtual unique_ptr< BVHNode > widen_children_nodes(unique_ptr< BVHNode > &&root)
Definition bvh2.cpp:91
void pack_leaf(const BVHStackEntry &e, const LeafNode *leaf)
Definition bvh2.cpp:96
void pack_triangle(const int idx, const float4 storage[3])
PackedBVH pack
Definition bvh2.h:47
void pack_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition bvh2.cpp:119
void refit_primitives(const int start, const int end, BoundBox &bbox, uint &visibility)
Definition bvh2.cpp:354
void pack_instances(const size_t nodes_size, const size_t leaf_nodes_size)
Definition bvh2.cpp:470
void pack_aligned_node(const int idx, const BoundBox &b0, const BoundBox &b1, int c0, int c1, uint visibility0, uint visibility1)
Definition bvh2.cpp:142
void pack_unaligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition bvh2.cpp:174
void pack_primitives()
Definition bvh2.cpp:449
void pack_nodes(const BVHNode *root)
Definition bvh2.cpp:219
void refit(Progress &progress)
Definition bvh2.cpp:78
BVH2(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition bvh2.cpp:32
void refit_nodes()
Definition bvh2.cpp:293
void build(Progress &progress, Stats *stats)
Definition bvh2.cpp:39
vector< Geometry * > geometry
Definition bvh/bvh.h:70
BVH(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition bvh.cpp:90
BVHParams params
Definition bvh/bvh.h:69
vector< Object * > objects
Definition bvh/bvh.h:71
#define CCL_NAMESPACE_END
const BVHNode * node
Definition bvh2.h:27
BVHStackEntry(const BVHNode *n=nullptr, const int i=0)
Definition bvh2.cpp:25
int idx
Definition bvh2.h:28
int encodeIdx() const
Definition bvh2.cpp:27
i
Definition text_draw.cc:230