17 using System.Collections;
18 using System.Collections.Generic;
23 using UnityEngine.Rendering;
55 Log.
Warn(
"Could not retrieve display settings from the plugin.");
79 [RequireComponent(typeof(Camera))]
83 internal GlassesHandle glassesHandle;
94 internal bool UseSpectatorCamera
128 private Dictionary<AREyes, Camera>
eyeCameras =
new Dictionary<AREyes, Camera>()
130 {
AREyes.EYE_LEFT,
null },
131 {
AREyes.EYE_RIGHT,
null }
162 private CommandBuffer commandBuffer;
166 [System.Obsolete(
"fieldOfView is deprecated, please use GlassesSettings' fieldOfView instead.")]
174 [System.Obsolete(
"nearClipPlane is deprecated, please use GlassesSettings' nearClipPlane instead.")]
182 [System.Obsolete(
"farClipPlane is deprecated, please use GlassesSettings' farClipPlane instead.")]
190 [System.Obsolete(
"aspectRatio is deprecated, please use DisplaySettings.monoWidthToHeightRatio instead.")]
209 if(headPoseRoot ==
null || spectatorSettings ==
null)
211 Log.
Error(
"Arguments cannot be null");
216 this.glassesSettings = glassesSettings;
217 this.spectatorSettings = spectatorSettings;
220 commandBuffer =
new CommandBuffer() { name =
"Onscreen Preview" };
262 GameObject placeholder = cloneCameraTemplateChildren ? null :
new GameObject(
"Placeholder");
263 if (!cloneCameraTemplateChildren)
265 placeholder.transform.parent =
headPose.transform.parent;
268 cameraTemplate.transform.GetChild(0).parent = placeholder.transform;
282 for (
int i = 0; i < splitStereoCamerasLeft.Length; i++)
284 Destroy(splitStereoCamerasLeft[i]);
288 for (
int i = 0; i < splitStereoCamerasRight.Length; i++)
290 Destroy(splitStereoCamerasRight[i]);
294 if (!cloneCameraTemplateChildren)
297 while (placeholder.transform.childCount > 0)
299 placeholder.transform.GetChild(0).parent =
cameraTemplate.transform;
301 Destroy(placeholder);
327 if (
leftEyeCamera.allowMSAA && QualitySettings.antiAliasing > 1)
329 leftTex.antiAliasing = QualitySettings.antiAliasing;
345 rightTex.antiAliasing = QualitySettings.antiAliasing;
370 leftEye.transform.position = pose.transform.position;
371 leftEye.transform.localPosition = pose.transform.localPosition;
372 leftEye.transform.rotation = pose.transform.rotation;
373 leftEye.transform.localRotation = pose.transform.localRotation;
374 leftEye.transform.localScale = pose.transform.localScale;
378 rightEye.transform.position = pose.transform.position;
379 rightEye.transform.localPosition = pose.transform.localPosition;
380 rightEye.transform.rotation = pose.transform.rotation;
381 rightEye.transform.localRotation = pose.transform.localRotation;
398 if(Application.isPlaying)
400 RenderPipelineManager.beginFrameRendering += OnBeginFrameRendering;
401 RenderPipelineManager.endFrameRendering += OnEndFrameRendering;
430 RenderPipelineManager.beginFrameRendering -= OnBeginFrameRendering;
431 RenderPipelineManager.endFrameRendering -= OnEndFrameRendering;
440 private void OnBeginFrameRendering(ScriptableRenderContext context, Camera[] cameras)
460 if(!UseSpectatorCamera)
483 GL.Clear(
true,
true, Color.black);
499 float screenRatio = Screen.width / (float)Screen.height;
504 if(screenRatio > targetRatio) {
506 float normalizedWidth = targetRatio / screenRatio;
507 float barThickness = (1f - normalizedWidth) / 2f;
512 float normalizedHeight = screenRatio / targetRatio;
513 float barThickness = (1f - normalizedHeight) / 2f;
526 void OnEndFrameRendering(ScriptableRenderContext context, Camera[] cameras)
537 bool currentlyRenderingEyeCameras =
false;
539 for (
int i = 0; i < cameras.Length; i++)
542 if (cameras[i].Equals(UnityEditor.SceneView.lastActiveSceneView.camera))
549 currentlyRenderingEyeCameras =
true;
552 if (!currentlyRenderingEyeCameras)
558 float screenRatio = Screen.width / (float)Screen.height;
560 ? DisplaySettings.stereoWidthToHeightRatio
561 : DisplaySettings.monoWidthToHeightRatio;
562 Vector2 frameScale = Vector2.one;
564 if (screenRatio != targetRatio)
566 frameScale = screenRatio > targetRatio
567 ?
new Vector2(screenRatio / targetRatio, 1f)
568 : new Vector2(1f, targetRatio / screenRatio);
573 context.ExecuteCommandBuffer(commandBuffer);
575 commandBuffer.Clear();
577 spectatorSettings.ResetSpectatorCamera();
598 if(splitStereoCameras !=
null && splitStereoCameras.Length > 0
599 && splitStereoCameras[0].Equals(
this))
601 Graphics.Blit(src,
null as RenderTexture);
608 if(!UseSpectatorCamera)
624 Graphics.Blit(previewTex,
625 null as RenderTexture,
629 else Graphics.Blit(src,
null as RenderTexture);
633 spectatorSettings.ResetSpectatorCamera();
640 var cachedWaitForEndOfFrame =
new WaitForEndOfFrame();
644 yield
return cachedWaitForEndOfFrame;
657 bool isSrgb = leftTargetTex.sRGB;
660 Quaternion rotToUWRLD_ULVC =
leftEyeCamera.transform.rotation;
672 leftTexHandle, rightTexHandle,
673 leftTargetTex.width, rightTargetTex.height,
688 if (glassesSettings ==
null)
715 if (
false == UnityEditor.EditorApplication.isPlaying)
735 leftEye.hideFlags = HideFlags.None;
736 rightEye.hideFlags = HideFlags.None;
740 leftEye.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
741 rightEye.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
TiltFive.Glasses.AREyes AREyes
static bool GetDisplayDimensions(ref Vector2Int displayDimensions)
static bool PresentStereoImages(PlayerIndex playerIndex, IntPtr leftTexHandle, IntPtr rightTexHandle, int texWidth_PIX, int texHeight_PIX, bool isSrgb, float fovYDegrees, float widthToHeightRatio, Quaternion rotToUGBD_ULVC, Vector3 posOfULVC_UGBD, Quaternion rotToUGBD_URVC, Vector3 posOfURVC_UGBD)
Display settings constants.
readonly Vector2Int defaultDimensions
static float monoWidthToHeightRatio
The display aspect ratio.
const RenderTextureFormat nativeTextureFormat
static int monoWidth
The display width for a single eye.
static float stereoWidthToHeightRatio
The double-width display aspect ratio.
static DisplaySettings Instance
static int height
The display height.
const int depthBuffer
The depth buffer's precision.
static DisplaySettings instance
static int stereoWidth
The display width for two eyes.
The Glasses API and runtime.
static bool IsTracked(PlayerIndex playerIndex=PlayerIndex.One)
Indicate if the specified glasses are tracked.
GlassesSettings encapsulates all configuration data used by the Glasses' tracking runtime to compute ...
Camera cameraTemplate
The camera used as a template for creating the eye cameras at runtime.
float farClipPlane
The far clip plane in physical space (meters), to adjust for content scale and gameboard size
float nearClipPlane
The near clip plane in physical space (meters), to adjust for content scale and gameboard size
bool cloneCameraTemplateChildren
Whether or not the camera template's child gameobjects should be cloned during eye camera instantiati...
static void Warn(string m, params object[] list)
WARN logging function call.
static void Error(string m, params object[] list)
ERROR logging function call.
Provides access to player settings and functionality.
static bool IsConnected(PlayerIndex playerIndex)
Determines whether the specified player has an associated pair of glasses connected.
PlayerIndex spectatedPlayer
The player that will have their perspective mirrored on screen.
Rect rect
The viewport rect used by the Spectator Camera.
GlassesMirrorMode glassesMirrorMode
The spectator camera will display content on screen depending on the mirroring mode....
Camera spectatorCamera
The camera used for rendering the onscreen preview
IEnumerator presentStereoImagesCoroutine
float nearClipPlane
The Cameras' near clip plane property.
bool showCameras
In-editor toggle for displaying the eye cameras in the runtime Hierarchy.
void SyncTransform()
EDITOR-ONLY: Syncs the eye Cameras' transform to the Head Pose when tracking is not available.
float aspectRatio
The Cameras' aspect ratio property.
const string RIGHT_EYE_CAMERA_NAME
The name assigned to the dynamically created camera used for rendering the right eye.
void Initialize(GameObject headPoseRoot, GlassesSettings glassesSettings, SpectatorSettings spectatorSettings)
float farClipPlane
The Cameras' far clip plane property.
void OnPreRender()
Configure rendering parameters for the upcoming frame.
GameObject rightEye
The right eye camera GameObject.
void SyncFields()
Syncs the Cameras' fields to the settings.
Quaternion rotToUGBD_UWRLD
The rotation taking points from the Unity world-space reference frame to the game board reference fra...
void InstantiateEyeCameras(out GameObject leftEye, out GameObject rightEye)
void OnValidate()
EDITOR-ONLY
void Awake()
Awake this instance.
Camera leftEyeCamera
The left eye Camera property.
SplitStereoTextures splitStereoTextures
bool startedMirroringToOnscreenPreview
void PresentStereoImages()
IEnumerator PresentStereoImagesCoroutine()
GlassesMirrorMode previousMirrorMode
GlassesMirrorMode glassesMirrorMode
void ShowHideCameras()
Show/hide to the eye camerasin the hierarchy.
const string LEFT_EYE_CAMERA_NAME
The name assigned to the dynamically created camera used for rendering the left eye.
Camera cameraTemplate
The Camera used as a template when creating the eye cameras.
Vector3 posUGBD_UWRLD
The position of the game board reference frame w.r.t. the Unity world-space reference frame.
void ConfigureEyeCameras()
Material displayBlitShader
The Material used to store/reference the shader.
GameObject leftEye
The left eye camera GameObject.
Camera rightEyeCamera
The right eye Camera property.
float scaleToUGBD_UWRLD
The uniform scale factor that takes points from the Unity world-space to the game board reference fra...
const string SHADER_DISPLAY_BLIT
The name of the custom shader that blits the rendertextures to the backbuffer.
float fieldOfView
The Cameras' field of view property.
void OnRenderImage(RenderTexture src, RenderTexture dst)
Apply post-processing effects to the final image before it is presented.
void GenerateEyeCameras(out GameObject leftEye, out GameObject rightEye)
GameObject headPose
The head pose GameObject property.
Dictionary< AREyes, Camera > eyeCameras
The Camera objects.
RenderTexture MonoPreviewTex
The rendertexture used to display onscreen previews for the left or right eye camera.
void ValidateNativeTexturePointers()
Determines whether the left/right texture handles are still valid, and resets them if needed
void GetNativeTexturePointers(out IntPtr leftTexHandle, out IntPtr rightTexHandle)
Acquires the native output textures upon startup or invalidaiton.
void SubmitPreviewTextures(GlassesMirrorMode glassesMirrorMode)
Copies frame data from the HDR input textures to the onscreen preview textures.
RenderTexture LeftTexture_GLS
The left eye rendertexture
RenderTexture RightTexture_GLS
The right eye rendertexture
RenderTexture StereoPreviewTex
The rendertexture used to display onscreen previews for the left and right eye cameras in stereo.
void Initialize()
Creates and configures the stereo rendertextures
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)