none
Kinect For Windows Unity Pro Plugin DepthSourceView.cs Script RRS feed

  • Question

  • In the DepthSourceView.cs Script there is a const _DownSampleSize = 4 what is its use and why does it have to be equal to 4?
    Thursday, February 27, 2020 12:01 PM

Answers

  • From what I read, they basically create a mesh from a smaller version of the depth texture so it's lighter. To do that, they average neighborhoods of 4x4 pixels and the result is placed in the smaller texture for the UVs. DownSampleSize is the step of sampling per row and per column, which pretty much costructs those 4x4 regions. You could say that they collapse every 4x4 region into one pixel by taking the 4x4 region's average as the 1 pixel's value.

    So in the end, anything they want to do with the downres'd version of the texture is gonna be faster as it's 1/16th of the 512x424 texture. And it seems it's good enough for creating a mesh per frame. For example, here they produce a mesh that's consisted of 13568(512/4=128, 424/4=106, 128x106=13568) vertices and the equivalent per-vertex UVs, instead of 217088 if they had used the full 512x424 depth texture. Also considering when this plugin was written, it meant having a mesh that did not exceed the 16bit mesh indexing that Unity had, which the full texture would have done.

    This is my assumption, but typically when you deal with textures you don't want to create odd number dimensions. In this case, proper downscale of a 512x424 means using some common factor, which in this case means 1,2,4,8. But dividing with 8 produces 53 on the Y dimension. So the next best case is 4. If they picked 2, it might have also worked and it would have been under the 2^16=65536 index limit but I'm thinking it might have been a bit too much work to do per frame, especially when they also sample textures. So I assume they chose 4 as a good trade off.

    • Marked as answer by Omar Yatim Thursday, February 27, 2020 3:45 PM
    Thursday, February 27, 2020 3:39 PM

All replies

  • From what I read, they basically create a mesh from a smaller version of the depth texture so it's lighter. To do that, they average neighborhoods of 4x4 pixels and the result is placed in the smaller texture for the UVs. DownSampleSize is the step of sampling per row and per column, which pretty much costructs those 4x4 regions. You could say that they collapse every 4x4 region into one pixel by taking the 4x4 region's average as the 1 pixel's value.

    So in the end, anything they want to do with the downres'd version of the texture is gonna be faster as it's 1/16th of the 512x424 texture. And it seems it's good enough for creating a mesh per frame. For example, here they produce a mesh that's consisted of 13568(512/4=128, 424/4=106, 128x106=13568) vertices and the equivalent per-vertex UVs, instead of 217088 if they had used the full 512x424 depth texture. Also considering when this plugin was written, it meant having a mesh that did not exceed the 16bit mesh indexing that Unity had, which the full texture would have done.

    This is my assumption, but typically when you deal with textures you don't want to create odd number dimensions. In this case, proper downscale of a 512x424 means using some common factor, which in this case means 1,2,4,8. But dividing with 8 produces 53 on the Y dimension. So the next best case is 4. If they picked 2, it might have also worked and it would have been under the 2^16=65536 index limit but I'm thinking it might have been a bit too much work to do per frame, especially when they also sample textures. So I assume they chose 4 as a good trade off.

    • Marked as answer by Omar Yatim Thursday, February 27, 2020 3:45 PM
    Thursday, February 27, 2020 3:39 PM
  • Thank you
    Thursday, February 27, 2020 3:45 PM