-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathPassthroughChanger.cs
144 lines (129 loc) · 5.15 KB
/
PassthroughChanger.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
// Copyright (c) Meta Platforms, Inc. and affiliates.
using Meta.Utilities;
using UnityEngine;
namespace CrypticCabinet.Passthrough
{
/// <summary>
/// This component interacts with the PassthroughConfigurator (if any in the scene)
/// to apply changes to the passthrough dynamically in terms of brightness, contrast,
/// opacity and saturation.
/// </summary>
public class PassthroughChanger : Singleton<PassthroughChanger>
{
/// <summary>
/// True if this change will need to happen on all headsets.
/// </summary>
[SerializeField] private bool m_propagateToAllClients;
private bool m_darkActive;
private bool m_uvActive;
/// <summary>
/// Reset the passthrough to default if this is disabled.
/// </summary>
private void OnDisable()
{
SetPassthroughDefaultLut();
}
[ContextMenu("Set Passthrough Default Lut")]
public void SetPassthroughDefaultLut()
{
m_darkActive = false;
m_uvActive = false;
SetPassthroughLut(ELutId.DEFAULT, 1);
}
[ContextMenu("Set Passthrough Darker Room Lut")]
public void SetPassthroughDarkerRoomLut()
{
if (m_darkActive)
{
m_darkActive = false;
if (!m_uvActive)
{
SetPassthroughDefaultLut();
}
}
else
{
m_darkActive = true;
SetPassthroughLut(ELutId.DARKER_ROOM, 1);
}
}
[ContextMenu("Set Passthrough Lighter Room Lut")]
public void SetPassthroughUvLightRoomLut()
{
if (m_uvActive)
{
m_uvActive = false;
if (!m_darkActive)
{
SetPassthroughDefaultLut();
}
}
else
{
m_uvActive = true;
SetPassthroughLut(ELutId.DARKER_ROOM, 1);
}
}
/// <summary>
/// Sets a new color LUT by ID, and smoothly reaches the specified target blend between
/// previous LUT and new LUT.
/// </summary>
/// <param name="lutID"></param>
/// <param name="targetBlend"> Value is clamped between 0 and 1 inclusive </param>
private void SetPassthroughLut(ELutId lutID, float targetBlend)
{
targetBlend = Mathf.Clamp(targetBlend, 0, 1);
Debug.Assert(PassthroughConfigurator.Instance != null,
"Instance of passthrough configurator is null!");
if (m_darkActive && m_uvActive)
{
targetBlend = 1.0f;
}
PassthroughConfigurator.Instance.SetLut(lutID, targetBlend, m_propagateToAllClients);
}
/// <summary>
/// Changes the brightness of the passthrough layer designated by the passthrough configurator.
/// </summary>
/// <param name="brightness">Value between -1 and +1</param>
public void SetPassthroughBrightness(float brightness)
{
brightness = Mathf.Clamp(brightness, -1, 1);
Debug.Assert(PassthroughConfigurator.Instance != null,
"Instance of passthrough configurator is null!");
PassthroughConfigurator.Instance.SetBrightness(brightness, m_propagateToAllClients);
}
/// <summary>
/// Changes the contrast of the passthrough layer designated by the passthrough configurator.
/// </summary>
/// <param name="contrast">Value between -1 and +1</param>
public void SetPassthroughContrast(float contrast)
{
contrast = Mathf.Clamp(contrast, -1, 1);
Debug.Assert(PassthroughConfigurator.Instance != null,
"Instance of passthrough configurator is null!");
PassthroughConfigurator.Instance.SetContrast(contrast, m_propagateToAllClients);
}
/// <summary>
/// Changes the opacity of the passthrough layer designated by the passthrough configurator.
/// </summary>
/// <param name="opacity">Value between -1 and +1</param>
public void SetPassthroughOpacity(float opacity)
{
opacity = Mathf.Clamp(opacity, -1, 1);
Debug.Assert(PassthroughConfigurator.Instance != null,
"Instance of passthrough configurator is null!");
PassthroughConfigurator.Instance.SetOpacity(opacity, m_propagateToAllClients);
}
/// <summary>
/// Changes the saturation of the passthrough layer designated by the passthrough configurator.
/// </summary>
/// <param name="saturation">Value between -1 and +1</param>
public void SetPassthroughSaturation(float saturation)
{
saturation = Mathf.Clamp(saturation, -1, 1);
Debug.Assert(PassthroughConfigurator.Instance != null,
"Instance of passthrough configurator is null!");
PassthroughConfigurator.Instance.SetSaturation(saturation, m_propagateToAllClients);
}
}
}