You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.6 KiB
81 lines
1.6 KiB
1 year ago
|
#pragma kernel BakeVertexTexColorResK2
|
||
|
|
||
|
uint2 PointCloudRes;
|
||
|
uint2 DepthRes;
|
||
|
float2 SpaceScale;
|
||
|
|
||
|
uint MinDepth;
|
||
|
uint MaxDepth;
|
||
|
|
||
|
int BodyIndexAll;
|
||
|
|
||
|
int BodyIndex0;
|
||
|
int BodyIndex1;
|
||
|
int BodyIndex2;
|
||
|
int BodyIndex3;
|
||
|
int BodyIndex4;
|
||
|
|
||
|
StructuredBuffer<float> SpaceTable;
|
||
|
StructuredBuffer<uint> DepthMap;
|
||
|
StructuredBuffer<uint> BodyIndexMap;
|
||
|
StructuredBuffer<float> ColorToDepthMap;
|
||
|
|
||
|
RWTexture2D<float4> PointCloudVertexTex;
|
||
|
|
||
|
|
||
|
[numthreads(8, 8, 1)]
|
||
|
void BakeVertexTexColorResK2(uint3 id : SV_DispatchThreadID)
|
||
|
{
|
||
|
uint i = id.x + id.y * PointCloudRes.x;
|
||
|
|
||
|
int dx = max(ColorToDepthMap[i << 1], 0);
|
||
|
int dy = max(ColorToDepthMap[(i << 1) + 1], 0);
|
||
|
uint di = dx + dy * DepthRes.x;
|
||
|
|
||
|
uint depth2 = DepthMap[di >> 1];
|
||
|
uint depth = di & 1 != 0 ? depth2 >> 16 : depth2 & 0xffff;
|
||
|
|
||
|
depth = (depth >= MinDepth && depth <= MaxDepth) * depth;
|
||
|
//float fDepth = (float)depth / 1000.0;
|
||
|
//bool mask = depth != 0;
|
||
|
|
||
|
uint bi4 = BodyIndexMap[di >> 2];
|
||
|
int bi = 255;
|
||
|
|
||
|
switch (di & 3)
|
||
|
{
|
||
|
case 0:
|
||
|
bi = bi4 & 255;
|
||
|
break;
|
||
|
case 1:
|
||
|
bi = (bi4 >> 8) & 255;
|
||
|
break;
|
||
|
case 2:
|
||
|
bi = (bi4 >> 16) & 255;
|
||
|
break;
|
||
|
case 3:
|
||
|
bi = (bi4 >> 24) & 255;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
bool mask = false;
|
||
|
if (BodyIndexAll != 0)
|
||
|
{
|
||
|
mask = (bi != 255);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mask = ((bi == BodyIndex0) || (bi == BodyIndex1) || (bi == BodyIndex2) || (bi == BodyIndex3) || (bi == BodyIndex4));
|
||
|
}
|
||
|
|
||
|
float fDepth = (float)(depth * mask) / 1000.0;
|
||
|
|
||
|
float3 pos = float3(
|
||
|
SpaceTable[di * 3] * fDepth * SpaceScale.x,
|
||
|
SpaceTable[di * 3 + 1] * fDepth * SpaceScale.y,
|
||
|
mask ? fDepth : 1000
|
||
|
);
|
||
|
|
||
|
PointCloudVertexTex[id.xy] = float4(pos, mask);
|
||
|
}
|