docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class RayTracingHelper

    Helper functions that can be used to create a scratch buffer.

    Inheritance
    object
    RayTracingHelper
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.Rendering.UnifiedRayTracing
    Assembly: Unity.UnifiedRayTracing.Runtime.dll
    Syntax
    public static class RayTracingHelper
    Remarks

    A scratch buffer is a GraphicsBuffer that Unity uses during the acceleration structure build or the ray tracing dispatch to store temporary data.

    Fields

    ScratchBufferTarget

    UnityEngine.GraphicsBuffer.Target suitable for scratch buffers used in for both Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint) and Build(CommandBuffer, GraphicsBuffer).

    Declaration
    public const GraphicsBuffer.Target ScratchBufferTarget = Structured
    Field Value
    Type Description
    GraphicsBuffer.Target

    Methods

    CreateDispatchIndirectBuffer()

    Creates an indirect args buffer suitable for Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    Declaration
    public static GraphicsBuffer CreateDispatchIndirectBuffer()
    Returns
    Type Description
    GraphicsBuffer

    The scratch buffer.

    CreateScratchBufferForBuild(IRayTracingAccelStruct)

    Creates a scratch buffer suitable for Build(CommandBuffer, GraphicsBuffer).

    Declaration
    public static GraphicsBuffer CreateScratchBufferForBuild(IRayTracingAccelStruct accelStruct)
    Parameters
    Type Name Description
    IRayTracingAccelStruct accelStruct

    The acceleration structure that will be passed to Build(CommandBuffer, GraphicsBuffer).

    Returns
    Type Description
    GraphicsBuffer

    The scratch buffer.

    CreateScratchBufferForBuildAndDispatch(IRayTracingAccelStruct, IRayTracingShader, uint, uint, uint)

    Creates a scratch buffer suitable for both Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint) and Build(CommandBuffer, GraphicsBuffer).

    Declaration
    public static GraphicsBuffer CreateScratchBufferForBuildAndDispatch(IRayTracingAccelStruct accelStruct, IRayTracingShader shader, uint dispatchWidth, uint dispatchHeight, uint dispatchDepth)
    Parameters
    Type Name Description
    IRayTracingAccelStruct accelStruct

    The acceleration structure that will be passed to Build(CommandBuffer, GraphicsBuffer).

    IRayTracingShader shader

    The shader that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchWidth

    Number of threads in the X dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchHeight

    Number of threads in the Y dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchDepth

    Number of threads in the Z dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    Returns
    Type Description
    GraphicsBuffer

    The scratch buffer.

    CreateScratchBufferForTrace(IRayTracingShader, uint, uint, uint)

    Creates a scratch buffer suitable for Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    Declaration
    public static GraphicsBuffer CreateScratchBufferForTrace(IRayTracingShader shader, uint dispatchWidth, uint dispatchHeight, uint dispatchDepth)
    Parameters
    Type Name Description
    IRayTracingShader shader

    The shader that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchWidth

    Number of threads in the X dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchHeight

    Number of threads in the Y dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchDepth

    Number of threads in the Z dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    Returns
    Type Description
    GraphicsBuffer

    The scratch buffer.

    ResizeScratchBufferForBuild(IRayTracingAccelStruct, ref GraphicsBuffer)

    Resizes a scratch buffer if its size doesn't fit the requirement of Build(CommandBuffer, GraphicsBuffer).

    Declaration
    public static void ResizeScratchBufferForBuild(IRayTracingAccelStruct accelStruct, ref GraphicsBuffer scratchBuffer)
    Parameters
    Type Name Description
    IRayTracingAccelStruct accelStruct

    The acceleration structure that will be passed to Build(CommandBuffer, GraphicsBuffer).

    GraphicsBuffer scratchBuffer

    The scratch buffer.

    Remarks

    The resize is accomplished by disposing of the GraphicsBuffer and instanciating a new one at the proper size.

    ResizeScratchBufferForTrace(IRayTracingShader, uint, uint, uint, ref GraphicsBuffer)

    Resizes a scratch buffer if its size doesn't fit the requirement of Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    Declaration
    public static void ResizeScratchBufferForTrace(IRayTracingShader shader, uint dispatchWidth, uint dispatchHeight, uint dispatchDepth, ref GraphicsBuffer scratchBuffer)
    Parameters
    Type Name Description
    IRayTracingShader shader

    The shader that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchWidth

    Number of threads in the X dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchHeight

    Number of threads in the Y dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    uint dispatchDepth

    Number of threads in the Z dimension that will be passed to Dispatch(CommandBuffer, GraphicsBuffer, uint, uint, uint).

    GraphicsBuffer scratchBuffer

    The scratch buffer.

    Remarks

    The resize is accomplished by disposing of the GraphicsBuffer and instanciating a new one at the proper size.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)