How to align depth map of Unity 3d object and depth map from ARKit
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?
We're working on a better sample for this.
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 ,
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
This functionality is now available in the AROcclusionManager. The SimpleAR sample uses it.