44 lines
1.1 KiB
HLSL
44 lines
1.1 KiB
HLSL
#define GROUP_SIZE 64
|
|
|
|
cbuffer FrameConstants : register(b0)
|
|
{
|
|
float4x4 gViewProjection;
|
|
float4x4 gView;
|
|
float4x4 gProjection;
|
|
float4 gCameraWorldPos;
|
|
float4 gScreenParams;
|
|
float4 gSettings;
|
|
};
|
|
|
|
ByteAddressBuffer gPositions : register(t0);
|
|
StructuredBuffer<uint> gOrderBuffer : register(t1);
|
|
RWStructuredBuffer<uint> gSortKeys : register(u0);
|
|
|
|
float3 LoadFloat3(ByteAddressBuffer buffer, uint byteOffset)
|
|
{
|
|
return asfloat(buffer.Load3(byteOffset));
|
|
}
|
|
|
|
uint FloatToSortableUint(float value)
|
|
{
|
|
uint bits = asuint(value);
|
|
uint mask = (0u - (bits >> 31)) | 0x80000000u;
|
|
return bits ^ mask;
|
|
}
|
|
|
|
[numthreads(GROUP_SIZE, 1, 1)]
|
|
void MainCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
uint index = dispatchThreadId.x;
|
|
uint splatCount = (uint)gSettings.x;
|
|
if (index >= splatCount)
|
|
{
|
|
return;
|
|
}
|
|
|
|
uint splatIndex = gOrderBuffer[index];
|
|
float3 position = LoadFloat3(gPositions, splatIndex * 12);
|
|
float3 viewPosition = mul(float4(position, 1.0), gView).xyz;
|
|
gSortKeys[index] = FloatToSortableUint(viewPosition.z);
|
|
}
|