using Unity.Mathematics; namespace UnityEngine.Rendering.UnifiedRayTracing { /// /// Shader abstraction that is used to bind resources and execute a unified ray tracing shader (.urtshader) on the GPU. /// /// /// It can be created by calling , or . /// Depending on the backend that was selected when creating the , this class either wraps /// a RayTracing or a Compute shader. /// public interface IRayTracingShader { /// /// Adds a command in cmd to set an IRayTracingAccelStruct on this shader. /// /// CommandBuffer to register the command to. /// Name of the variable in shader code. /// The IRayTracingAccelStruct to be used. void SetAccelerationStructure(CommandBuffer cmd, string name, IRayTracingAccelStruct accelStruct); /// /// Adds a command in cmd to set an integer parameter on this shader. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// Value to set. void SetIntParam(CommandBuffer cmd, int nameID, int val); /// /// Adds a command in cmd to set a float parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// Value to set. void SetFloatParam(CommandBuffer cmd, int nameID, float val); /// /// Adds a command in cmd to set a vector parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// Value to set. void SetVectorParam(CommandBuffer cmd, int nameID, Vector4 val); /// /// Adds a command in cmd to set a matrix parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// Value to set. void SetMatrixParam(CommandBuffer cmd, int nameID, Matrix4x4 val); /// /// Adds a command in cmd to set a texture parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// Texture to set. void SetTextureParam(CommandBuffer cmd, int nameID, RenderTargetIdentifier rt); /// /// Adds a command in cmd to set a buffer parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// Buffer to set. void SetBufferParam(CommandBuffer cmd, int nameID, GraphicsBuffer buffer); /// /// Adds a command in cmd to set a buffer parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// Buffer to set. void SetBufferParam(CommandBuffer cmd, int nameID, ComputeBuffer buffer); /// /// Adds a command in cmd to dispatch this IRayTracingShader. /// /// /// Dispatches to the GPU this shader to be executed on a grid of width*height*depth 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 . /// /// CommandBuffer to register the command to. /// Temporary buffer used during the shader's ray tracing calls. /// Number of threads in the X dimension. /// Number of threads in the Y dimension. /// Number of threads in the Z dimension. void Dispatch(CommandBuffer cmd, GraphicsBuffer scratchBuffer, uint width, uint height, uint depth); /// /// Adds a command in cmd to dispatch this IRayTracingShader. /// /// /// Dispatches to the GPU this shader to be executed on a grid of width*height*depth 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 . /// /// CommandBuffer to register the command to. /// Temporary buffer used during the shader's ray tracing calls. /// Buffer with work grid dimensions. void Dispatch(CommandBuffer cmd, GraphicsBuffer scratchBuffer, GraphicsBuffer argsBuffer); /// /// Adds a command in cmd to set a constant buffer parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// The buffer to bind as constant buffer. /// 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. /// The number of bytes to bind. void SetConstantBufferParam(CommandBuffer cmd, int nameID, GraphicsBuffer buffer, int offset, int size); /// /// Adds a command in cmd to set a constant buffer parameter. /// /// CommandBuffer to register the command to. /// Property name ID. Use Shader.PropertyToID to get this ID. /// The buffer to bind as constant buffer. /// 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. /// The number of bytes to bind. void SetConstantBufferParam(CommandBuffer cmd, int nameID, ComputeBuffer buffer, int offset, int size); /// /// Returns the minimum buffer size that is required by the scratchBuffer parameter of . /// This size depends on the specific values for width,height and depth that will be passed to Dispatch(). /// /// Number of threads in the X dimension. /// Number of threads in the Y dimension. /// Number of threads in the Z dimension. /// The minimum size in bytes. ulong GetTraceScratchBufferRequiredSizeInBytes(uint width, uint height, uint depth); /// /// Get the thread group sizes of this shader. /// /// Thread group size in the X,Y and Z directions. uint3 GetThreadGroupSizes(); } }