Add gaussian splat compute shader contracts

This commit is contained in:
2026-04-11 01:30:59 +08:00
parent 4080b2e5fe
commit d9bc0f1457
9 changed files with 442 additions and 8 deletions

View File

@@ -0,0 +1,56 @@
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
}
}
}