Search code examples
arcore

How to adjust ARCore light estimation in front camera


Hello I have some problems and questions about ARCore materials and lighting in front - camera

When ı paint a mesh from substancfe painter and export its textures then put them on unity material and after assigning to a mesh.Model is cool but when lighting is in the game.Model goes black.Textures does not appear. How can i do ligthing in front camera any advices can you give? Thank you.


Solution

  • Apply light Estimationfor from camera for all lights on scene and rendersetting ambient light with ARFoundation

    using UnityEngine;
    using System.Collections.Generic;
    using UnityEngine.XR.ARFoundation;
    
    public class lightEstimationController: MonoBehaviour
    {
        private ARCameraManager arCameraManager;
    
        private Light[] lights;
    
        private void Awake() 
        {
            lights = GetComponentsInChildren<Light>();
            arCameraManager = this.GetComponent<ARCameraManager>();
        }
    
        private void OnEnable() 
        {
            if (arCameraManager)
            arCameraManager.frameReceived += FrameUpdated;
        }
    
        private void OnDisable() 
        {
            if (arCameraManager)
                arCameraManager.frameReceived -= FrameUpdated;
        }
    
        private void FrameUpdated(ARCameraFrameEventArgs args)
        {
            if(args.lightEstimation.averageBrightness.HasValue)
            {
                for(int i=0;i< lights.Length; i++)
                {
                    lights[i].intensity = args.lightEstimation.averageBrightness.Value;
                    
                    if (args.lightEstimation.averageColorTemperature.HasValue)
                    {
                        lights[i].colorTemperature = args.lightEstimation.averageColorTemperature.Value;
                    }
    
                    if (args.lightEstimation.colorCorrection.HasValue)
                    {
                        lights[i].color = args.lightEstimation.colorCorrection.Value;
                    }
                    
                }
    
                float factor = args.lightEstimation.averageBrightness.Value;
                Color color = new Color(SceneConfig.SceneLightColor.r * factor, SceneConfig.SceneLightColor.g * factor, SceneConfig.SceneLightColor.b * factor);
    
                RenderSettings.ambientLight = color;
    
                //   Debug.Log(  $"Color Correction: {args.lightEstimation.colorCorrection.Value}");
                //   Debug.Log($"Color Temperature: {args.lightEstimation.averageColorTemperature.Value}");
                //   Debug.Log ( $"Brightness: {args.lightEstimation.averageBrightness.Value}");
            }
    
    
    
        }
    }