Interface IRayTracingAccelStruct
A data structure used to represent a collection of instances and geometries that are used for GPU ray tracing. It can be created by calling CreateAccelerationStructure(AccelerationStructureOptions).
Inherited Members
Namespace: UnityEngine.Rendering.UnifiedRayTracing
Assembly: Unity.UnifiedRayTracing.Runtime.dll
Syntax
public interface IRayTracingAccelStruct : IDisposable
Methods
AddInstance(MeshInstanceDesc)
Adds an instance to the RayTracingAccelerationStructure.
Declaration
int AddInstance(MeshInstanceDesc meshInstance)
Parameters
Type | Name | Description |
---|---|---|
MeshInstanceDesc | meshInstance | The parameters describing this instance. |
Returns
Type | Description |
---|---|
int | A value representing a handle that you can use to perform later actions (e.g. RemoveInstance...) |
Exceptions
Type | Condition |
---|---|
UnifiedRayTracingException | Thrown if the instance cannot be added. Inspect errorCode for the reason. |
Build(CommandBuffer, GraphicsBuffer)
Adds a command in cmd to build this acceleration structure on the GPU.
Declaration
void Build(CommandBuffer cmd, GraphicsBuffer scratchBuffer)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the build command to. |
GraphicsBuffer | scratchBuffer | Temporary buffer used during the build. |
Remarks
Depending on the backend, the GPU build algorithm can require additional GPU storage that is supplied through the scratchBuffer parameter. Its required size can be queried by calling GetBuildScratchBufferRequiredSizeInBytes().
Exceptions
Type | Condition |
---|---|
UnifiedRayTracingException | Thrown if the build failed. Inspect errorCode for the reason. |
ClearInstances()
Removes all ray tracing instances from the acceleration structure.
Declaration
void ClearInstances()
GetBuildScratchBufferRequiredSizeInBytes()
Returns the minimum buffer size that is required by the scratchBuffer parameter of Build(CommandBuffer, GraphicsBuffer).
Declaration
ulong GetBuildScratchBufferRequiredSizeInBytes()
Returns
Type | Description |
---|---|
ulong | The minimum size in bytes. |
RemoveInstance(int)
Removes an instance.
Declaration
void RemoveInstance(int instanceHandle)
Parameters
Type | Name | Description |
---|---|---|
int | instanceHandle | The handle associated with an instance. |
UpdateInstanceID(int, uint)
Updates the instance ID of an instance.
Declaration
void UpdateInstanceID(int instanceHandle, uint instanceID)
Parameters
Type | Name | Description |
---|---|---|
int | instanceHandle | The handle associated with an instance. |
uint | instanceID | The new instance ID. |
UpdateInstanceMask(int, uint)
Updates the instance mask of an instance.
Declaration
void UpdateInstanceMask(int instanceHandle, uint mask)
Parameters
Type | Name | Description |
---|---|---|
int | instanceHandle | The handle associated with an instance. |
uint | mask | The new mask. |
Remarks
Ray tracing instances in the acceleration structure contain an 8-bit user defined instance mask. The TraceRay() HLSL function has an 8-bit input parameter, InstanceInclusionMask which gets ANDed with the instance mask from any ray tracing instance that is a candidate for intersection during acceleration structure traversal on the GPU. If the result of the AND operation is zero, the GPU ignores the intersection.
UpdateInstanceTransform(int, Matrix4x4)
Updates the transformation of an instance.
Declaration
void UpdateInstanceTransform(int instanceHandle, Matrix4x4 localToWorldMatrix)
Parameters
Type | Name | Description |
---|---|---|
int | instanceHandle | The handle associated with an instance. |
Matrix4x4 | localToWorldMatrix | The new transformation matrix of the instance. |