Pink numbers in a bounding box
Unreal Blueprint graph calling a compute shader

Writing to a render target

Writing to a render target via compute in UE5

Drawing to render targets from compute shaders is an extremely useful method to render all sorts of things that need multiple passes or expensive calculations cached.

Get the code

$ shadeup-unreal
 > [COMPUTE] Compute Shader
 > Render Target
OR

Applications

Usage

  1. Generate or download the template using the instructions above
  2. Rebuild your project
  3. Create or navigate to an existing Blueprint
  4. Right-click and add the node called “Execute RTCompute Shader”

Notes

Helpful reading


Sample snippet

// rt.usf

#include "/Engine/Generated/Material.ush"
#include "/Engine/Public/Platform.ush"

RWTexture2D<float3> RenderTarget;

[numthreads(THREADS_X, THREADS_Y, THREADS_Z)]
void RTExample(
	uint3 DispatchThreadId : SV_DispatchThreadID,
	uint GroupIndex : SV_GroupIndex )
{
	// Simple checkerboard
	int x = floor(DispatchThreadId.x / 16.f);
	int y = floor(DispatchThreadId.y / 16.f);
	int c = (x + y % 2) % 2;

	RenderTarget[DispatchThreadId.xy] = float3(c, c, c);
}