

Render Textures A special type of Texture that is created and updated at runtime. See Unity documentation on ComputeShader class for more details.Ĭlosely related to compute shaders is a ComputeBuffer class, which defines arbitrary data buffer (“structured buffer” in DX11 lingo). This allows you to invoke them with ComputeShader.Dispatch function. In your script, define a variable of ComputeShader type and assign a reference to the Asset. The #pragma kernel line can optionally be followed by a number of preprocessor macros to define while compiling that kernel, for example: #pragma kernel KernelOne SOME_DEFINE DEFINE_WITH_VALUE=1337

When using multiple #pragma kernel lines, note that comments of the style // text are not permitted on the same line as the #pragma kernel directives, and cause compilation errors if used. There can be more kernels in the file just add multiple #pragma kernel lines. One compute shader Asset file must contain at least one compute kernel that can be invoked, and that function is indicated by the #pragma directive. The language is standard DX11 HLSL, with an additional #pragma kernel FillWithRed directive. Void FillWithRed (uint3 dtid : SV_DispatchThreadID) Here’s a basic example of a compute shader file, which fills the output texture with red: // pute They are written in DirectX 11 style HLSL language, with a minimal number of #pragma compilation directives to indicate which functions to compile as compute shader kernels. Similar to shader assets, compute shader assets are files in your project. Note that Mac OS X does not support OpenGL 4.3Ĭompute shader support can be queried runtime using SystemInfo.supportsComputeShaders. Modern OpenGL platforms (OpenGL 4.3 on Linux or Windows OpenGL ES 3.1 on Android). More info See in Glossary using Metal graphics APIĪndroid, Linux and Windows platforms with Vulkan API MacOS and iOS Apple’s mobile operating system.

Windows and Windows Store, with a DirectX 11 or DirectX 12 graphics API and Shader Model 5.0 GPU In order to efficiently use them, an in-depth knowledge of GPU architectures and parallel algorithms is often needed as well as knowledge of DirectCompute, OpenGL Compute, CUDA, or OpenCL.Ĭompute shaders in Unity closely match DirectX 11 DirectCompute technology. They can be used for massively parallel GPGPU algorithms, or to accelerate parts of game rendering.

More info See in Glossary programs that run on the GPU, outside of the normal rendering pipeline. Compute shaders are shader A program that runs on the GPU.
