为虚拟对象添加逼真的光照
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Lighting Estimation API 提供详细数据,可让您在渲染虚拟对象时模拟各种光照提示。ARCore 支持三种光照估算模式:
- 已停用
- 氛围强度模式
- 环境 HDR 模式
前提条件
在继续操作之前,请确保您了解基本 AR 概念以及如何配置 ARCore 会话。
启用光照估算
请按照以下步骤在应用中启用光照估算功能。
- 设置 AR Foundation 项目或 ARCore Extensions 项目。
- 在 Hierarchy 标签页中,前往 XR Session Origin > AR Camera。

- 在 AR Camera Manager 组件下,选择 Light Estimation。
- 在 Light Estimation 下拉菜单中,选择要使用的模式。

启用环境 HDR 模式
环境 HDR 模式可启用以下光估测设置:
当满足以下条件时,系统会自动启用此模式:
启用氛围强度模式
在 ARCameraManager
组件中选择氛围强度模式后,系统会自动启用基本光照估算。
“氛围强度”模式可启用以下光照估算设置:
获得正确的照明设置后,您可以照亮场景中的虚拟对象,使其看起来像是真实世界中的一部分。
ARCameraManager
组件可以引发 frameReceived
事件,用于在启用光照估算时估算帧的光照条件。frameReceived
事件中的信息会以 ARLightEstimationData
的形式存储在 ARCameraFrameEventArgs
结构体中。
如需在运行时更改灯具的参数,请按以下步骤操作。
- 创建或修改场景中的现有平行光。
将新脚本附加到平行光。
// Sample Lighting Estimation script
Light light;
void Awake ()
{
light = GetComponent<Light>();
}
void OnEnable()
{
if (cameraManager != null)
cameraManager.frameReceived += FrameChanged;
}
void OnDisable()
{
if (cameraManager != null)
cameraManager.frameReceived -= FrameChanged;
}
void FrameChanged(ARCameraFrameEventArgs args)
{
// Modify `light` parameters using ARCameraFrameEventArgs.
}
修改此新脚本以检测光线变化。如需查看实现方法示例,请参阅 Unity 的 BasicLightEstimation.cs
和 HDRLightEstimation.cs
脚本。
在场景中使用环境探针
请按照以下步骤在场景中启用环境探针。
- 在场景的
ARSessionOrigin
中启用自动放置。
- 将
AREnvironmentProbeManager
组件添加到 ARSessionOrigin
。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-14。
[null,null,["最后更新时间 (UTC):2025-07-14。"],[[["\u003cp\u003eThe Lighting Estimation API enables virtual objects to realistically reflect real-world lighting conditions within AR experiences.\u003c/p\u003e\n"],["\u003cp\u003eARCore offers three light estimation modes: Disabled, Ambient Intensity, and Environmental HDR, each providing varying levels of lighting detail.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can enable lighting estimation by configuring settings on the AR Camera Manager component within their Unity project.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize lighting data, developers can access light estimation information through the ARCameraManager's frameReceived event and apply it to virtual objects in the scene.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment probes can be enabled to further enhance lighting realism by capturing and applying environmental reflections to virtual objects.\u003c/p\u003e\n"]]],[],null,["# Realistically light virtual objects in a scene\n\nThe [Lighting Estimation API](/ar/develop/unity-arf/lighting-estimation/introduction) provides detailed data that lets you mimic various lighting cues when rendering virtual objects. ARCore supports three light estimation modes:\n\n1. Disabled\n2. [Ambient Intensity mode](/ar/develop/unity-arf/lighting-estimation/introduction#ambient_intensity_mode)\n3. [Environmental HDR mode](/ar/develop/unity-arf/lighting-estimation/introduction#environmental_hdr_mode)\n\nPrerequisites\n-------------\n\nMake sure that you understand [fundamental AR concepts](/ar/develop/fundamentals)\nand how to [configure an ARCore session](/ar/develop/unity-arf/session-config) before proceeding.\n\nEnable Lighting Estimation\n--------------------------\n\nFollow these steps to enable lighting estimation in your app.\n\n1. Set up an [AR Foundation project](/ar/develop/unity-arf/getting-started-ar-foundation) or [ARCore Extensions project](/ar/develop/unity-arf/getting-started-extensions).\n2. In the **Hierarchy** tab, navigate to **XR Session Origin \\\u003e AR Camera**.\n\n1. Under the **AR Camera Manager** component, select **Light Estimation**.\n2. In the **Light Estimation** drop-down menu, select the mode(s) you wish to use.\n\n### Enable Environmental HDR mode\n\n[Environmental HDR mode](/ar/develop/unity-arf/lighting-estimation/introduction#environmental_hdr_mode) enables the following light estimation settings:\n\n- [Main Light Direction](/ar/develop/lighting-estimation#main-directional-light)\n- Main Light Intensity\n- [Ambient Spherical Harmonics](/ar/develop/unity-arf/lighting-estimation/introduction#ambient_spherical_harmonics)\n\nThis mode is automatically enabled when the following criteria are met:\n\n- Ambient Spherical Harmonics, Main Light Direction, and/or Main Light Intensity are selected in the Light Estimation mode provided by the [AR Camera manager](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual/#ar-camera-manager)\n- [Environment probes](/ar/develop/unity-arf/lighting-estimation/introduction#environment_probes) are enabled in an [`AREnvironmentProbeManager`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual/environment-probe-manager.html)\n- A compatible [camera configuration](/ar/develop/unity-arf/camera-configs) is selected\n\n### Enable Ambient Intensity mode\n\nBasic light estimation is automatically enabled when [Ambient Intensity mode](/ar/develop/unity-arf/lighting-estimation/introduction#ambient_intensity_mode) is selected in the [`ARCameraManager`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual/#ar-camera-manager) component.\n\nAmbient Intensity mode enables the following light estimation settings:\n\n- Ambient Color\n- Ambient Intensity\n\nUse lighting information in your scene\n--------------------------------------\n\nOnce you have obtained the correct lighting settings, you can light the virtual objects in your scene as if they were a part of the real world.\n\nThe [`ARCameraManager`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.ARCameraManager.html) component can raise a [`frameReceived`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.ARCameraManager.html#events) event that estimates frames' lighting conditions when lighting estimation is enabled. Information from [`frameReceived`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.ARCameraManager.html#events) events are stored in [`ARCameraFrameEventArgs`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.ARCameraFrameEventArgs.html) structs as [`ARLightEstimationData`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.ARLightEstimationData.html).\n\nFollow these steps to change a light's parameters at runtime.\n\n1. Create or modify the existing Directional Light in your scene.\n2. Attach a new script to the Directional Light.\n\n // Sample Lighting Estimation script\n\n Light light;\n void Awake ()\n {\n light = GetComponent\u003cLight\u003e();\n }\n\n void OnEnable()\n {\n if (cameraManager != null)\n cameraManager.frameReceived += FrameChanged;\n }\n\n void OnDisable()\n {\n if (cameraManager != null)\n cameraManager.frameReceived -= FrameChanged;\n }\n\n void FrameChanged(ARCameraFrameEventArgs args)\n {\n // Modify `light` parameters using ARCameraFrameEventArgs.\n }\n\n3. Modify this new script to detect changes in lighting. For examples of how to do this, check out Unity's [`BasicLightEstimation.cs`](https://github.com/Unity-Technologies/arfoundation-samples/blob/main/Assets/Scripts/BasicLightEstimation.cs) and [`HDRLightEstimation.cs`](https://github.com/Unity-Technologies/arfoundation-samples/blob/main/Assets/Scripts/HDRLightEstimation.cs) scripts.\n\n### Use environment probes in your scene\n\nFollow these steps to enable [environment probes](/ar/develop/unity-arf/lighting-estimation/introduction#environment_probes) in your scene.\n\n1. Enable automatic placement in your scene's [`ARSessionOrigin`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.ARSessionOrigin.html).\n2. Add an [`AREnvironmentProbeManager`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual/environment-probe-manager.html) component to the [`ARSessionOrigin`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.ARSessionOrigin.html)."]]