Handling Plane Detection and Occlusion in AR Games

This article outlines how augmented reality (AR) game developers use computer vision, hardware sensors, and specialized rendering techniques to anchor digital content to physical spaces. It covers the mechanics of plane detection, the generation of real-time environmental meshes, and the use of depth buffers and occlusion shaders to realistically conceal virtual objects behind real-world obstacles.

Plane Detection: Anchoring Virtual Assets

Plane detection is the process by which an AR system identifies flat, continuous physical surfaces such as floors, tables, and walls. Developers rely on software development kits (SDKs) like Apple’s ARKit, Google’s ARCore, or cross-platform layers like Unity’s AR Foundation to handle the heavy computational load.

  1. Feature Point Tracking: The device’s camera tracks high-contrast visual points across sequential video frames. By pairing this visual data with motion readings from the device’s Inertial Measurement Unit (IMU)—a process known as Visual-Inertial Odometry (VIO)—the system estimates its position in 3D space.
  2. Plane Fitting: The AR engine identifies clusters of coplanar feature points. When enough points align along a shared geometric plane, the system classifies the area as a candidate surface (horizontal or vertical).
  3. Dynamic Boundary Expansion: As the player moves the camera, the system discovers additional feature points, automatically merging overlapping surfaces and refining the polygon boundaries of detected planes in real time.

In game development, these detected planes act as spawn areas, navigation meshes (NavMesh) for AI agents, and collision boundaries for physics simulations.

Surface Mesh Occlusion: Hiding Digital Behind Physical

Without occlusion, virtual objects render on top of real-world objects regardless of depth, breaking visual immersion. Occlusion ensures that if a real person, chair, or wall stands between the player and a virtual character, the character is partially or fully hidden.

Depth Acquisition

Developers obtain real-world depth data through two primary methods:

  • Hardware Sensors: Modern devices equipped with Time-of-Flight (ToF) or LiDAR sensors emit light pulses to measure the exact distance to physical surfaces on a per-pixel basis. This yields instantaneous, highly accurate depth maps regardless of visual texture.
  • Algorithmic Estimation: Devices with standard cameras use machine learning models and optical flow algorithms to estimate depth from color data (RGB depth), inferring distance by how objects shift as the camera moves.

The Occlusion Material and Depth Buffer Technique

To make a real object block a virtual one, developers do not need to render the physical object’s appearance; they only need its depth.

  1. Mesh Reconstruction: The AR runtime turns raw depth data into a continuous 3D polygon mesh that matches the contours of the real world.
  2. Depth-Mask Shaders: Developers apply a specialized occlusion shader to this environmental mesh.
  3. Z-Buffer Manipulation: The occlusion shader writes directly to the rendering engine’s depth buffer (Z-buffer) while disabling writes to the color buffer (setting the color output to completely transparent).
  4. Rendering Order: When virtual game objects are drawn, the graphics pipeline checks the Z-buffer. If a virtual pixel's depth is greater than the value recorded by the invisible occlusion mesh, the pipeline discards the virtual pixel.

Best Practices for Developers

  • Implement Semantic Segmentation: High-end AR frameworks classify detected geometry (e.g., humans, floors, ceilings). Prioritize occluding dynamic elements like people over static background geometry to maintain high frame rates.
  • Smooth Mesh Updates: Constantly recalculating high-poly meshes drains the device's battery. Developers frequently smooth mesh updates by using lower-poly colliders for physics while reserving higher-density geometry for rendering occlusion.
  • Provide User Guidance: Plane detection relies on adequate lighting and surface texture. Developers build visual cues—such as reticles or coaching overlays—that instruct players to pan their cameras across textured surfaces if detection stalls.