#[repr(C)]pub struct CwBvh {
pub nodes: Vec<CwBvhNode>,
pub primitive_indices: Vec<u32>,
pub total_aabb: Aabb,
pub exact_node_aabbs: Option<Vec<Aabb>>,
pub uses_spatial_splits: bool,
}Expand description
A Compressed Wide BVH8
Fields§
§nodes: Vec<CwBvhNode>§primitive_indices: Vec<u32>§total_aabb: Aabb§exact_node_aabbs: Option<Vec<Aabb>>§uses_spatial_splits: boolIndicates that this BVH is using spatial splits. Large triangles are split into multiple smaller Aabbs, so primitives will extend outside the leaf in some cases. If the bvh uses splits, a primitive can show up in multiple leaf nodes so there wont be a 1 to 1 correlation between the total number of primitives in leaf nodes and in Bvh2::primitive_indices, vs the input triangles. If spatial splits are used, some validation steps have to be skipped.
Implementations§
Source§impl CwBvh
impl CwBvh
pub fn new_ray_traversal(&self, ray: Ray) -> RayTraversal
Sourcepub fn new_traversal(&self, traversal_direction: Vec3A) -> Traversal
pub fn new_traversal(&self, traversal_direction: Vec3A) -> Traversal
traversal_direction is used to determine the order of bvh node child traversal. This would typically be the ray direction.
Sourcepub fn ray_traverse<F: FnMut(&Ray, usize) -> f32>(
&self,
ray: Ray,
hit: &mut RayHit,
intersection_fn: F,
) -> bool
pub fn ray_traverse<F: FnMut(&Ray, usize) -> f32>( &self, ray: Ray, hit: &mut RayHit, intersection_fn: F, ) -> bool
Traverse the BVH, finding the closest hit. Returns true if any primitive was hit.
Sourcepub fn ray_traverse_miss<F: FnMut(&Ray, usize) -> f32>(
&self,
ray: Ray,
intersection_fn: F,
) -> bool
pub fn ray_traverse_miss<F: FnMut(&Ray, usize) -> f32>( &self, ray: Ray, intersection_fn: F, ) -> bool
Traverse the bvh for a given Ray. Returns true if the ray missed all primitives.
Sourcepub fn ray_traverse_anyhit<F: FnMut(&Ray, usize)>(
&self,
ray: Ray,
intersection_fn: F,
)
pub fn ray_traverse_anyhit<F: FnMut(&Ray, usize)>( &self, ray: Ray, intersection_fn: F, )
Traverse the bvh for a given Ray. Intersects all primitives along ray (for things like evaluating transparency)
intersection_fn is called for all intersections. Ray is not updated to allow for evaluating at every hit.
§Arguments
ray- The ray to be tested for intersection.intersection_fn- takes the given ray and primitive index.
Sourcepub fn ray_traverse_dynamic<F: FnMut(&Ray, usize) -> f32>(
&self,
state: &mut RayTraversal,
hit: &mut RayHit,
intersection_fn: F,
) -> bool
pub fn ray_traverse_dynamic<F: FnMut(&Ray, usize) -> f32>( &self, state: &mut RayTraversal, hit: &mut RayHit, intersection_fn: F, ) -> bool
Traverse the BVH Yields at every primitive hit, returning true. Returns false when no hit is found. For basic miss test, just run until the first time it yields true. For closest hit run until it returns false and check hit.t < ray.tmax to see if it hit something For transparency, you want to hit every primitive in the ray’s path, keeping track of the closest opaque hit. and then manually setting ray.tmax to that closest opaque hit at each iteration. For best performance & customizability use the traverse! macro instead.
Sourcepub fn ray_traverse_tlas_blas<F: FnMut(&Ray, usize, usize) -> f32>(
&self,
blas: &[CwBvh],
ray: Ray,
hit: &mut RayHit,
intersection_fn: F,
) -> bool
pub fn ray_traverse_tlas_blas<F: FnMut(&Ray, usize, usize) -> f32>( &self, blas: &[CwBvh], ray: Ray, hit: &mut RayHit, intersection_fn: F, ) -> bool
This is currently mostly here just for reference. It’s setup somewhat similarly to the GPU version,
reusing the same stack for both BLAS and TLAS traversal. It might be better to traverse separately on
the CPU using two instances of Traversal with CwBvh::traverse_dynamic() or the traverse! macro.
I haven’t benchmarked this comparison yet. This example also does not take into account transforming
the ray into the local space of the blas instance. (but has comments denoting where this would happen)
Sourcepub fn compute_parents(&self) -> Vec<u32>
pub fn compute_parents(&self) -> Vec<u32>
Returns the list of parents where parent_index = parents[node_index]
Sourcepub fn order_children<T: Boundable>(
&mut self,
primitives: &[T],
direct_layout: bool,
)
pub fn order_children<T: Boundable>( &mut self, primitives: &[T], direct_layout: bool, )
Reorder the children of every BVH node. Arranges child nodes in Morton order according to their centroids so that the order in which the intersected children are traversed can be determined by the ray octant. This results in a slightly different order since the normal reordering during building is using the aabb’s from the Bvh2 and this uses the children node.p and node.e to compute the aabb. Traversal seems to be a bit slower on some scenes and a bit faster on others. Note this will rearrange self.nodes. Anything that depends on the order of self.nodes will need to be updated.
§Arguments
primitives- List of BVH primitives, implementing Boundable.direct_layout- The primitives are already laid out in bvh.primitive_indices order.
Sourcepub fn order_node_children<T: Boundable>(
&mut self,
primitives: &[T],
node_index: usize,
direct_layout: bool,
)
pub fn order_node_children<T: Boundable>( &mut self, primitives: &[T], node_index: usize, direct_layout: bool, )
Reorder the children of the given node_idx. Arranges child nodes in Morton order according to their centroids so that the order in which the intersected children are traversed can be determined by the ray octant. This results in a slightly different order since the normal reordering during building is using the aabb’s from the Bvh2 and this uses the children node.p and node.e to compute the aabb. Traversal seems to be a bit slower on some scenes and a bit faster on others. Note this will rearrange self.nodes. Anything that depends on the order of self.nodes will need to be updated.
§Arguments
primitives- List of BVH primitives, implementing Boundable.node_idx- Index of node to be reordered.direct_layout- The primitives are already laid out in bvh.primitive_indices order.