Docs / Ray tracing

Glossary: MeshBlas

The members of MeshBlas, in alphabetical order.

Color legend plain property method

A bounding volume hierarchy over one mesh’s triangles, in the mesh’s own space: the bottom level of the two. Built once per mesh, and shared by every instance of it.

A sealed class with no public constructor: Build makes one. The meshes page shows it in context, with code. A refit changes it for every Tlas that uses it: don’t refit while one of them is being queried.

Names are colored by what they are: a property or a method; values and fields keep the plain color.

Properties

Bvh →

Bvh · Read-only. The tree over the triangles: its nodes, and the order of the triangles in its leaves. See the BVH page.

Geometry →

ITriangleMesh · Read-only. The mesh the BLAS was built from. A refit reads it again, and the attributes of a hit are looked up in it, by TriangleIndex.

LocalBounds →

BoundingBox · Read-only. The tight box around the triangles, in the mesh’s space: the box of the tree’s root. A Tlas transforms it into each instance’s box in the scene. Only Refit moves it.

Triangles →

ReadOnlySpan<GpuTriangle> · Read-only. The triangles as the walks test them, a corner and two edges each, in the tree’s order: entry i is triangle Bvh.PrimitiveIndices[i] of Geometry, so a leaf’s triangles are one run. Filled by the build and by every refit; the GPU copy sends them as they are.

Version →

int · Read-only. 0 when built, one more after every Refit. A Tlas and a GpuAccelerationStructure compare it with the version they last saw, to tell a BLAS that moved.

Methods

Build() →

Build(ITriangleMesh geometry) · Static. Returns MeshBlas?: a tree over the mesh’s triangles, or null for a mesh with none, which has nothing to trace. Reads the mesh twice, once for each triangle’s box and centroid and once more for the triangles in the tree’s order, and allocates: build at load time. Throws ArgumentNullException for a null mesh.

Parameter Type Description
geometry ITriangleMesh The mesh, in its own space.

Intersect() →

Intersect(in Ray ray, float maxDistance, out float distance, out int triangleIndex, out float u, out float v) · Whether the ray hits a triangle closer than maxDistance, and the nearest: the closest hit on this mesh alone, in its own space. The direction need not be of length 1, and the distance is in the ray’s own parameter: a world ray taken into the mesh’s space without normalizing its direction gets the distance along the world ray. Hits closer than 10−4 are ignored.

Parameter Type Description
ray Ray The ray, in the mesh’s space.
maxDistance float Hits at or beyond this ray parameter are left out.
distance out float The hit’s ray parameter; maxDistance when there is none.
triangleIndex out int The triangle hit, as GetTriangle numbers it; −1 for none.
u out float The hit’s barycentric weight of the triangle’s second corner. Not a texture coordinate.
v out float The weight of its third corner. The first’s is 1 - u - v.

IntersectAny() →

IntersectAny(in Ray ray, float maxDistance) · Whether any triangle blocks the ray closer than maxDistance, in the mesh’s space. Stops at the first hit and keeps no order, so it walks the nodes in one forward pass with no stack, and costs less than the closest hit. The root’s own box isn’t tested.

Parameter Type Description
ray Ray The ray, in the mesh’s space.
maxDistance float Hits at or beyond this ray parameter don’t count.

Refit() →

Refit() · Reads the mesh’s current positions, copies the triangles and recomputes every box, keeping the tree’s shape: for a mesh that deforms, a skinned character or a cloth. Moves LocalBounds and Version; the next Tlas.Add of an instance and the next Upload follow it with no other call. The splits stay the ones chosen for the pose it was built in, so after a large change of pose, build afresh. Throws InvalidOperationException when the mesh no longer has the triangle count it was built with.