Docs / Ray tracing

Glossary: Tlas

The members of Tlas, in alphabetical order.

Color legend plain property method

The scene as rays see it: a bounding volume hierarchy over instances, each a MeshBlas placed by a world matrix under an id of yours. The top level of the two, and the CPU queries.

A sealed class. It is declared anew at every update, and works out on its own whether that means nothing, a refit or a rebuild. The scene page shows it in context, with code. It isn’t thread-safe: see threads.

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 instances’ boxes in the scene, one instance a leaf. Refitted or rebuilt by EndUpdate.

FlagsVersion →

int · Read-only. Moves when an update changed an instance’s flags and nothing else about it, the one change that leaves the tree, and so Version, alone. Flags that changed along with anything else ride on Version’s move, so a mirror of the instances watches both.

InstanceCount →

int · Read-only. How many instances have been declared since BeginUpdate: after EndUpdate, the scene’s. The Add calls of the update, less the ones ignored.

Instances →

ReadOnlySpan<TlasInstance> · Read-only. The instances, in the order they were declared. InstanceIndex is a place in it. It reads the Tlas’s own array: read it between an EndUpdate and the next BeginUpdate, and don’t keep it across an update.

Version →

int · Read-only. Moves whenever the tree does: at every refit and every rebuild, the first EndUpdate included. A GpuAccelerationStructure sends the scene again when it has moved.

Methods

Tlas() →

Tlas() · An empty scene: no instances and an empty tree. Its first EndUpdate builds the tree, even with nothing declared.

Add() →

Add(ulong instanceId, MeshBlas? blas, in Matrix world, RayTracingFlags flags = RayTracingFlags.Default) · Declares one instance for this update. It is compared with what the same place held in the last update: the same id and BLAS with the same matrix and BLAS Version cost a few comparisons, and anything else is worked out afresh. A null BLAS is ignored. A matrix that squashes the mesh flat is traced through a stand-in a ten-thousandth of its longest axis thick, see IsFlat; one that collapses it to a line or a point, holds an infinity or a NaN, or puts its box beyond float’s range is ignored. Declare the instances in the same order every update: another order is still right, but rebuilds the tree.

Parameter Type Description
instanceId ulong Your id for the object, handed back in InstanceId. Only ever compared.
blas MeshBlas? Its geometry, in its own space. null declares nothing.
world Matrix Its world matrix, in MonoGame’s row-vector convention.
flags RayTracingFlags The queries it takes part in. Default: Default, all of them.

BeginUpdate() →

BeginUpdate() · Starts an update: no instances until they are added. The last update’s stay where they are, to compare the new ones with.

EndUpdate() →

EndUpdate() · Returns TlasUpdateResult: brings the tree in line with the instances declared since BeginUpdate, doing the least that does. It rebuilds the tree when instances were added, removed or reordered. Otherwise it refits the tree when an instance’s box moved, and rebuilds it after all when the refit took the root’s area past twice, or the tree’s AreaCost past one and a half times, the last build’s. Moves Version when the tree moved, and FlagsVersion when flags alone changed.

Intersect() →

Intersect(in Ray ray, float maxDistance, out RayHit hit, RayTracingFlags mask = RayTracingFlags.None) · Whether the ray hits an instance with every flag in mask closer than maxDistance, and the nearest such hit. The ray is in world space and its direction need not be of length 1: the hit’s distance is in its parameter, which it keeps through each instance’s inverse matrix. Opens the nearer child of each node first, and takes an infinite maxDistance as it is. Doesn’t allocate.

Parameter Type Description
ray Ray The ray, in world space.
maxDistance float Hits at or beyond this ray parameter are left out. float.MaxValue for no limit.
hit out RayHit The nearest hit, or RayHit.None(maxDistance) when there is none.
mask RayTracingFlags Only instances with every flag in it are seen. Default: None, every instance.

IntersectAny() →

IntersectAny(in Ray ray, float maxDistance, RayTracingFlags mask = RayTracingFlags.None) · Whether anything with every flag in mask blocks the ray closer than maxDistance. Stops at the first hit, in no order, and walks with no stack: the walk RtTraceAny is a port of. Takes an infinite maxDistance as float.MaxValue, as the GPU does. Doesn’t allocate.

Parameter Type Description
ray Ray The ray, in world space, starting off the surface it leaves.
maxDistance float Hits at or beyond this ray parameter don’t count: the distance to a lamp, say.
mask RayTracingFlags Only instances with every flag in it block the ray. Default: None, every instance.