Lighting Estimation developer guide for Unity

Learn how to use Lighting Estimation in your own apps.

Prerequisites

This guide is written assuming you have already installed and configured Unity with the ARCore SDK for Unity 1.10.0 or later. If not, see the Unity Quickstart for Android.

Build and run the sample app

Beginning with the ARCore SDK for Unity 1.10, the HelloAR sample for Unity has Environmental HDR With Reflections mode (EnvironmentalHDRWithReflections) enabled by default.

  1. Create a new project in Unity based on the quickstart.

  2. In Build Settings > Scenes in Build specify the scene from Assets/GoogleARCore/Examples/HelloAR/Scenes/HelloAR.unity.

  3. Make sure your device is connected to your machine and then click Build and Run. Unity builds your project into an Android APK, installs it on the device, and launches it.

    1. Find a location that has varied layers of lighting and shadow in one scene.

    2. Move the device to identify planes planes for placement. As you move your device, the app automatically detects flat surfaces and draws a diamond grid.

    3. Tap the grid to place an Android robot on the surface.

      Note the specular highlights, shadows, and ambient light that rendered on the model.

    4. Try adding new Android robots in different parts of the scene. Note how each model conforms to the lighting in a different way.

Configuring Lighting Estimation in your scene

You can configure Unity to select from two Environmental HDR modes or Ambient Intensity mode. After you set a lighting estimation mode, add the Environmental Light prefab to your scene. This prefab will automatically apply ARCore light estimation in your scene.

  • When the Light Estimation Mode is set to Environmental HDR (with or without reflections), the Environmental Light component will update the rotation and color of the directional light, ambient probe (through RenderSettings.ambientProbe), and reflection probe (through RenderSettings.customReflection).

  • When the Light Estimation Mode is set to Ambient Intensity, the Environmental Light component will set the _GlobalLightEstimation property that is used in ARCore/DiffuseWithLightEstimation and ARCore/SpecularWithLightEstimation and other custom shaders to adjust the final color output to match the camera image color.

You can also disable lighting estimation.

To configure Lighting Estimation for new or existing projects:

  1. Open an existing Unity project.

    Otherwise, create a new Unity project, then perform one of these steps:

    • Import the ARCore for Unity SDK: Select Assets > Import Package > Custom Package, then import the arcore-unity-sdk*.unitypackage with all options enabled.

    • Create a new session configuration: Select Assets > Create > Google ARCore > SessionConfig.

  2. If you're working in a new Unity project, configure ARCore prefabs:

    1. From the Project folder, drag the ARCore Device and Environmental Light prefabs into the hierarchy to add them as GameObjects.

    2. The prefabs you just imported already have a camera and directional light. Delete the default camera and the default directional light GameObjects from the root of the same hierarchy.

      Your hierarchy should now look something like this:

  3. Choose a Light Estimation mode in the session configuration:

    1. In your project hierarchy, click the ARCore Device GameObject, then double-click the session configuration.

    2. In the session configuration Inspector, click the Light Estimation Mode drop-down, and select the mode you prefer (or disable lighting estimation altogether).

      (The default for new projects is Environmental HDR With Reflections.)

  4. Choose the shader that is appropriate to the Lighting Estimation mode:

    • If you want to use Environmental HDR mode, you can simply use Unity built-in Mobile shaders or Standard Shaders.

    • If you want to use Ambient Intensity mode, you will need to use a custom shader that apply the _GlobalLightEstimation term in the final color output to render your virtual object. See ARCore/DiffuseWithLightEstimation and ARCore/SpecularWithLightEstimation shaders for reference.

Adjust shadow quality

When using the ARCore/TransparentShadow shader that's included in the ARCore SDK for Unity, we recommend starting with the following Quality Settings:

Property Setting
Shadows Hard and Soft Shadows
Shadow Resolution High Resolution
Shadow Projection Close Fit
Shadow Distance 20
Shadowmask Mode Distance Shadowmask
Shadow Near Plane Offset 0
Shadow Cascades No Cascades