Skip to content

Instantly share code, notes, and snippets.

@douduck08
Created December 28, 2021 05:57
Show Gist options
  • Save douduck08/396e2f085ed089e7ebc019b483f6ca24 to your computer and use it in GitHub Desktop.
Save douduck08/396e2f085ed089e7ebc019b483f6ca24 to your computer and use it in GitHub Desktop.
Unity compute shader template
#pragma kernel CSMain
#define THREAD_GROUP_SIZE_X 8
#define THREAD_GROUP_SIZE_Y 8
#define THREAD_GROUP_SIZE_Z 1
// Buffers
RWTexture2D<float4> Result;
// Functions
// Kernels
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, THREAD_GROUP_SIZE_Z)]
void CSMain (
in uint3 dispatchThreadID : SV_DispatchThreadID, // DispatchThreadID = dot(GroupID, numthreads) + GroupThreadId;
in uint groupIndex : SV_GroupIndex, // uint GroupIndex = unique index of a thread inside a group
in uint3 groupID : SV_GroupID, // GroupID = index for each dimension inside a ThreadGroupCount
in uint3 groupThreadID : SV_GroupThreadID // uint3 GroupThreadId = indices for each dimension inside a group of the current thread
) {
Result[id.xy] = float4(dispatchThreadID.x & dispatchThreadID.y, (dispatchThreadID.x & 15) / 15.0, (dispatchThreadID.y & 15) / 15.0, 0.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment