#pragma kernel BakeColorBodyIndex uint2 _ColorRes; uint2 _DepthRes; StructuredBuffer _BodyIndexMap; StructuredBuffer _Color2DepthMap; //Texture2D _ColorTex; RWStructuredBuffer _ColorBodyIndexMap; [numthreads(8, 8, 1)] void BakeColorBodyIndex(uint3 id : SV_DispatchThreadID) { //if (id.x & 1 == 0) { uint ci = id.x + id.y * _ColorRes.x; uint bi = 255; // bi0 if (!isinf(_Color2DepthMap[ci << 1])) { int dx = _Color2DepthMap[ci << 1]; int dy = _Color2DepthMap[(ci << 1) + 1]; uint di = dx + dy * _DepthRes.x; uint bi4 = _BodyIndexMap[di >> 2]; 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; } } uint bi0 = bi; // bi1 ci++; bi = 255; if (!isinf(_Color2DepthMap[ci << 1])) { int dx = _Color2DepthMap[ci << 1]; int dy = _Color2DepthMap[(ci << 1) + 1]; uint di = dx + dy * _DepthRes.x; uint bi4 = _BodyIndexMap[di >> 2]; 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; } } uint bi1 = bi << 8; // bi2 ci++; bi = 255; if (!isinf(_Color2DepthMap[ci << 1])) { int dx = _Color2DepthMap[ci << 1]; int dy = _Color2DepthMap[(ci << 1) + 1]; uint di = dx + dy * _DepthRes.x; uint bi4 = _BodyIndexMap[di >> 2]; 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; } } uint bi2 = bi << 16; // bi3 ci++; bi = 255; if (!isinf(_Color2DepthMap[ci << 1])) { int dx = _Color2DepthMap[ci << 1]; int dy = _Color2DepthMap[(ci << 1) + 1]; uint di = dx + dy * _DepthRes.x; uint bi4 = _BodyIndexMap[di >> 2]; 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; } } uint bi3 = bi << 24; _ColorBodyIndexMap[ci >> 2] = (bi0 | bi1 | bi2 | bi3); } }