浏览代码

Merge pull request #72 from unity/light-estimation

Re-refactor light estimation
/4.1
GitHub Enterprise 4 年前
当前提交
0f16250f
共有 5 个文件被更改,包括 429 次插入26 次删除
  1. 357
      Assets/Scenes/LightEstimation/HDRLightEstimation.unity
  2. 14
      Assets/Scripts/BasicLightEstimationUI.cs
  3. 45
      Assets/Scripts/HDRLightEstimation.cs
  4. 37
      Assets/Scripts/HDRLightEstimationUI.cs
  5. 2
      README.md

357
Assets/Scenes/LightEstimation/HDRLightEstimation.unity


m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &381010662
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 381010663}
- component: {fileID: 381010665}
- component: {fileID: 381010664}
m_Layer: 5
m_Name: AmbientColorVal
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &381010663
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 381010662}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 196, y: -355}
m_SizeDelta: {x: 300, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &381010664
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 381010662}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 49
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 49
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: New Text
--- !u!222 &381010665
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 381010662}
m_CullTransparentMesh: 0
--- !u!1 &400734518
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 3
m_RootOrder: 5
m_AnchoredPosition: {x: 125, y: -645}
m_AnchoredPosition: {x: 125, y: -936}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &400734520

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 6
m_RootOrder: 10
m_AnchoredPosition: {x: 125, y: -550}
m_AnchoredPosition: {x: 125, y: -841}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &639485727

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 639485725}
m_CullTransparentMesh: 0
--- !u!1 &659350078
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 659350079}
- component: {fileID: 659350081}
- component: {fileID: 659350080}
m_Layer: 5
m_Name: AmbientColorLabel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &659350079
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 659350078}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 125, y: -285}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &659350080
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 659350078}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 49
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 49
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: Ambient Color
--- !u!222 &659350081
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 659350078}
m_CullTransparentMesh: 0
--- !u!1 &862497818
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 4
m_RootOrder: 8
m_AnchoredPosition: {x: 125, y: -230}
m_AnchoredPosition: {x: 125, y: -521}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &862497820

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 1
m_RootOrder: 3
m_AnchoredPosition: {x: 125, y: -325}
m_AnchoredPosition: {x: 125, y: -616}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1139514417

m_Script: {fileID: 11500000, guid: a683fd6dcd1b846678402aaa9d564d0a, type: 3}
m_Name:
m_EditorClassIdentifier:
m_AmbientIntensityText: {fileID: 1395795803}
m_AmbientColorText: {fileID: 381010664}
m_ModeSupportedText: {fileID: 0}
--- !u!114 &1195718495
MonoBehaviour:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 5
m_RootOrder: 9
m_AnchoredPosition: {x: 125, y: -390}
m_AnchoredPosition: {x: 125, y: -681}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1373858106

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 7
m_RootOrder: 11
m_AnchoredPosition: {x: 125, y: -710}
m_AnchoredPosition: {x: 125, y: -1001}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1377107162

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1377107160}
m_CullTransparentMesh: 0
--- !u!1 &1395795801
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1395795802}
- component: {fileID: 1395795804}
- component: {fileID: 1395795803}
m_Layer: 5
m_Name: AmbientIntensityVal
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1395795802
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1395795801}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 196, y: -195}
m_SizeDelta: {x: 300, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1395795803
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1395795801}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 49
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 49
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: New Text
--- !u!222 &1395795804
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1395795801}
m_CullTransparentMesh: 0
--- !u!1 &1430355520
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 0
m_RootOrder: 2
m_AnchoredPosition: {x: 125, y: -165}
m_AnchoredPosition: {x: 125, y: -456}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1430355522

- target: {fileID: 2304810881573073946, guid: 4ee22c1f54b174122b6a766fe09e0de8,
type: 3}
propertyPath: m_RootOrder
value: 9
value: 12
objectReference: {fileID: 0}
- target: {fileID: 2304810881573073946, guid: 4ee22c1f54b174122b6a766fe09e0de8,
type: 3}

m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1957679544}
- {fileID: 659350079}
- {fileID: 1395795802}
- {fileID: 381010663}
- {fileID: 862497819}
- {fileID: 1373858105}
- {fileID: 639485726}

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 2
m_RootOrder: 4
m_AnchoredPosition: {x: 125, y: -485}
m_AnchoredPosition: {x: 125, y: -776}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1637602053

m_Script: {fileID: 11500000, guid: a7cfdbcf3ec334776ac44c24c8b3e991, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1957679543
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1957679544}
- component: {fileID: 1957679546}
- component: {fileID: 1957679545}
m_Layer: 5
m_Name: AmbientIntensityLabel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1957679544
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1957679543}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1633939411}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 125, y: -125}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1957679545
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1957679543}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 49
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 49
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: Ambient Intensity
--- !u!222 &1957679546
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1957679543}
m_CullTransparentMesh: 0
--- !u!1 &2146525365
GameObject:
m_ObjectHideFlags: 0

14
Assets/Scripts/BasicLightEstimationUI.cs


void Awake()
{
m_LightEstimation = GetComponent<BasicLightEstimation>();
m_BasicLightEstimation = GetComponent<BasicLightEstimation>();
SetUIValue(m_LightEstimation.brightness, ambientIntensityText);
SetUIValue(m_BasicLightEstimation.brightness, ambientIntensityText);
if (m_LightEstimation.colorTemperature != null)
SetUIValue(m_LightEstimation.colorTemperature, ambientColorText);
else if (m_LightEstimation.colorCorrection != null)
SetUIValue(m_LightEstimation.colorCorrection, ambientColorText);
if (m_BasicLightEstimation.colorTemperature != null)
SetUIValue(m_BasicLightEstimation.colorTemperature, ambientColorText);
else if (m_BasicLightEstimation.colorCorrection != null)
SetUIValue(m_BasicLightEstimation.colorCorrection, ambientColorText);
else
SetUIValue<float>(null, ambientColorText);
}

text.text = displayValue.HasValue ? displayValue.Value.ToString(): "Unavailable";
}
BasicLightEstimation m_LightEstimation;
BasicLightEstimation m_BasicLightEstimation;
}
}

45
Assets/Scripts/HDRLightEstimation.cs


}
/// <summary>
/// The estimated brightness of the physical environment, if available.
/// </summary>
public float? brightness { get; private set; }
/// <summary>
/// The estimated color temperature of the physical environment, if available.
/// </summary>
public float? colorTemperature { get; private set; }
/// <summary>
/// The estimated color correction value of the physical environment, if available.
/// </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; }

void FrameChanged(ARCameraFrameEventArgs args)
{
if (args.lightEstimation.averageBrightness.HasValue)
{
brightness = args.lightEstimation.averageBrightness.Value;
m_Light.intensity = brightness.Value;
}
else
{
brightness = null;
}
if (args.lightEstimation.averageColorTemperature.HasValue)
{
colorTemperature = args.lightEstimation.averageColorTemperature.Value;
m_Light.colorTemperature = colorTemperature.Value;
}
else
{
colorTemperature = null;
}
if (args.lightEstimation.colorCorrection.HasValue)
{
colorCorrection = args.lightEstimation.colorCorrection.Value;
m_Light.color = colorCorrection.Value;
}
else
{
colorCorrection = null;
}
if (args.lightEstimation.mainLightDirection.HasValue)
{
mainLightDirection = args.lightEstimation.mainLightDirection;

37
Assets/Scripts/HDRLightEstimationUI.cs


[RequireComponent(typeof(HDRLightEstimation))]
public class HDRLightEstimationUI : MonoBehaviour
{
[Tooltip("The UI Text element used to display the estimated ambient intensity in the physical environment.")]
[SerializeField]
Text m_AmbientIntensityText;
/// <summary>
/// The UI Text element used to display the estimated ambient intensity value.
/// </summary>
public Text ambientIntensityText
{
get { return m_AmbientIntensityText; }
set { m_AmbientIntensityText = ambientIntensityText; }
}
[Tooltip("The UI Text element used to display the estimated ambient color in the physical environment.")]
[SerializeField]
Text m_AmbientColorText;
/// <summary>
/// The UI Text element used to display the estimated ambient color in the scene.
/// </summary>
public Text ambientColorText
{
get { return m_AmbientColorText; }
set { m_AmbientColorText = value; }
}
[Tooltip("The UI Text element used to display the estimated direction of the main light for the physical environment.")]
[SerializeField]
Text m_MainLightDirectionText;

void Update()
{
//Display basic light estimation info
SetUIValue(m_HDRLightEstimation.brightness, ambientIntensityText);
//Display color temperature or color correction if supported
if (m_HDRLightEstimation.colorTemperature != null)
SetUIValue(m_HDRLightEstimation.colorTemperature, ambientColorText);
else if (m_HDRLightEstimation.colorCorrection != null)
SetUIValue(m_HDRLightEstimation.colorCorrection, ambientColorText);
else
SetUIValue<float>(null, ambientColorText);
//Display HDR only light estimation info
SetUIValue(m_HDRLightEstimation.mainLightDirection, mainLightDirectionText);
SetUIValue(m_HDRLightEstimation.mainLightColor, mainLightColorText);
SetUIValue(m_HDRLightEstimation.mainLightIntensityLumens, mainLightIntensityLumens);

2
README.md


Demonstrates basic light estimation information from the camera frame. You should see values for "Ambient Intensity" and "Ambient Color" on screen. The relevant script is [`BasicLightEstimation.cs`](https://github.com/Unity-Technologies/arfoundation-samples/blob/master/Assets/Scripts/BasicLightEstimation.cs) script.
### HDRLightEstimation
This sample attempts to read HDR lighting information. You should see values for "Main Light Direction", "Main Light Intensity Lumens", "Main Light Color", and "Spherical Harmonics". Most devices only support a subset of these 4, so some will be listed as "unavailable." The relevant script is [`HDRLightEstimation.cs`](https://github.com/Unity-Technologies/arfoundation-samples/blob/master/Assets/Scripts/HDRLightEstimation.cs) script.
This sample attempts to read HDR lighting information. You should see values for "Ambient Intensity", "Ambient Color", "Main Light Direction", "Main Light Intensity Lumens", "Main Light Color", and "Spherical Harmonics". Most devices only support a subset of these 6, so some will be listed as "Unavailable." The relevant script is [`HDRLightEstimation.cs`](https://github.com/Unity-Technologies/arfoundation-samples/blob/master/Assets/Scripts/HDRLightEstimation.cs) script.
On iOS, this is only available when face tracking is enabled and requires a device that supports face tracking (such as an iPhone X, XS or 11). When available, a virtual arrow appears in front of the camera which indicates the estimated main light direction. The virtual light direction is also updated, so that virtual content appears to be lit from the direction of the real light source.

正在加载...
取消
保存