-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
CameraWhiteBalanceController.cs
146 lines (122 loc) · 4.75 KB
/
CameraWhiteBalanceController.cs
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
136
137
138
139
140
141
142
143
144
145
146
using System;
using UnityEngine.UI;
#if UNITY_IOS
using UnityEngine.XR.ARKit;
#endif // UNITY_IOS
namespace UnityEngine.XR.ARFoundation.Samples
{
[RequireComponent(typeof(ARCameraManager))]
public class CameraWhiteBalanceController
#if UNITY_IOS
: ARKitAdvancedCameraConfigurationController<ARKitWhiteBalanceMode, ARKitWhiteBalanceGains>
#else
: ARKitAdvancedCameraConfigurationController
#endif
{
[SerializeField]
Slider m_BlueGainSlider;
[SerializeField]
Slider m_GreenGainSlider;
[SerializeField]
Slider m_RedGainSlider;
float m_BlueGain;
float m_GreenGain;
float m_RedGain;
public float blueGain
{
get => m_BlueGain;
set => m_BlueGain = value;
}
public float greenGain
{
get => m_GreenGain;
set => m_GreenGain = value;
}
public float redGain
{
get => m_RedGain;
set => m_RedGain = value;
}
#if UNITY_IOS
protected override void UpdateCachedValues(ARKitLockedCamera lockedCamera)
{
currentMode = lockedCamera.currentWhiteBalanceMode;
currentValue = lockedCamera.whiteBalance;
}
protected override void PopulateSupportedModes(ARKitLockedCamera lockedCamera)
{
var supportedModes = lockedCamera.supportedWhiteBalanceModes;
m_SupportedModes = new();
if ((supportedModes & ARKitWhiteBalanceMode.Locked) != ARKitWhiteBalanceMode.None)
{
m_SupportedModes.Add(ARKitWhiteBalanceMode.Locked);
}
if ((supportedModes & ARKitWhiteBalanceMode.Auto) != ARKitWhiteBalanceMode.None)
{
m_SupportedModes.Add(ARKitWhiteBalanceMode.Auto);
}
if ((supportedModes & ARKitWhiteBalanceMode.ContinuousAuto) != ARKitWhiteBalanceMode.None)
{
m_SupportedModes.Add(ARKitWhiteBalanceMode.ContinuousAuto);
}
}
protected override void PopulateRanges(ARKitLockedCamera lockedCamera)
{
if (!m_BlueGainSlider && !m_GreenGainSlider && !m_RedGainSlider)
{
return;
}
var range = lockedCamera.whiteBalanceRange;
Debug.Log($"White Balance Range: {range.minimumGain}, {range.maximumGain}");
// update range of blue gain slider
if (m_BlueGainSlider)
{
m_BlueGainSlider.minValue = range.minimumGain;
m_BlueGainSlider.maxValue = range.maximumGain;
}
// update range of green gain slider
if (m_GreenGainSlider)
{
m_GreenGainSlider.minValue = range.minimumGain;
m_GreenGainSlider.maxValue = range.maximumGain;
}
// update range of red gain slider
if (m_RedGainSlider)
{
m_RedGainSlider.minValue = range.minimumGain;
m_RedGainSlider.maxValue = range.maximumGain;
}
RefreshUI(lockedCamera.whiteBalance);
}
void RefreshUI(ARKitWhiteBalanceGains whiteBalance)
{
if (m_BlueGainSlider != null && Math.Abs(m_BlueGainSlider.value - whiteBalance.blue) > float.Epsilon)
{
blueGain = whiteBalance.blue;
m_BlueGainSlider.SetValueWithoutNotify(whiteBalance.blue);
}
if (m_GreenGainSlider != null && Math.Abs(m_GreenGainSlider.value - whiteBalance.green) > float.Epsilon)
{
greenGain = whiteBalance.green;
m_GreenGainSlider.SetValueWithoutNotify(whiteBalance.green);
}
if (m_RedGainSlider != null && Math.Abs(m_RedGainSlider.value - whiteBalance.red) > float.Epsilon)
{
redGain = whiteBalance.red;
m_RedGainSlider.SetValueWithoutNotify(whiteBalance.red);
}
}
protected override void UpdateMode(ARKitLockedCamera lockedCamera, ARKitWhiteBalanceMode mode)
{
Debug.Log($"Updating white balance mode to {mode.ToString()}.");
lockedCamera.requestedWhiteBalanceMode = mode;
}
protected override void UpdateConfigValues(ARKitLockedCamera lockedCamera)
{
var whiteBalance = new ARKitWhiteBalanceGains(m_BlueGain, m_GreenGain, m_RedGain);
Debug.Log($"Updating white balance: {whiteBalance.ToString()}");
lockedCamera.whiteBalance = whiteBalance;
}
#endif // UNITY_IOS
}
}