Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

Light Estimation values are not showing #675

Closed dragonho96 closed 3 years ago

dragonho96 commented 3 years ago
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;

public class LE : MonoBehaviour
{
    [SerializeField]
    [Tooltip("The ARCameraManager which will produce frame events containing light estimation information.")]
    ARCameraManager aRCameraManager;

    public Text brightnessValue;
    public Text tempValue;
    public Text colorCorrectionValue;

    private Light currentLight;

    private void Awake()
    {
        currentLight = GetComponent<Light>();
    }

    private void OnEnable()
    {
        aRCameraManager.frameReceived += FrameUpdated;

    }
    private void OnDisble()
    {
        aRCameraManager.frameReceived -= FrameUpdated;
    }

    void FrameUpdated(ARCameraFrameEventArgs args)
    {
        if (args.lightEstimation.averageMainLightBrightness.HasValue)
        {
            brightnessValue.text = $"Brightness: {args.lightEstimation.averageBrightness.Value}";
            currentLight.intensity = args.lightEstimation.averageBrightness.Value;
        }
        else
        {
            brightnessValue.text = "Nothing";
        }
        if (args.lightEstimation.averageColorTemperature.HasValue)
        {
            tempValue.text = $"averageColorTemperature: {args.lightEstimation.averageColorTemperature.Value}";
            currentLight.colorTemperature = args.lightEstimation.averageColorTemperature.Value;
        }
        else
        {
            tempValue.text = "nothing";
        }
        if (args.lightEstimation.mainLightColor.HasValue)
        {
            colorCorrectionValue.text = $"colorCorrection: {args.lightEstimation.colorCorrection.Value}";
            currentLight.color = args.lightEstimation.colorCorrection.Value;
        }
        else
        {
            colorCorrectionValue.text = "nothing";
        }
    }
}

This is my code which is attached to the main light. And I set the light estimation mode to ambient intensity. But from the debug text, I am not getting any values. Is there any solution to solve this problem?

Thanks!

Unity version : 2019.4.6 ARFoundation: 4.0.8 ARCore: 4.0.8

tdmowrer commented 3 years ago

averageMainLightBrightness and mainLightColor require HDR lighting on Android, which is only enabled in certain cases. What light estimation features have you enabled in your ARCameraManager? You might try averageBrightness instead.

Color temperature only has meaning on iOS. On Android, you want colorCorrection.

In development builds, there is debug output that will tell you which features were requested (including lighting features) and which it chose (because not all are simultaneously compatible). You can use logcat to see what configuration ARFoundation chooses:

adb logcat -s Unity

Also, it might be helpful to have a look at the samples for these features: https://github.com/Unity-Technologies/arfoundation-samples#lightestimation

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

noble-man commented 1 year ago

I'm getting values for mainLightDirection, mainLightColor and ambientSphericalHarmonics, but I'm not getting anything for mainLightIntensityLumens or averageMainLightBrightness.

I tried building the app on another phone, but got the same results. The debug tool (logcat) says Main Light Intensity is supported on the device. But, I'm not getting its value.