Class RayTracingContext
Entry point for the UnifiedRayTracing API.
Implements
Inherited Members
Namespace: UnityEngine.Rendering.UnifiedRayTracing
Assembly: Unity.UnifiedRayTracing.Runtime.dll
Syntax
public sealed class RayTracingContext : IDisposable
Remarks
It provides functionality to:
- load shader code (CreateRayTracingShader)
- create an acceleration structure (CreateAccelerationStructure) that represents the geometry to be ray traced against.
Constructors
RayTracingContext(RayTracingBackend, RayTracingResources)
Creates a RayTracingContext.
Declaration
public RayTracingContext(RayTracingBackend backend, RayTracingResources resources)
Parameters
Type | Name | Description |
---|---|---|
RayTracingBackend | backend | The chosen backend. |
RayTracingResources | resources | The resources (provides the various shaders the context needs to operate). |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when the supplied backend is not supported. |
RayTracingContext(RayTracingResources)
Creates a RayTracingContext.
Declaration
public RayTracingContext(RayTracingResources resources)
Parameters
Type | Name | Description |
---|---|---|
RayTracingResources | resources | The resources (provides the various shaders the context needs to operate). |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when no supported backend is available. |
Properties
BackendType
The RayTracingBackend this context was created with.
Declaration
public RayTracingBackend BackendType { get; }
Property Value
Type | Description |
---|---|
RayTracingBackend |
Resources
RayTracingResources object this context has been created with.
Declaration
public RayTracingResources Resources { get; }
Property Value
Type | Description |
---|---|
RayTracingResources |
Methods
CreateAccelerationStructure(AccelerationStructureOptions)
Creates a IRayTracingAccelStruct.
Declaration
public IRayTracingAccelStruct CreateAccelerationStructure(AccelerationStructureOptions options)
Parameters
Type | Name | Description |
---|---|---|
AccelerationStructureOptions | options | Options for quality/performance trade-offs for the returned acceleration structure |
Returns
Type | Description |
---|---|
IRayTracingAccelStruct | The acceleration structure. |
CreateRayTracingShader(Object)
Creates a IRayTracingShader.
Declaration
public IRayTracingShader CreateRayTracingShader(Object shader)
Parameters
Type | Name | Description |
---|---|---|
Object | shader | The ComputeShader or RayTracingShader asset. |
Returns
Type | Description |
---|---|
IRayTracingShader | The unified ray tracing shader. |
Remarks
Depending on the chosen backend, the shader parameter needs to be either a ComputeShader or RayTracingShader.
Dispose()
Disposes the RaytracingContext.
Declaration
public void Dispose()
Remarks
Before calling this, all IRayTracingAccelStruct that have been created with this RayTracingContext must be disposed as well.
GetRequiredTraceScratchBufferSizeInBytes(uint, uint, uint)
Returns the minimum size that is required by the scratchBuffer parameter of Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).
Declaration
public ulong GetRequiredTraceScratchBufferSizeInBytes(uint width, uint height, uint depth)
Parameters
Type | Name | Description |
---|---|---|
uint | width | Number of threads in the X dimension. |
uint | height | Number of threads in the Y dimension. |
uint | depth | Number of threads in the Z dimension. |
Returns
Type | Description |
---|---|
ulong | The size in bytes. |
GetScratchBufferStrideInBytes()
Required stride for the creation of the scratchBuffers used by Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint) and Build(CommandBuffer, GraphicsBuffer).
Declaration
public static uint GetScratchBufferStrideInBytes()
Returns
Type | Description |
---|---|
uint | The required stride. |
IsBackendSupported(RayTracingBackend)
Checks if the specified backend is supported on the current GPU.
Declaration
public static bool IsBackendSupported(RayTracingBackend backend)
Parameters
Type | Name | Description |
---|---|---|
RayTracingBackend | backend | The backend. |
Returns
Type | Description |
---|---|
bool | Whether the specified bakend is supported. |
LoadRayTracingShader(string)
Creates a unified ray tracing shader from .urtshader asset file.
Declaration
public IRayTracingShader LoadRayTracingShader(string fileName)
Parameters
Type | Name | Description |
---|---|---|
string | fileName | Path to the .urtshader shader asset file to load. |
Returns
Type | Description |
---|---|
IRayTracingShader | The unified ray tracing shader. |
Remarks
- This API works only in the Unity Editor, not at runtime.
- The path must be relative to the project folder, for example: "Assets/Stuff/myshader.urtshader".
- A .urtshader asset file is imported in the Editor as 2 shaders: a ComputeShader and a RayTracingShader. LoadRayTracingShader loads the one relevant one depending on the RayTracingContext's backend.
LoadRayTracingShaderFromAssetBundle(AssetBundle, string)
Creates a unified ray tracing shader from an AssetBundle.
Declaration
public IRayTracingShader LoadRayTracingShaderFromAssetBundle(AssetBundle assetBundle, string name)
Parameters
Type | Name | Description |
---|---|---|
AssetBundle | assetBundle | The AssetBundle. |
string | name | The asset name with the .urtshader extension included. |
Returns
Type | Description |
---|---|
IRayTracingShader | The unified ray tracing shader. |