Interface IRayTracingShader
Shader abstraction that is used to bind resources and execute a unified ray tracing shader (.urtshader) on the GPU.
Namespace: UnityEngine.Rendering.UnifiedRayTracing
Assembly: Unity.UnifiedRayTracing.Runtime.dll
Syntax
public interface IRayTracingShader
Remarks
It can be created by calling CreateRayTracingShader(Object), LoadRayTracingShader(string) or LoadRayTracingShaderFromAssetBundle(AssetBundle, string). Depending on the backend that was selected when creating the RayTracingContext, this class either wraps a RayTracing or a Compute shader.
Methods
Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint)
Adds a command in cmd to dispatch this IRayTracingShader.
Declaration
void Dispatch(CommandBuffer cmd, GraphicsBuffer scratchBuffer, uint width, uint height, uint depth)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
GraphicsBuffer | scratchBuffer | Temporary buffer used during the shader's ray tracing calls. |
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. |
Remarks
Dispatches to the GPU this shader to be executed on a grid of widthheightdepth threads. Depending on the backend, the GPU ray traversal algorithm can require additional GPU storage that is supplied through the scratchBuffer parameter. Its required size can be queried by calling GetTraceScratchBufferRequiredSizeInBytes(uint, uint, uint).
Dispatch(CommandBuffer, GraphicsBuffer, GraphicsBuffer)
Adds a command in cmd to dispatch this IRayTracingShader.
Declaration
void Dispatch(CommandBuffer cmd, GraphicsBuffer scratchBuffer, GraphicsBuffer argsBuffer)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
GraphicsBuffer | scratchBuffer | Temporary buffer used during the shader's ray tracing calls. |
GraphicsBuffer | argsBuffer | Buffer with work grid dimensions. |
Remarks
Dispatches to the GPU this shader to be executed on a grid of widthheightdepth threads. The grid dimensions are read directly from the argsBuffer parameter. It needs to contain 3 integers: number of threads in X dimension, number of threads in Y dimension, number of threads in Z dimension. Typical use case is writing to argsBuffer from another shader and then dispatching this shader, without requiring a readback to the CPU. Depending on the backend, the GPU ray traversal algorithm can require additional GPU storage that is supplied through the scratchBuffer parameter. Its required size can be queried by calling GetTraceScratchBufferRequiredSizeInBytes(uint, uint, uint).
GetThreadGroupSizes()
Get the thread group sizes of this shader.
Declaration
uint3 GetThreadGroupSizes()
Returns
Type | Description |
---|---|
uint3 | Thread group size in the X,Y and Z directions. |
GetTraceScratchBufferRequiredSizeInBytes(uint, uint, uint)
Returns the minimum buffer size that is required by the scratchBuffer parameter of Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint). This size depends on the specific values for width,height and depth that will be passed to Dispatch().
Declaration
ulong GetTraceScratchBufferRequiredSizeInBytes(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 minimum size in bytes. |
SetAccelerationStructure(CommandBuffer, string, IRayTracingAccelStruct)
Adds a command in cmd to set an IRayTracingAccelStruct on this shader.
Declaration
void SetAccelerationStructure(CommandBuffer cmd, string name, IRayTracingAccelStruct accelStruct)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
string | name | Name of the variable in shader code. |
IRayTracingAccelStruct | accelStruct | The IRayTracingAccelStruct to be used. |
SetBufferParam(CommandBuffer, int, ComputeBuffer)
Adds a command in cmd to set a buffer parameter.
Declaration
void SetBufferParam(CommandBuffer cmd, int nameID, ComputeBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
ComputeBuffer | buffer | Buffer to set. |
SetBufferParam(CommandBuffer, int, GraphicsBuffer)
Adds a command in cmd to set a buffer parameter.
Declaration
void SetBufferParam(CommandBuffer cmd, int nameID, GraphicsBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
GraphicsBuffer | buffer | Buffer to set. |
SetConstantBufferParam(CommandBuffer, int, ComputeBuffer, int, int)
Adds a command in cmd to set a constant buffer parameter.
Declaration
void SetConstantBufferParam(CommandBuffer cmd, int nameID, ComputeBuffer buffer, int offset, int size)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
ComputeBuffer | buffer | The buffer to bind as constant buffer. |
int | offset | The offset in bytes from the beginning of the buffer to bind. Must be a multiple of SystemInfo.constantBufferOffsetAlignment, or 0 if that value is 0. |
int | size | The number of bytes to bind. |
SetConstantBufferParam(CommandBuffer, int, GraphicsBuffer, int, int)
Adds a command in cmd to set a constant buffer parameter.
Declaration
void SetConstantBufferParam(CommandBuffer cmd, int nameID, GraphicsBuffer buffer, int offset, int size)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
GraphicsBuffer | buffer | The buffer to bind as constant buffer. |
int | offset | The offset in bytes from the beginning of the buffer to bind. Must be a multiple of SystemInfo.constantBufferOffsetAlignment, or 0 if that value is 0. |
int | size | The number of bytes to bind. |
SetFloatParam(CommandBuffer, int, float)
Adds a command in cmd to set a float parameter.
Declaration
void SetFloatParam(CommandBuffer cmd, int nameID, float val)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
float | val | Value to set. |
SetIntParam(CommandBuffer, int, int)
Adds a command in cmd to set an integer parameter on this shader.
Declaration
void SetIntParam(CommandBuffer cmd, int nameID, int val)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
int | val | Value to set. |
SetMatrixParam(CommandBuffer, int, Matrix4x4)
Adds a command in cmd to set a matrix parameter.
Declaration
void SetMatrixParam(CommandBuffer cmd, int nameID, Matrix4x4 val)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
Matrix4x4 | val | Value to set. |
SetTextureParam(CommandBuffer, int, RenderTargetIdentifier)
Adds a command in cmd to set a texture parameter.
Declaration
void SetTextureParam(CommandBuffer cmd, int nameID, RenderTargetIdentifier rt)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
RenderTargetIdentifier | rt | Texture to set. |
SetVectorParam(CommandBuffer, int, Vector4)
Adds a command in cmd to set a vector parameter.
Declaration
void SetVectorParam(CommandBuffer cmd, int nameID, Vector4 val)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | CommandBuffer to register the command to. |
int | nameID | Property name ID. Use Shader.PropertyToID to get this ID. |
Vector4 | val | Value to set. |