Table of Contents

Using EasyAR Mega to achieve occlusion in Unity

Occlusion is a key technology to enhance the immersive experience of AR virtual-real fusion. This article will introduce how to achieve the occlusion effect in Unity through EasyAR Mega.

Before you begin

Implementation of occlusion

  • Offline modeling: In the Block coordinate system, create 1:1 matching geometric bodies for real-world entities (such as walls, columns, and large equipment); or obtain optimized models by cropping and reducing the faces of the Block dense model.

  • Runtime alignment: During runtime, align the Block coordinate system with the real-world space through cloud localization and load the corresponding geometric bodies.

  • Material replacement: Assign special occlusion materials to these geometric bodies.

  • Visual effect: When the GPU renders other virtual objects, pixels of the occluded parts are automatically culled due to failed depth testing, making the virtual objects follow the occlusion logic of real physical space.

How to use geometry as occlusion

Follow these steps to add geometry as occlusion in the scene and verify the effect.

Place occlusion geometry

According to the dense model of Mega Block, use built-in geometry or self-built geometry as occlusion and place it in the correct position in the Block coordinate system. Place occlusion geometry

[Optional] Fine-tune the geometry position based on the panorama

Fine-tune occlusion based on the panorama

Assign occlusion material to geometry

Modify the geometry material to occlusion material, you can use Unity's built-in SpatialMappingOcculusion. Fine-tune occlusion based on panorama

Simulate running with EIF data or run on the actual device

You can fine-tune the placement of the occlusion model based on the running effect.

How to use the cropped and decimated dense model as occlusion

Follow the steps below to crop and decimate the exported Mega Block dense model to obtain a simplified white model for occlusion, and import it into the scene as occlusion.

Export in Mega Blocks

Select export in the Mega Blocks tool in the Inspector panel

Select export

Modify export options

Pay attention to modify the export options when exporting.

Export options

In the figure, 1 is the LOD level. The lower the level, the simpler the model and the fewer the polygons. If the highest precision is required, choose 2. If you can accept reduced precision to decrease the polygon count, choose 1 or 0.

In the figure, 2 is the texture export option. Since we only need a white model for occlusion, textures are not required.

Crop and reduce the model

Crop and reduce the exported model in digital content creation software (e.g., Blender), then save it as Glb.

Tip

The example uses Blender's Decimate Modifier.

Before cropping

After cropping and reducing:

After cropping

Import the occlusion model into Unity and mount it under the Block node in the scene

Import the occlusion model

Modify the transform of the model

Modify the Transform of the model so that both Position and Rotation are set to 0.

At this point, the white model used for occlusion should fit closely with the dense model. This is because, during the clipping and decimation operations in the digital content creation software, the definition of the Block coordinate system was not altered.

Occlusion model fitting

Give the model occlusion material

Modify the model material to occlusion material, you can use Unity's built-in SpatialMappingOcculusion.

Occlusion model change material

Simulate or run on the actual device using EIF data

Simulate or run on the actual device using EIF data to view the effect.

The effect expectation of occlusion

The effect of occlusion is mainly influenced by the following points:

  • The accuracy of positioning and tracking itself
  • The accuracy of model placement
  • The precision of the model itself (if it is not a simple geometric shape)

A misalignment of several centimeters during positioning drift is normal.

Occlusion models with too many polygons can easily affect performance. It is recommended to use them only in necessary areas and to use simple geometric shapes for occlusion as much as possible.