Arfoundation-samples: HumanSegmentation - How to make Occlusion

Created on 2 Aug 2019  路  1Comment  路  Source: Unity-Technologies/arfoundation-samples

I'm trying to achieve occlusion by using 2 cameras and a rendertexture on a plane.
therefore i'm first trying to just make a mask over the areas where humans are detected.

in the file "TestDepthImage.cs" i can access the Texture2D humanStencil.
Unfortunately i just can't get the values out of this texture. when i'm calling the method GetRawTextureData() it has a Length of 0.
and when i call GetPixels() every pixel is the same value (0, 0, 0, 0).
the format is R8 so i actually thought that i get back a byte array when using GetRawTextureData() which i can use afterwards.

i'm glad for every suggestion or solution. thank you

Most helpful comment

i managed to do it with some strange(imo) method:

// Make Texture Readable
RenderTexture renderTexture = RenderTexture.GetTemporary(
texture.width,
texture.height,
0,
RenderTextureFormat.RFloat,
RenderTextureReadWrite.Linear);

Graphics.Blit(texture, renderTexture);
RenderTexture previous = RenderTexture.active;
RenderTexture.active = renderTexture;
Destroy(m_readableStencilTexture);
m_readableStencilTexture = new Texture2D(texture.width, texture.height);
m_readableStencilTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
m_readableStencilTexture.Apply();
RenderTexture.active = previous;
RenderTexture.ReleaseTemporary(renderTexture);

i was able to create human occlusion, but the depth information is too low.

and there is the next problem. when switching the Human Segmentation Depth from "Standard Resolution" in the "ArHumanBodyManager" to Half-Screen, there is no texture at all anymore.
I would prefer a higher resolution depth image. Is this possible somehow?
I think this should be a bug, because I can choose Half-Screen, but there is an empty texture then.

>All comments

i managed to do it with some strange(imo) method:

// Make Texture Readable
RenderTexture renderTexture = RenderTexture.GetTemporary(
texture.width,
texture.height,
0,
RenderTextureFormat.RFloat,
RenderTextureReadWrite.Linear);

Graphics.Blit(texture, renderTexture);
RenderTexture previous = RenderTexture.active;
RenderTexture.active = renderTexture;
Destroy(m_readableStencilTexture);
m_readableStencilTexture = new Texture2D(texture.width, texture.height);
m_readableStencilTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
m_readableStencilTexture.Apply();
RenderTexture.active = previous;
RenderTexture.ReleaseTemporary(renderTexture);

i was able to create human occlusion, but the depth information is too low.

and there is the next problem. when switching the Human Segmentation Depth from "Standard Resolution" in the "ArHumanBodyManager" to Half-Screen, there is no texture at all anymore.
I would prefer a higher resolution depth image. Is this possible somehow?
I think this should be a bug, because I can choose Half-Screen, but there is an empty texture then.

Was this page helpful?
0 / 5 - 0 ratings