Summary:Building BVHs • Find bounding box 找到当前节点物体的包围盒 • Recursively split set of objects in two subsets 递归地将当前物体分为两堆 • Recompute the bounding box of the subsets 重新计算两堆物体的包围盒 • Stop when necessary 适合的时候停止(每个叶子节点中三角形数量较少,空间中物体的划分尽量均匀) • Store objects in each leaf node 物体存储在叶子节点中
Heuristics of subdivision Choose a dimension tosplit • Heuristic #1: Always choose the longest axis in node • Heuristic #2: Split node at location of median object 即选定最长轴划分,划分界限为排序后位于中位的物体。
【补充:快速选择算法】
问题:对于n个无序数组成的序列,找出其中第i大的数。 时间复杂度:O(n)
BVH中用这一算法实现对于大小居中物体的查找。
3.3 存储结构
1 2 3 4 5 6 7
Data Structure for BVHs [Internal nodes store] • Bounding box • Children: pointers to child nodes [Leaf nodes store] • Bounding box • List of objects
3.4 伪代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Intersect(Ray ray, BVH node) { if (ray misses node.bbox) return; //若光线与bounding box不相交,结束 //若相交,分为是否是叶子节点 if (node is a leaf node) { test intersection with all objs; return closest intersection; } //叶子节点,判断节点内部所有物体,返回最近的交点 hit1 = Intersect(ray, node.child1); hit2 = Intersect(ray, node.child2); //若节点不是叶子节点,返回两个子节点交点的最近值 return the closer of hit1, hit2; }
4.加速结构的比较:Spatial vs Object Partitions
4.1 Spatial partition (e.g.KD-tree)
1 2 3 4
• Partition space into non-overlapping regions 空间划分,划分的节点之间不重叠 • An object can be contained in multiple regions 缺点:一个物体可能被划分到多个区域中
4.2 Object partition (e.g. BVH)
1 2 3 4
• Partition setof objects into disjoint subsets 优点:物体划分到不相交的子集,不会出现同一个物体被划分到不同的节点 • Bounding boxes foreachset may overlap inspace 缺点:不同节点所占空间可能重叠