Skip to content

Instantly share code, notes, and snippets.

@DanMillerDev
Created July 31, 2018 18:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanMillerDev/b7638c757d4ce22183184aef6dee9c11 to your computer and use it in GitHub Desktop.
Save DanMillerDev/b7638c757d4ce22183184aef6dee9c11 to your computer and use it in GitHub Desktop.
Light Estimation for ARFoundation
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