Answers for "AR light estimation Unity"

C#
0

AR light estimation Unity

using UnityEngine;
using UnityEngine.XR.ARFoundation;
using TMPro;

public class Estimate_light : MonoBehaviour
{
    public ARCameraManager arcamman;
    public TMP_Text brightness;
    public float? averageBrightness { get; set; }
    Light our_light;
    // Start is called before the first frame update
    void OnEnable()
    {
        arcamman.frameReceived+=getlight;
        brightness.text="Enabled";

    }
    void OnDisable()
    {
        arcamman.frameReceived-=getlight;
        brightness.text="Disabled";

    }

    void Start()
    {
        our_light=GetComponent<Light>();
    }

    void getlight(ARCameraFrameEventArgs args)
    {
        
        if(args.lightEstimation.mainLightColor.HasValue)
        {
            //brightness.text=$"Brightness: {args.lightEstimation.mainLightColor.Value}";
            our_light.color=args.lightEstimation.mainLightColor.Value;
            float y=0.2126f*our_light.color.r+0.7152f*our_light.color.b+0.0722f*our_light.color.g;
            brightness.text=$"Brightness: {y}";
        }
        else
        {
            brightness.text="No Value";
        }

        
    }

}
Posted by: Guest on May-07-2022

C# Answers by Framework

Browse Popular Code Answers by Language