Skip to content

How AR Occlusion Works: Hiding Virtual Objects

By AR Compare Team ·

Occlusion in AR means real objects can hide virtual ones, the way a real table hides the legs of a real chair behind it. To do it, the device builds a depth map, a picture of the scene where every pixel holds a distance instead of a colour. When it draws a virtual object, it compares the object’s distance with the depth map pixel by pixel and skips any part that sits behind something real. Without occlusion, a virtual object always appears pasted on top of everything, which breaks the illusion that it is in the room.

This explainer draws on Google’s ARCore depth guide, the DepthLab paper by Ruofei Du and colleagues at Google, presented at the UIST 2020 conference, and Magic Leap’s dimmer design guidelines. If you build AR apps, see AR glasses for developers.

Why occlusion matters

Google’s guide gives a simple example: a virtual figure placed next to a real trunk. Drawn without occlusion, the figure overlaps the edge of the trunk even though the trunk is closer to you. Your brain reads that as wrong straight away. With occlusion, the trunk hides part of the figure and it looks like it belongs there. Google calls occlusion paramount to an immersive AR experience.

Step 1: build a depth map

A depth map can come from 2 places.

From camera motion. Google’s Depth API uses what it calls depth from motion. As you move the device, it takes images from slightly different angles and compares them to estimate the distance to every pixel. Google says it also uses machine learning so it can work with only small movements.

From a depth sensor. Some devices have a time-of-flight sensor, which measures distance directly with light. Google says ARCore merges this automatically when present. That gives depth even when the camera is still, and better depth on featureless surfaces such as white walls, and in scenes with people or things moving.

Google gives the useful range: estimates from 0 to 65 meters, but most accurate from about half a meter to 5 meters. Depth only becomes available after the user has started moving the device.

Step 2: compare depth when drawing

Renderers already work out which virtual object is in front by comparing distances. AR occlusion adds the real world to that comparison. For every pixel of a virtual object, the renderer asks: is the real surface at this pixel closer than the virtual object? If yes, it shows the real world there instead.

The DepthLab paper sorts uses of depth into 3 levels:

  • Point depth: the distance at 1 spot, used for placing or measuring.
  • Surface depth: the shape of a patch of surface, used for collisions and for placing objects on uneven ground.
  • Per-pixel depth: the full map, needed for occlusion, shadows and relighting.

Du and colleagues built DepthLab as an open-source library so app developers could add these features without writing the depth processing themselves. They report it passed 100,000 downloads.

Where it goes wrong

Occlusion is only as good as the depth map.

  • Blank surfaces. Google notes surfaces with few or no features, such as white walls, give imprecise depth from motion alone.
  • Distance. Accuracy drops outside the half a meter to 5 meter sweet spot.
  • Moving things. Depth from motion works by comparing views over time. Google says a depth sensor gives better depth in scenes with moving people or objects.
  • Standing still. Valid depth arrives only after the device has started moving, unless it has a depth sensor.

Two kinds of occlusion on glasses

On a phone or a passthrough headset, the device shows you a camera image, so hiding the virtual object behind a real one is just a matter of not drawing those pixels. The real world is already in the picture.

Optical see-through glasses, where you look through clear lenses, split the problem in 2:

  • Real hides virtual. Easy. The glasses just do not draw the hidden part of the virtual object, and you see the real object through the lens.
  • Virtual hides real. Hard. The display can only add light. Magic Leap’s docs describe its displays as additive, so a virtual object cannot block the real world behind it. A dark virtual object looks see-through.

Magic Leap 2 tackles the second case with segmented dimming, an extra panel that darkens the real world only behind virtual content, which Magic Leap says lets it show black and more solid images. Its guidelines admit the panel is low resolution and out of focus, so it leaves a soft dark halo. For the full story on optical approaches, read the deep dive on occlusion in optical see-through AR.

What it means for you

Occlusion matters when virtual objects share space with real ones: games on a table, furniture apps, or windows pinned behind a real monitor. It does not matter for display glasses that float a screen in front of you. If occlusion matters to you, look for a headset or glasses with cameras, depth sensing and 6DoF tracking; see how spatial anchors work and AR headsets for work.

For the term itself, see the occlusion glossary entry.

More buying guides: XR glasses.

Frequently asked questions

What is occlusion in AR?

It is drawing a virtual object so that real things in front of it hide part of it, the way a real chair would be hidden behind a real table. Without it, virtual objects look pasted on top of everything.

How does an AR device know what is in front?

It builds a depth map, a picture where each pixel holds a distance. Comparing that distance with the virtual object's distance tells the renderer which pixels to hide.

Do you need a depth sensor for occlusion?

No. Google's ARCore estimates depth from ordinary camera images as you move the device. A time-of-flight depth sensor helps: Google says it gives depth without moving and works better on blank walls and moving people.

Why does occlusion sometimes look wrong?

The depth map is less accurate on blank surfaces, at long range and with moving things. Google says ARCore's depth is most accurate from about half a meter to 5 meters away.

Is occlusion harder on see-through AR glasses?

Yes. See-through glasses can hide part of a virtual object easily, but they cannot block real light to make a virtual object hide the real world behind it without a dimming layer.