![Line with pink and purple gradient](/_app/immutable/assets/compute-base-497ea7ee.jpg)
![Unreal Blueprint graph calling a compute shader](/_app/immutable/assets/compute-base-shot-2a2b1c10.png)
Bare-bones Compute Shader in UE5
A minimal compute-shader scaffold. Great as a starting point for new shaders or for learning the basics of how shaders are defined in Unreal.
Get the code
Usage
- Generate or download the template using the instructions above
- Rebuild your project
- Create or navigate to an existing Blueprint
- Right-click and add the node called “Execute Base Compute Shader”
Notes
- The mechanism used for detecting when the results are ready on the CPU is for example purposes (see
F[NAME]Interface::DispatchRenderThread - RunnerFunc
). A better strategy would be to queue and check a list of buffers per tick in an external singleton.
Helpful reading
- Using Compute Shaders in Unreal Engine 4
- Overview of Shaders in Plugins
- UE4ShaderPluginDemo
- Render Dependency Graph
Sample snippet
// base.usf
#include "/Engine/Public/Platform.ush"
Buffer<int> Input;
RWBuffer<int> Output;
[numthreads(THREADS_X, THREADS_Y, THREADS_Z)]
void BaseExample(
uint3 DispatchThreadId : SV_DispatchThreadID,
uint GroupIndex : SV_GroupIndex )
{
// Outputs one number
Output[0] = Input[0] * Input[1];
}