Created
July 31, 2018 18:03
-
-
Save DanMillerDev/b7638c757d4ce22183184aef6dee9c11 to your computer and use it in GitHub Desktop.
Light Estimation for ARFoundation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Experimental.XR; | |
using UnityEngine.UI; | |
using UnityEngine.XR.ARFoundation; | |
[RequireComponent(typeof(Light))] | |
public class LightEstimation : MonoBehaviour | |
{ | |
Light m_Light; | |
/// <summary> | |
/// The light affected | |
/// </summary> | |
public Light Light | |
{ | |
get { return m_Light; } | |
set { m_Light = value; } | |
} | |
void Awake () | |
{ | |
m_Light = GetComponent<Light>(); | |
ARSubsystemManager.cameraFrameReceived += FrameChanged; | |
} | |
void FrameChanged(ARCameraFrameEventArgs args) | |
{ | |
if (args.lightEstimation.averageBrightness.HasValue) | |
{ | |
m_Light.intensity = args.lightEstimation.averageBrightness.Value; | |
} | |
if (args.lightEstimation.averageColorTemperature.HasValue) | |
{ | |
m_Light.colorTemperature = args.lightEstimation.averageColorTemperature.Value; | |
} | |
if (args.lightEstimation.colorCorrection.HasValue) | |
{ | |
m_Light.color = args.lightEstimation.colorCorrection.Value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment