LightEstimation.cs
5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// Defines types of light estimation
/// </summary>
[Flags]
public enum LightEstimation
{
/// <summary>
/// No light estimation.
/// </summary>
None = 0,
/// <summary>
/// An estimate for the average ambient intensity of the environment.
/// </summary>
AmbientIntensity = 1 << 0,
/// <summary>
/// An estimate for the average ambient color of the environment.
/// </summary>
AmbientColor = 1 << 1,
/// <summary>
/// Estimate for the spherical harmonics representing the average ambient lighting of the environment.
/// </summary>
AmbientSphericalHarmonics = 1 << 2,
/// <summary>
/// An estimate for the direction of the main light in the environment.
/// </summary>
MainLightDirection = 1 << 3,
/// <summary>
/// An estimate for the intensity of the main light in the environment.
/// </summary>
MainLightIntensity = 1 << 4,
}
/// <summary>
/// Extension methods for the <see cref="LightEstimation"/> enum.
/// </summary>
public static class LightEstimationExtensions
{
/// <summary>
/// Converts a <see cref="LightEstimation"/> to a <c>Feature</c>.
/// </summary>
/// <param name="self">The <see cref="LightEstimation"/> being extended.</param>
/// <returns>A <c>Feature</c> representation of the <see cref="LightEstimation"/> with the relevant bits enabled.</returns>
public static Feature ToFeature(this LightEstimation self)
{
var feature = Feature.None;
if ((self & LightEstimation.AmbientIntensity) != LightEstimation.None)
feature |= Feature.LightEstimationAmbientIntensity;
if ((self & LightEstimation.AmbientColor) != LightEstimation.None)
feature |= Feature.LightEstimationAmbientColor;
if ((self & LightEstimation.AmbientSphericalHarmonics) != LightEstimation.None)
feature |= Feature.LightEstimationAmbientSphericalHarmonics;
if ((self & LightEstimation.MainLightDirection) != LightEstimation.None)
feature |= Feature.LightEstimationMainLightDirection;
if ((self & LightEstimation.MainLightIntensity) != LightEstimation.None)
feature |= Feature.LightEstimationMainLightIntensity;
return feature;
}
/// <summary>
/// Converts a <c>Feature</c> to a <see cref="LightEstimation"/> enum by extracting the
/// relevant light estimation bits from <paramref name="self"/>.
/// </summary>
/// <param name="self">The <c>Feature</c> being extended.</param>
/// <returns>A <see cref="LightEstimation"/> representation of the relevant <c>Feature</c> bits.</returns>
public static LightEstimation ToLightEstimation(this Feature self)
{
var lightEstimation = LightEstimation.None;
if ((self & Feature.LightEstimationAmbientIntensity) != Feature.None)
lightEstimation |= LightEstimation.AmbientIntensity;
if ((self & Feature.LightEstimationAmbientColor) != Feature.None)
lightEstimation |= LightEstimation.AmbientColor;
if ((self & Feature.LightEstimationAmbientSphericalHarmonics) != Feature.None)
lightEstimation |= LightEstimation.AmbientSphericalHarmonics;
if ((self & Feature.LightEstimationMainLightDirection) != Feature.None)
lightEstimation |= LightEstimation.MainLightDirection;
if ((self & Feature.LightEstimationMainLightIntensity) != Feature.None)
lightEstimation |= LightEstimation.MainLightIntensity;
return lightEstimation;
}
/// <summary>
/// Convert the deprecated <c>LightEstimationMode</c> to <see cref="LightEstimation"/>.
/// </summary>
/// <param name="mode">The <c>LightEstimationMode</c> to convert.</param>
/// <returns>The <see cref="LightEstimation"/> representation of the <c>LightEstimationMode</c>.</returns>
public static LightEstimation ToLightEstimation(this LightEstimationMode mode)
{
switch (mode)
{
case LightEstimationMode.AmbientIntensity:
return LightEstimation.AmbientIntensity
| LightEstimation.AmbientColor;
case LightEstimationMode.EnvironmentalHDR:
return LightEstimation.AmbientSphericalHarmonics
| LightEstimation.MainLightIntensity
| LightEstimation.MainLightDirection;
default:
return LightEstimation.None;
}
}
/// <summary>
/// Converts a <see cref="LightEstimation"/> to the deprecated <c>LightEstimationMode</c>.
/// </summary>
/// <param name="self">The <see cref="LightEstimation"/> being converted.</param>
/// <returns>A <c>LightEstimationMode</c> representation of the <see cref="LightEstimation"/>.</returns>
public static LightEstimationMode ToLightEstimationMode(this LightEstimation self)
{
switch (self)
{
case LightEstimation.AmbientColor:
case LightEstimation.AmbientIntensity:
return LightEstimationMode.AmbientIntensity;
case LightEstimation.AmbientSphericalHarmonics:
case LightEstimation.MainLightDirection:
case LightEstimation.MainLightIntensity:
return LightEstimationMode.EnvironmentalHDR;
default:
return LightEstimationMode.Disabled;
}
}
}
}