arfoundation-samples icon indicating copy to clipboard operation
arfoundation-samples copied to clipboard

How to align depth map of Unity 3d object and depth map from ARKit

Open smalleight17 opened this issue 7 years ago • 4 comments

I can get the human occlusion working in fragment shader, but I realize the depth map of my 3d virtual object and the depth map returned by ARKit is not really aligned. As the depth is a bit off now my body occlusion it's working only kind of realistic. Any idea on converting them to a same distribution?

smalleight17 avatar Aug 16 '19 18:08 smalleight17

We're working on a better sample for this.

tdmowrer avatar Oct 08 '19 20:10 tdmowrer

Ah! I had my own working version for this. As ARKit depth map pixel value stands for meters from camera, I translate the unity depth map into a linear 0-1 scale and multiply by camera's far clipping plane (my near clipping plane is .01)

            float human_depth = tex2D(_HumanDepth, some_uv).r;
            float unity_depth = tex2D(_CameraDepthTexture, some_uv).r;
            unity_depth = Linear01Depth(unity_depth) * my_step(0., unity_depth);
            unity_depth *= _ProjectionParams.z;
        
            float my_step(float a, float x){
                return x > a;
            }

This puts unity depth and arkit depth into same scale. I think. Let me know if this is right!

smalleight17 avatar Oct 09 '19 23:10 smalleight17

@smalleight17 ,

I have been working on the new occlusion functionality in ARFoundation.

The depth functionality in the shader includes are not accurate in the ARKit / Metal cases.

The new occlusion functionality with include calculations that will work better in the ARKit / Metal samples.

Todd

todds-unity avatar Oct 10 '19 17:10 todds-unity

This functionality is now available in the AROcclusionManager. The SimpleAR sample uses it.

tdmowrer avatar May 11 '20 22:05 tdmowrer