浏览代码

Merge pull request #34 from unity/hdr-light-est

HDR Light Estimation Samples
/3.1
GitHub Enterprise 5 年前
当前提交
d0d2ff92
共有 11 个文件被更改,包括 2151 次插入1002 次删除
  1. 1
      .gitignore
  2. 58
      Assets/Scripts/LightEstimation.cs
  3. 74
      Assets/Scripts/LightEstimationUI.cs
  4. 2
      ProjectSettings/EditorBuildSettings.asset
  5. 8
      Assets/Scenes/LightEstimation.meta
  6. 1001
      Assets/Scenes/LightEstimation/ARKitHDRLightEstimation.unity
  7. 7
      Assets/Scenes/LightEstimation/ARKitHDRLightEstimation.unity.meta
  8. 1001
      Assets/Scenes/LightEstimation/LightEstimation.unity
  9. 1001
      Assets/Scenes/LightEstimation.unity
  10. 0
      /Assets/Scenes/LightEstimation/LightEstimation.unity.meta

1
.gitignore


# Ignore manually added packages
com.*
upm-xr*
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/

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;
}
}

74
Assets/Scripts/LightEstimationUI.cs


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

[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;
}
StringBuilder m_SphericalHarmonicsStringBuilder = new StringBuilder("");
/// <summary>
/// The UI Text element used to display the estimated color correction value for the scene.
/// </summary>

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)
{
m_SphericalHarmonicsStringBuilder.Clear();
for (int i = 0; i < 3; ++i)
{
if (i == 0)
m_SphericalHarmonicsStringBuilder.Append("R:[");
else if (i == 1)
m_SphericalHarmonicsStringBuilder.Append("G:[");
else
m_SphericalHarmonicsStringBuilder.Append("B:[");
for (int j = 0; j < 9; ++j)
{
m_SphericalHarmonicsStringBuilder.Append(j != 8 ? $"{maybeAmbientSphericalHarmonics.Value[i, j]}, " : $"{maybeAmbientSphericalHarmonics.Value[i, j]}]\n");
}
}
text.text = m_SphericalHarmonicsStringBuilder.ToString();
}
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

正在加载...
取消
保存