- Home /
How do i get the correct light estimation in AR Foundation?
Hello, i'm working on a AR application and i try to implement the light estimation feature, nevertheless, a few months ago the information given by the ARCameraFrameEventArgs variable became a little weird:
lightEstimation: ( Avg. Brightness: 0.5368686, Avg. Color Temperature: , Color Correction: RGBA(1.013, 1.000, 0.953, 0.537), Avg. Intensity in Lumens: 1073.737)
Even if I focus my camera directly to the sun the "Avg. Brightness" value is never greater than 0.6, and the Color Correction values are too high for a RGBA form 0 to 1 and too low for a RGBA from 0 to 255.
i'm very confused since my app was working fine a few months ago, but now even the sample scene gives me this outputs in android and iOS.
this is the code i'm using (based on the AR foundation examples)
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class LigthEstimation : MonoBehaviour {
[SerializeField] private ARCameraManager arCameraManager;
private Light mainLight;
public float? Brightness { get; private set; }
public float? ColorTemperature { get; private set; }
public Color? ColorCorrection { get; private set; }
private void Awake () {
mainLight = GetComponent<Light> ();
}
private void OnEnable () {
arCameraManager.frameReceived += FrameUpdated;
}
private void OnDisable () {
arCameraManager.frameReceived -= FrameUpdated;
}
private void FrameUpdated (ARCameraFrameEventArgs args) {
if (args.lightEstimation.averageBrightness.HasValue) {
Brightness = args.lightEstimation.averageBrightness.Value;
Debug.Log (">>>>" + Brightness.Value);
mainLight.intensity = Brightness.Value;
}
if (args.lightEstimation.averageColorTemperature.HasValue) {
ColorTemperature = args.lightEstimation.averageColorTemperature.Value;
Debug.Log (">>>>" + ColorTemperature.Value);
mainLight.colorTemperature = ColorTemperature.Value;
}
if (args.lightEstimation.colorCorrection.HasValue) {
ColorCorrection = args.lightEstimation.colorCorrection.Value;
Debug.Log (">>>>" + ColorCorrection.Value);
mainLight.color = ColorCorrection.Value;
}
}
}
am i doing something wrong?
i'm using ARFoundation 2.2.2 (From Package Manager) in unity 2019.1.14f1 i'll appreciate any information
Answer by Jasr_88 · Feb 27, 2020 at 11:27 PM
Well turns out that they modified this feature to include some others values like Light Direction and sphericalHarmonics now in ARFoundation Version 3.1.0 (preview4) the LightEstimation object have the following properties:
LightEstimation.brightness
LightEstimation.colorTemperature
LightEstimation.colorCorrection
LightEstimation.mainLightDirection
LightEstimation.mainLightColor
LightEstimation.mainLightIntensityLumens
LightEstimation.sphericalHarmonics
As you can see, this is much more infromation than the given in the former versión (2.2.0 for example):
Avg. Brightness
Avg. Color Temperature
Color Correction
Avg. IntensityInLumens
So if you where using a script similar to the showed in this tutorial:
now instead of use colorTemperature or colorCorrection values for your main ligth, we need to use LightEstimation.mainLightColor and LightEstimation.mainLightDirection to achieve the desired effect
The problem is not thecnical or a bug is just the lack of documentation
Now days the example on https://github.com/Unity-Technologies/arfoundation-samples is working with this features, so now we have to hope that the code remains working the same way, or if its modified, wait 3 monts for a working example on the official repo.
Your answer
Follow this Question
Related Questions
LightEstimation Values in AR Foundation 0 Answers
Cloud recognition in Vuforia 0 Answers
Directional light - Help 0 Answers
Need help with Flashlight Script 1 Answer