Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Issues Reading Depth Value from environmentDepthTexture

Discussion in 'AR' started by j0schm03, Aug 24, 2020.

  1. j0schm03

    j0schm03

    Joined:
    Jun 21, 2018
    Posts:
    16
    I've got a couple of issues I'm hoping someone can help me with.

    1) environmentDepthTexture Orientation: In a portrait app, the environmentDepthTexture is rotated 90 degrees. Is there a way to automatically adjust this to portrait?

    2) environmentDepthTexture Depth Values: It's my understanding that the values returned by the environmentDepthTexture are in meters, the distance from the camera to the real-world object represented by the pixel in the environmentDepthTexture. According to this comment:
    We are noticing that when using getPixel on the environmentDepthTexture, the values returned for the Color.r value are only returning between 0 and 1. Is this the correct behavior? With the distance supposedly in meters we anticipated values over 1 meter. Or are the Color.r values returned by the environmentDepthTexture actually not the distance in meters as was stated and we then have to calculate the distance based on the clipping planes etc?

    For example, doing the following never gives us a value over 1. We always end up with something between 0 and 1.

    Code (CSharp):
    1. Color depthValue = m_OcclusionManager.environmentDepthTexture.GetPixel((int)touchPos.x,(int)touchPos.y);
    2. Debug.Log(depthValue.r)