浏览代码

- Added new ARKit HDR light estimation sample scene

- Modified LightEstimation scene to display HDR estimation information.
/3.1
David Mohrhardt 5 年前
当前提交
5e5dd2a2
共有 10 个文件被更改,包括 2151 次插入1002 次删除
  1. 58
      Assets/Scripts/LightEstimation.cs
  2. 75
      Assets/Scripts/LightEstimationUI.cs
  3. 2
      ProjectSettings/EditorBuildSettings.asset
  4. 8
      Assets/Scenes/LightEstimation.meta
  5. 1001
      Assets/Scenes/LightEstimation/ARKitHDRLightEstimation.unity
  6. 7
      Assets/Scenes/LightEstimation/ARKitHDRLightEstimation.unity.meta
  7. 1001
      Assets/Scenes/LightEstimation/LightEstimation.unity
  8. 1001
      Assets/Scenes/LightEstimation.unity
  9. 0
      /Assets/Scenes/LightEstimation/LightEstimation.unity.meta

58
Assets/Scripts/LightEstimation.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.XR.ARFoundation;
/// <summary>

/// </summary>
public Color? colorCorrection { get; private set; }
/// <summary>
/// The estimated direction of the main light of the physical environment, if available.
/// </summary>
public Vector3? mainLightDirection { get; private set; }
/// <summary>
/// The estimated color of the main light of the physical environment, if available.
/// </summary>
public Color? mainLightColor { get; private set; }
/// <summary>
/// The estimated intensity in lumens of main light of the physical environment, if available.
/// </summary>
public float? mainLightIntensityLumens { get; private set; }
/// <summary>
/// The estimated spherical harmonics coefficients of the physical environment, if available.
/// </summary>
public SphericalHarmonicsL2? sphericalHarmonics { get; private set; }
void Awake ()
{
m_Light = GetComponent<Light>();

{
colorCorrection = args.lightEstimation.colorCorrection.Value;
m_Light.color = colorCorrection.Value;
}
if (args.lightEstimation.mainLightDirection.HasValue)
{
mainLightDirection = args.lightEstimation.mainLightDirection;
m_Light.transform.rotation = Quaternion.LookRotation(mainLightDirection.Value);
}
if (args.lightEstimation.mainLightColor.HasValue)
{
mainLightColor = args.lightEstimation.mainLightColor;
#if PLATFORM_ANDROID
// ARCore needs to apply energy conservation term (1 / PI) and be placed in gamma
m_Light.color = mainLightColor.Value / Mathf.PI;
m_Light.color = m_Light.color.gamma;
// ARCore returns color in HDR format (can be represented as FP16 and have values above 1.0)
var camera = m_CameraManager.GetComponentInParent<Camera>();
if (camera == null || !camera.allowHDR)
{
Debug.LogWarning($"HDR Rendering is not allowed. Color values returned could be above the maximum representable value.");
}
#endif
}
if (args.lightEstimation.mainLightIntensityLumens.HasValue)
{
mainLightIntensityLumens = args.lightEstimation.mainLightIntensityLumens;
m_Light.intensity = args.lightEstimation.averageMainLightBrightness.Value;
}
if (args.lightEstimation.ambientSphericalHarmonics.HasValue)
{
sphericalHarmonics = args.lightEstimation.ambientSphericalHarmonics;
RenderSettings.ambientMode = AmbientMode.Skybox;
RenderSettings.ambientProbe = sphericalHarmonics.Value;
}
}

75
Assets/Scripts/LightEstimationUI.cs


using UnityEngine;
using UnityEngine.UI;
using SphericalHarmonicsL2 = UnityEngine.Rendering.SphericalHarmonicsL2;
/// <summary>
/// A simple UI controller to display light estimation information.
/// </summary>

[Tooltip("The UI Text element used to display the estimated color correction value for the physical environment.")]
[SerializeField]
Text m_ColorCorrectionText;
[Tooltip("The UI Text element used to display the estimated direction of the main light for the physical environment.")]
[SerializeField]
Text m_MainLightDirectionText;
public Text mainLightDirectionText
{
get => m_MainLightDirectionText;
set => m_MainLightDirectionText = value;
}
[Tooltip("The UI Text element used to display the estimated intensity in lumens of the main light for the physical environment.")]
[SerializeField]
Text m_MainLightIntensityLumens;
public Text mainLightIntensityLumens
{
get => m_MainLightIntensityLumens;
set => m_MainLightIntensityLumens = value;
}
[Tooltip("The UI Text element used to display the estimated color of the main light for the physical environment.")]
[SerializeField]
Text m_MainLightColor;
public Text mainLightColorText
{
get => m_MainLightColor;
set => m_MainLightColor = value;
}
[Tooltip("The UI Text element used to display the estimated spherical harmonics coefficients for the physical environment.")]
[SerializeField]
Text m_SphericalHarmonicsText;
public Text ambientSphericalHarmonicsText
{
get => m_SphericalHarmonicsText;
set => m_SphericalHarmonicsText = value;
}
/// <summary>
/// The UI Text element used to display the estimated color correction value for the scene.

SetUIValue(m_LightEstimation.brightness, brightnessText);
SetUIValue(m_LightEstimation.colorTemperature, colorTemperatureText);
SetUIValue(m_LightEstimation.colorCorrection, colorCorrectionText);
SetUIValue(m_LightEstimation.mainLightDirection, mainLightDirectionText);
SetUIValue(m_LightEstimation.mainLightColor, mainLightColorText);
SetUIValue(m_LightEstimation.mainLightIntensityLumens, mainLightIntensityLumens);
SetSphericalHarmonicsUIValue(m_LightEstimation.sphericalHarmonics, ambientSphericalHarmonicsText);
}
void SetSphericalHarmonicsUIValue(SphericalHarmonicsL2? maybeAmbientSphericalHarmonics, Text text)
{
if (text != null)
{
if (maybeAmbientSphericalHarmonics.HasValue)
{
string sphericalHarmonicsCoefficientsStr = "";
if (m_LightEstimation.sphericalHarmonics.HasValue)
{
for (int i = 0; i < 3; ++i)
{
if (i == 0)
sphericalHarmonicsCoefficientsStr += $"R: [";
else if (i == 1)
sphericalHarmonicsCoefficientsStr += $"G: [";
else
sphericalHarmonicsCoefficientsStr += $"B: [";
for (int j = 0; j < 9; ++j)
{
sphericalHarmonicsCoefficientsStr += $"{m_LightEstimation.sphericalHarmonics.Value[i,j].ToString("0.000")}{(j != 8 ? ", " : "]\n")}";
}
}
}
text.text = sphericalHarmonicsCoefficientsStr;
}
else
{
text.text = k_UnavailableText;
}
}
}
void SetUIValue<T>(T? displayValue, Text text) where T : struct

2
ProjectSettings/EditorBuildSettings.asset


path: Assets/Scenes/ImageTracking/ImageTracking.unity
guid: e0b018a3c3b5cfd4c8e316706ec0a18c
- enabled: 0
path: Assets/Scenes/LightEstimation.unity
path: Assets/Scenes/LightEstimation/LightEstimation.unity
guid: 2f0cbc82480584c258f99f0d9e4ba302
- enabled: 0
path: Assets/Scenes/Object Tracking/ObjectTracking.unity

8
Assets/Scenes/LightEstimation.meta


fileFormatVersion: 2
guid: 5bf9acd886dd646afbb73df643cc7aea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Scenes/LightEstimation/ARKitHDRLightEstimation.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Scenes/LightEstimation/ARKitHDRLightEstimation.unity.meta


fileFormatVersion: 2
guid: f7322e09f4047458fbc45af303830f01
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Scenes/LightEstimation/LightEstimation.unity
文件差异内容过多而无法显示
查看文件

1001
Assets/Scenes/LightEstimation.unity
文件差异内容过多而无法显示
查看文件

/Assets/Scenes/LightEstimation.unity.meta → /Assets/Scenes/LightEstimation/LightEstimation.unity.meta

正在加载...
取消
保存