CwBvh

Struct CwBvh 

Source
#[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: bool

Indicates 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

Source

pub fn new_ray_traversal(&self, ray: Ray) -> RayTraversal

Source

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.

Source

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.

Source

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.

Source

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.
Source

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.

Source

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)

Source

pub fn compute_parents(&self) -> Vec<u32>

Returns the list of parents where parent_index = parents[node_index]

Source

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.
Source

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.
Source

pub fn validate<T: Boundable>( &self, primitives: &[T], direct_layout: bool, ) -> CwBvhValidationResult

Direct layout: The primitives are already laid out in bvh.primitive_indices order.

Trait Implementations§

Source§

impl Clone for CwBvh

Source§

fn clone(&self) -> CwBvh

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CwBvh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CwBvh

Source§

fn default() -> CwBvh

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CwBvh

Source§

fn eq(&self, other: &CwBvh) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CwBvh

Auto Trait Implementations§

§

impl Freeze for CwBvh

§

impl RefUnwindSafe for CwBvh

§

impl Send for CwBvh

§

impl Sync for CwBvh

§

impl Unpin for CwBvh

§

impl UnwindSafe for CwBvh

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.