-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathXRLayout.cs
More file actions
126 lines (111 loc) · 4.65 KB
/
Copy pathXRLayout.cs
File metadata and controls
126 lines (111 loc) · 4.65 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
using System.Collections.Generic;
using System.Text;
namespace UnityEngine.Experimental.Rendering
{
/// <summary>
/// Used by render pipelines to store information about the XR device layout.
/// </summary>
public class XRLayout
{
readonly List<(Camera, XRPass)> m_ActivePasses = new List<(Camera, XRPass)>();
/// <summary>
/// State container for Quad View rendering, used to cache data across render passes.
/// </summary>
public QuadViewState quadView;
/// <summary>
/// Contains cached state for Quad View XR rendering.
/// Quad View is an XR rendering mode where peripheral (outer) and foveal (inner) views are rendered separately.
/// </summary>
public struct QuadViewState
{
/// <summary>
/// Cached vignette center from the peripheral (outer) view pass.
/// Used by the inner view pass to ensure vignette effect is consistent across both views.
/// </summary>
public Vector4 cachedPeripheralVignetteCenter;
}
/// <summary>
/// Configure the layout to render from the specified camera by generating passes from the the connected XR device.
/// </summary>
/// <param name="camera"> Camera that has XR device connected to. </param>
/// <param name="enableXR"> Determines XR capability of the generated layout. Can be used to force generate non-XR layout. </param>
public void AddCamera(Camera camera, bool enableXR)
{
if (camera == null)
return;
// Enable XR layout only for game camera
bool isGameCamera = (camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR);
bool xrSupported = isGameCamera && camera.targetTexture == null && enableXR;
if (XRSystem.displayActive && xrSupported)
{
XRSystem.SetDisplayZRange(camera.nearClipPlane, camera.farClipPlane);
XRSystem.CreateDefaultLayout(camera, this);
}
else
{
AddPass(camera, XRSystem.emptyPass);
}
}
/// <summary>
/// Used by render pipelines to reconfigure a pass from a camera.
/// </summary>
/// <param name="xrPass"> XRPass that needs to be reconfigured. </param>
/// <param name="camera"> The camera that XRPass configures against. </param>
public void ReconfigurePass(XRPass xrPass, Camera camera)
{
if (xrPass.enabled)
{
XRSystem.ReconfigurePass(xrPass, camera);
xrPass.UpdateCombinedOcclusionMesh();
}
}
/// <summary>
/// Used by render pipelines to access all registered passes on this layout.
/// </summary>
/// <returns> A list of registered camera/XRPass tuples. </returns>
public List<(Camera, XRPass)> GetActivePasses()
{
return m_ActivePasses;
}
internal void AddPass(Camera camera, XRPass xrPass)
{
xrPass.UpdateCombinedOcclusionMesh();
m_ActivePasses.Add((camera, xrPass));
}
internal void Clear()
{
for (int i = 0; i < m_ActivePasses.Count; i++)
{
// Pop from the back to keep initial ordering (see implementation of ObjectPool)
(Camera _, XRPass xrPass) = m_ActivePasses[m_ActivePasses.Count - i - 1];
if (xrPass != XRSystem.emptyPass)
xrPass.Release();
}
m_ActivePasses.Clear();
quadView = default;
}
internal void LogDebugInfo()
{
var sb = new StringBuilder();
sb.AppendFormat("XRSystem setup for frame {0}, active: {1}", Time.frameCount, XRSystem.displayActive);
sb.AppendLine();
for (int passIndex = 0; passIndex < m_ActivePasses.Count; passIndex++)
{
var pass = m_ActivePasses[passIndex].Item2;
for (int viewIndex = 0; viewIndex < pass.viewCount; viewIndex++)
{
var viewport = pass.GetViewport(viewIndex);
sb.AppendFormat("XR Pass {0} Cull {1} View {2} Slice {3} : {4} x {5}",
pass.multipassId,
pass.cullingPassId,
viewIndex,
pass.GetTextureArraySlice(viewIndex),
viewport.width,
viewport.height);
sb.AppendLine();
}
}
Debug.Log(sb);
}
}
}