-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathUnityARAmbient.cs
36 lines (30 loc) · 1.08 KB
/
UnityARAmbient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Runtime.InteropServices;
using UnityEngine.XR.iOS;
namespace UnityEngine.XR.iOS
{
public class UnityARAmbient : MonoBehaviour
{
private Light l;
public void Start()
{
l = GetComponent<Light>();
UnityARSessionNativeInterface.ARFrameUpdatedEvent += UpdateLightEstimation;
}
void UpdateLightEstimation(UnityARCamera camera)
{
if (camera.lightData.arLightingType == LightDataType.LightEstimate) {
// Convert ARKit intensity to Unity intensity
// ARKit ambient intensity ranges 0-2000
// Unity ambient intensity ranges 0-8 (for over-bright lights)
float newai = camera.lightData.arLightEstimate.ambientIntensity;
l.intensity = newai / 1000.0f;
//Unity Light has functionality to filter the light color to correct temperature
//https://docs.unity3d.com/ScriptReference/Light-colorTemperature.html
l.colorTemperature = camera.lightData.arLightEstimate.ambientColorTemperature;
}
}
void OnDestroy() {
UnityARSessionNativeInterface.ARFrameUpdatedEvent -= UpdateLightEstimation;
}
}
}