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.
| Stage | What happens | Effect on the app |
|---|---|---|
| Sensing | Stereo cameras, time-of-flight or motion parallax capture distance cues | Sets the physical accuracy ceiling |
| Estimation | Disparity or motion is converted into metric distance | Produces the raw depth values |
| Filtering | Temporal smoothing, hole filling, confidence scoring | Reduces flicker at the cost of lag |
| Reprojection | Depth is warped to the current eye or camera pose | Aligns depth with the rendered frame |
| Sampling | Shaders or CPU code read the depth texture | Enables occlusion, hit tests and physics |
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.
| Parameter | Typical range or behavior | What it affects |
|---|---|---|
| Depth resolution | Low, often a few hundred pixels per side | Sharpness of occlusion edges |
| Effective range | Most reliable at about 0.5 to 5 m | Usable distance for occlusion and hit tests |
| Update rate | Below the display refresh rate on many devices | Smoothness when hands or people move |
| Latency | Tens of milliseconds behind the pose | Visible lag at moving edges |
| Confidence | Per-pixel score from low to high | Whether a value should be trusted |
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.
Depth API compared with related XR features
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.
| Capability | Question it answers | Changes over time | Typical use |
|---|---|---|---|
| Depth API | How far is each visible pixel right now | Every frame | Occlusion of hands, people and pets |
| Scene understanding | What labeled surfaces and objects exist in the room | Rarely, after a scan | Placing content on a desk or wall |
| Plane detection | Where are flat horizontal or vertical surfaces | Gradually, as tracking improves | Anchoring a virtual board game |
| Spatial anchor | Where is this fixed point in world space | Persistent across sessions | Keeping content in the same spot |
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.
| Situation | Recommended approach | Reason |
|---|---|---|
| Hands pass in front of virtual objects | Soft occlusion with depth | Hides hard edges around fingers |
| Mobile app with tight GPU budget | Hard occlusion on key objects only | Keeps frame time stable |
| Static furniture blocks content | Scene mesh plus depth for movers | Mesh is cheaper and more stable |
| Measuring a real distance | Raw depth with confidence filtering | Avoids invented values |
| Bright sunlight or glass walls | Fallback without occlusion | Depth quality becomes unreliable |
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.