57 lines
1.7 KiB
GLSL
57 lines
1.7 KiB
GLSL
Shader "Builtin Gaussian Splat Utilities"
|
|
{
|
|
HLSLINCLUDE
|
|
uint FloatToSortableUint(float value)
|
|
{
|
|
const uint rawValue = asuint(value);
|
|
const uint mask = (rawValue & 0x80000000u) != 0u ? 0xffffffffu : 0x80000000u;
|
|
return rawValue ^ mask;
|
|
}
|
|
ENDHLSL
|
|
|
|
SubShader
|
|
{
|
|
Pass
|
|
{
|
|
Name "GaussianSplatPrepareOrder"
|
|
HLSLPROGRAM
|
|
#pragma target 4.5
|
|
#pragma compute GaussianSplatPrepareOrderCS
|
|
|
|
cbuffer PerObjectConstants
|
|
{
|
|
float4x4 gProjectionMatrix;
|
|
float4x4 gViewMatrix;
|
|
float4x4 gModelMatrix;
|
|
float4 gCameraRight;
|
|
float4 gCameraUp;
|
|
};
|
|
|
|
StructuredBuffer<float3> GaussianSplatPositions;
|
|
RWStructuredBuffer<uint> GaussianSplatSortDistances;
|
|
RWStructuredBuffer<uint> GaussianSplatOrderBuffer;
|
|
|
|
[numthreads(64, 1, 1)]
|
|
void GaussianSplatPrepareOrderCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
uint splatCount = 0u;
|
|
GaussianSplatOrderBuffer.GetDimensions(splatCount);
|
|
|
|
const uint index = dispatchThreadId.x;
|
|
if (index >= splatCount)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GaussianSplatOrderBuffer[index] = index;
|
|
|
|
const float3 localCenter = GaussianSplatPositions[index];
|
|
const float3 viewCenter =
|
|
mul(gViewMatrix, mul(gModelMatrix, float4(localCenter, 1.0))).xyz;
|
|
GaussianSplatSortDistances[index] = FloatToSortableUint(viewCenter.z);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|