Depth API

On this page 7

A Depth API is a platform interface that gives an application a per-pixel estimate of distance between the device and the real surfaces it sees, usually delivered as a depth map or depth texture refreshed many times per second. In XR development, it is the building block that lets virtual objects hide behind real furniture, collide with walls and land convincingly on uneven surfaces, which places it at the center of modern mixed reality and augmented reality work in extended reality.

The two best-known implementations are the Depth API on Meta Quest headsets, exposed through Meta SDKs and the OpenXR extension for environment depth, and the ARCore Depth API on supported Android phones. Both answer the same question, how far away is each pixel, but they differ in sensors, latency and accuracy.

How a Depth API produces a depth map

A Depth API converts raw sensor data into a dense distance image that the application samples like any other texture. On a headset, the system typically compares images from two outward-facing cameras (stereo matching) or reads an active depth sensor, then reprojects the result into the viewpoint of each eye. On a phone with a single camera, ARCore estimates depth from motion parallax as the user moves the device, and refines it with a time-of-flight sensor when one is present.

The output is rarely used raw. The runtime applies temporal filtering, fills holes and attaches a confidence value to each pixel, because reflective, transparent and textureless surfaces produce unreliable matches. Applications then compare the real depth with the depth of each rendered fragment in a shader: when the real surface is closer, the virtual pixel is discarded or faded, which creates dynamic occlusion.

The following table summarizes the main stages of the depth pipeline and what each contributes.

StageWhat happensEffect on the app
SensingStereo cameras, time-of-flight or motion parallax capture distance cuesSets the physical accuracy ceiling
EstimationDisparity or motion is converted into metric distanceProduces the raw depth values
FilteringTemporal smoothing, hole filling, confidence scoringReduces flicker at the cost of lag
ReprojectionDepth is warped to the current eye or camera poseAligns depth with the rendered frame
SamplingShaders or CPU code read the depth textureEnables occlusion, hit tests and physics
Stages of a typical depth pipeline

Key parameters of depth data

Depth quality is described by a small set of parameters that matter more than marketing claims. Resolution of the depth map is far lower than the color camera, often a few hundred pixels per side, so edges are approximate. Accuracy degrades with distance: stereo error grows roughly with the square of range, which is why most systems are most reliable between about 0.5 and 5 meters.

The table below lists the parameters developers should check before designing an interaction around depth.

ParameterTypical range or behaviorWhat it affects
Depth resolutionLow, often a few hundred pixels per sideSharpness of occlusion edges
Effective rangeMost reliable at about 0.5 to 5 mUsable distance for occlusion and hit tests
Update rateBelow the display refresh rate on many devicesSmoothness when hands or people move
LatencyTens of milliseconds behind the poseVisible lag at moving edges
ConfidencePer-pixel score from low to highWhether a value should be trusted
Parameters that shape depth quality

Developers usually choose between raw depth, which is sparse but honest about uncertainty, and smoothed depth, which is complete but may invent plausible values in hard regions. Raw depth suits measurement and reconstruction, while smoothed depth suits visual occlusion.

A Depth API is a frame-by-frame perception service, not a model of the room. It complements scene understanding, plane detection and spatial anchors, each of which answers a different question about the environment. Confusing them leads to apps that either ignore moving objects or waste processing on static geometry.

CapabilityQuestion it answersChanges over timeTypical use
Depth APIHow far is each visible pixel right nowEvery frameOcclusion of hands, people and pets
Scene understandingWhat labeled surfaces and objects exist in the roomRarely, after a scanPlacing content on a desk or wall
Plane detectionWhere are flat horizontal or vertical surfacesGradually, as tracking improvesAnchoring a virtual board game
Spatial anchorWhere is this fixed point in world spacePersistent across sessionsKeeping content in the same spot
How depth relates to neighboring capabilities

In practice, strong mixed reality apps combine static scene data with live depth: the room mesh handles walls and furniture efficiently, and the depth map catches everything that moves. Engine layers such as AR Foundation and the Meta XR All-in-One SDK expose depth alongside these features so that one shader can use both.

Implementing occlusion and interaction

The most common use of a Depth API is occlusion in the fragment shader. The shader reads the environment depth, converts both values into the same space and compares them. A hard occlusion mode discards pixels with a binary test and is cheap, while soft occlusion blends across a small depth band to hide jagged edges, at a higher GPU cost.

Depth also supports hit testing against arbitrary surfaces, simple physics such as particles bouncing off a sofa, and placement on geometry that plane detection misses. The decision table below helps choose a technique.

SituationRecommended approachReason
Hands pass in front of virtual objectsSoft occlusion with depthHides hard edges around fingers
Mobile app with tight GPU budgetHard occlusion on key objects onlyKeeps frame time stable
Static furniture blocks contentScene mesh plus depth for moversMesh is cheaper and more stable
Measuring a real distanceRaw depth with confidence filteringAvoids invented values
Bright sunlight or glass wallsFallback without occlusionDepth quality becomes unreliable
Choosing how to use depth data

Access to depth normally requires explicit user permission for spatial data, because depth maps reveal the shape of a private space. A well-designed app requests it in context and keeps working with reduced realism when the user declines.

Limitations and common mistakes

Depth estimation has physical limits that no SDK can remove. Low-texture surfaces, mirrors, glass and dark materials confuse stereo matching, and strong sunlight can overwhelm active sensors. Thin objects such as cables and chair legs often disappear because they are smaller than a depth pixel.

  • Assuming pixel-perfect edges: depth maps are coarse, so occlusion halos around hands are normal and must be softened.
  • Ignoring latency: comparing current rendering with older depth causes visible lag at moving edges unless the runtime reprojects it.
  • Running occlusion on everything: full-screen soft occlusion can consume a significant share of the GPU budget on standalone headsets.
  • Skipping confidence checks: low-confidence pixels produce flickering artifacts when used for physics or measurement.
  • Forgetting privacy: depth data describes a personal environment and should not be uploaded without clear consent.

Explained without jargon

A Depth API tells an app how far away everything in the room is. Think of it as a gray picture where near things are light and far things are dark, updated many times every second.

With that picture, the headset or phone knows when your hand, a chair or a person stands in front of a virtual object. It can then hide the right parts of the digital content, so the illusion holds. The picture is a little blurry and works best within a few meters, which is why the edges around fingers sometimes look soft.

A typical use case

A small studio builds a mixed reality tabletop strategy game for a standalone headset. Players sit around a real coffee table, and miniature virtual armies march across it. In early tests, players reaching toward the board saw their hands disappear behind the virtual troops, which broke immersion and made pointing at units confusing.

The team enables the platform Depth API and adds soft occlusion only to the game board shaders, leaving distant scenery untouched to protect the frame budget. They keep the scanned room mesh for the table and walls, and use live depth only for hands and people walking past.

The result is that fingers now appear in front of the miniatures with slightly soft edges, while frame rate stays at the target refresh rate. Testers report that selecting units feels natural, and the studio adds a fallback mode without occlusion for rooms with large windows, where depth quality drops in bright daylight.