Tilt Five Unity API  1.3.0
Public Member Functions | Public Attributes | Properties | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TiltFive.SplitStereoCamera Class Reference
Inheritance diagram for TiltFive.SplitStereoCamera:

Public Member Functions

void Initialize (GameObject headPoseRoot, GlassesSettings glassesSettings, SpectatorSettings spectatorSettings)
 

Public Attributes

GameObject headPose = null
 The head pose GameObject property. More...
 
bool showCameras = true
 In-editor toggle for displaying the eye cameras in the runtime Hierarchy. More...
 
Vector3 posUGBD_UWRLD = Vector3.zero
 The position of the game board reference frame w.r.t. the Unity world-space reference frame. More...
 
Quaternion rotToUGBD_UWRLD = Quaternion.identity
 The rotation taking points from the Unity world-space reference frame to the game board reference frame. More...
 
float scaleToUGBD_UWRLD = 1.0f
 The uniform scale factor that takes points from the Unity world-space to the game board reference frame. More...
 

Properties

Camera spectatorCamera [get]
 
Camera cameraTemplate [get]
 The Camera used as a template when creating the eye cameras. More...
 
Camera leftEyeCamera [get]
 The left eye Camera property. More...
 
Camera rightEyeCamera [get]
 The right eye Camera property. More...
 
GlassesMirrorMode glassesMirrorMode [get]
 
float fieldOfView [get, set]
 The Cameras' field of view property. More...
 
float nearClipPlane [get, set]
 The Cameras' near clip plane property. More...
 
float farClipPlane [get, set]
 The Cameras' far clip plane property. More...
 
float aspectRatio [get, set]
 The Cameras' aspect ratio property. More...
 

Private Member Functions

void Awake ()
 Awake this instance. More...
 
void InstantiateEyeCameras (out GameObject leftEye, out GameObject rightEye)
 
void GenerateEyeCameras (out GameObject leftEye, out GameObject rightEye)
 
void ConfigureEyeCameras ()
 
void SyncTransform ()
 EDITOR-ONLY: Syncs the eye Cameras' transform to the Head Pose when tracking is not available. More...
 
void OnEnable ()
 
void OnDisable ()
 
void OnPreRender ()
 Configure rendering parameters for the upcoming frame. More...
 
void OnRenderImage (RenderTexture src, RenderTexture dst)
 Apply post-processing effects to the final image before it is presented. More...
 
IEnumerator PresentStereoImagesCoroutine ()
 
void PresentStereoImages ()
 
void SyncFields (Camera theCamera)
 Syncs the Cameras' fields to the input parameter. More...
 
void OnValidate ()
 EDITOR-ONLY More...
 
void ShowHideCameras ()
 Show/hide to the eye camerasin the hierarchy. More...
 

Private Attributes

bool useSpectatorCamera
 
bool startedMirroringToOnscreenPreview = false
 
IEnumerator presentStereoImagesCoroutine
 
GameObject leftEye
 The left eye camera GameObject. More...
 
GameObject rightEye
 The right eye camera GameObject. More...
 
Dictionary< AREyes, Camera > eyeCameras
 The Camera objects. More...
 
Material displayBlitShader
 The Material used to store/reference the shader. More...
 
GlassesMirrorMode previousMirrorMode = GlassesMirrorMode.LeftEye
 
SplitStereoTextures splitStereoTextures = new SplitStereoTextures()
 

Static Private Attributes

const string LEFT_EYE_CAMERA_NAME = "Left Eye Camera"
 The name assigned to the dynamically created camera used for rendering the left eye. More...
 
const string RIGHT_EYE_CAMERA_NAME = "Right Eye Camera"
 The name assigned to the dynamically created camera used for rendering the right eye. More...
 
const string SHADER_DISPLAY_BLIT = "Tilt Five/Simple Blend Shader"
 The name of the custom shader that blits the rendertextures to the backbuffer. More...
 

Detailed Description

Definition at line 80 of file SplitStereoCamera.cs.

Member Function Documentation

◆ Awake()

void TiltFive.SplitStereoCamera.Awake ( )
private

Awake this instance.

Definition at line 200 of file SplitStereoCamera.cs.

201  {
202  enabled = false;
203  useSpectatorCamera = false;
205  }

References TiltFive.SplitStereoCamera.startedMirroringToOnscreenPreview, and TiltFive.SplitStereoCamera.useSpectatorCamera.

◆ ConfigureEyeCameras()

void TiltFive.SplitStereoCamera.ConfigureEyeCameras ( )
private

Definition at line 320 of file SplitStereoCamera.cs.

321  {
322  // Use the head pose camera's preferred texture format, rather than forcing it to render in LDR
324 
325  // Configure the left eye camera's render target
326  RenderTexture leftTex = splitStereoTextures.LeftTexture_GLS;
327  if (leftEyeCamera.allowMSAA && QualitySettings.antiAliasing > 1)
328  {
329  leftTex.antiAliasing = QualitySettings.antiAliasing;
330 
331  // Ensure that the preview textures' antiAliasing settings match.
332  // Otherwise, Unity 2020.3 complains during Graphics.CopyTexture about the mismatch,
333  // resulting in a broken onscreen preview (manifesting as a black screen).
334  splitStereoTextures.MonoPreviewTex.antiAliasing = QualitySettings.antiAliasing;
335  splitStereoTextures.StereoPreviewTex.antiAliasing = QualitySettings.antiAliasing;
336  }
337 
338  leftEyeCamera.targetTexture = leftTex;
339  leftEyeCamera.depth = spectatorCamera.depth - 1;
340 
341  // Configure the right eye camera's render target
342  RenderTexture rightTex = splitStereoTextures.RightTexture_GLS;
343  if (rightEyeCamera.allowMSAA && QualitySettings.antiAliasing > 1)
344  {
345  rightTex.antiAliasing = QualitySettings.antiAliasing;
346  }
347 
348  rightEyeCamera.targetTexture = rightTex;
349  rightEyeCamera.depth = spectatorCamera.depth - 1;
350  }
Camera leftEyeCamera
The left eye Camera property.
SplitStereoTextures splitStereoTextures
Camera rightEyeCamera
The right eye Camera property.
RenderTexture MonoPreviewTex
The rendertexture used to display onscreen previews for the left or right eye camera.
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

References TiltFive.SplitStereoTextures.Initialize(), TiltFive.SplitStereoCamera.leftEyeCamera, TiltFive.SplitStereoTextures.LeftTexture_GLS, TiltFive.SplitStereoTextures.MonoPreviewTex, TiltFive.SplitStereoCamera.rightEyeCamera, TiltFive.SplitStereoTextures.RightTexture_GLS, TiltFive.SplitStereoCamera.spectatorCamera, TiltFive.SplitStereoCamera.splitStereoTextures, and TiltFive.SplitStereoTextures.StereoPreviewTex.

Referenced by TiltFive.SplitStereoCamera.Initialize().

◆ GenerateEyeCameras()

void TiltFive.SplitStereoCamera.GenerateEyeCameras ( out GameObject  leftEye,
out GameObject  rightEye 
)
private

Definition at line 305 of file SplitStereoCamera.cs.

306  {
307  leftEye = new GameObject(LEFT_EYE_CAMERA_NAME, typeof(Camera));
308  rightEye = new GameObject(RIGHT_EYE_CAMERA_NAME, typeof(Camera));
309 
310  eyeCameras[AREyes.EYE_LEFT] = leftEye.GetComponent<Camera>();
311  eyeCameras[AREyes.EYE_RIGHT] = rightEye.GetComponent<Camera>();
312 
313  leftEye.transform.parent = headPose.transform;
314  rightEye.transform.parent = headPose.transform;
315 
316  leftEye.transform.SetPositionAndRotation(headPose.transform.position, headPose.transform.rotation);
317  rightEye.transform.SetPositionAndRotation(headPose.transform.position, headPose.transform.rotation);
318  }
TiltFive.Glasses.AREyes AREyes
const string RIGHT_EYE_CAMERA_NAME
The name assigned to the dynamically created camera used for rendering the right eye.
GameObject rightEye
The right eye camera GameObject.
const string LEFT_EYE_CAMERA_NAME
The name assigned to the dynamically created camera used for rendering the left eye.
GameObject leftEye
The left eye camera GameObject.
GameObject headPose
The head pose GameObject property.
Dictionary< AREyes, Camera > eyeCameras
The Camera objects.

References TiltFive.SplitStereoCamera.eyeCameras, TiltFive.SplitStereoCamera.headPose, TiltFive.SplitStereoCamera.LEFT_EYE_CAMERA_NAME, TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.RIGHT_EYE_CAMERA_NAME, and TiltFive.SplitStereoCamera.rightEye.

Referenced by TiltFive.SplitStereoCamera.Initialize().

◆ Initialize()

void TiltFive.SplitStereoCamera.Initialize ( GameObject  headPoseRoot,
GlassesSettings  glassesSettings,
SpectatorSettings  spectatorSettings 
)

Definition at line 207 of file SplitStereoCamera.cs.

208  {
209  if(headPoseRoot == null || spectatorSettings == null)
210  {
211  Log.Error("Arguments cannot be null");
212  return;
213  }
214 
215  headPose = headPoseRoot;
216  this.glassesSettings = glassesSettings;
217  this.spectatorSettings = spectatorSettings;
218 
219 #if TILT_FIVE_SRP
220  commandBuffer = new CommandBuffer() { name = "Onscreen Preview" };
221 #endif
222 
223  // For this mode, we need the headPose Camera to be enabled, as it is the
224  // primary Camera for blitting to the backbuffer.
225  if(spectatorCamera != null)
226  {
227  spectatorCamera.enabled = true;
228  }
229 
230  if(cameraTemplate != null)
231  {
233  }
234  else
235  {
237  }
239 
240  // Load the blitting shader to copy the the left & right render textures
241  // into the backbuffer
242  displayBlitShader = new Material(Shader.Find(SHADER_DISPLAY_BLIT));
243  // Did we find it?
244  if (null == displayBlitShader)
245  {
246  Log.Error("Failed to load Shader '{0}'", SHADER_DISPLAY_BLIT);
247  }
248 
250  SyncTransform();
251  ShowHideCameras();
252 
253  enabled = true;
254  }
The Logger.
Definition: Log.cs:42
static void Error(string m, params object[] list)
ERROR logging function call.
Definition: Log.cs:127
void SyncTransform()
EDITOR-ONLY: Syncs the eye Cameras' transform to the Head Pose when tracking is not available.
void SyncFields(Camera theCamera)
Syncs the Cameras' fields to the input parameter.
void InstantiateEyeCameras(out GameObject leftEye, out GameObject rightEye)
void ShowHideCameras()
Show/hide to the eye camerasin the hierarchy.
Camera cameraTemplate
The Camera used as a template when creating the eye cameras.
Material displayBlitShader
The Material used to store/reference the shader.
const string SHADER_DISPLAY_BLIT
The name of the custom shader that blits the rendertextures to the backbuffer.
void GenerateEyeCameras(out GameObject leftEye, out GameObject rightEye)

References TiltFive.SplitStereoCamera.cameraTemplate, TiltFive.SplitStereoCamera.ConfigureEyeCameras(), TiltFive.SplitStereoCamera.displayBlitShader, TiltFive.Logging.Log.Error(), TiltFive.SplitStereoCamera.GenerateEyeCameras(), TiltFive.SplitStereoCamera.headPose, TiltFive.SplitStereoCamera.InstantiateEyeCameras(), TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.rightEye, TiltFive.SplitStereoCamera.SHADER_DISPLAY_BLIT, TiltFive.SplitStereoCamera.ShowHideCameras(), TiltFive.SplitStereoCamera.spectatorCamera, TiltFive.SplitStereoCamera.SyncFields(), and TiltFive.SplitStereoCamera.SyncTransform().

Referenced by TiltFive.Glasses.GlassesCore.Reset().

◆ InstantiateEyeCameras()

void TiltFive.SplitStereoCamera.InstantiateEyeCameras ( out GameObject  leftEye,
out GameObject  rightEye 
)
private

Definition at line 256 of file SplitStereoCamera.cs.

257  {
258  var cloneCameraTemplateChildren = glassesSettings.cloneCameraTemplateChildren;
259 
260  // When we clone the head pose camera using Instantiate, we may not want to clone its children.
261  // If this is the case, detach the children and reparent them under a placeholder/babysitter GameObject
262  GameObject placeholder = cloneCameraTemplateChildren ? null : new GameObject("Placeholder");
263  if (!cloneCameraTemplateChildren)
264  {
265  placeholder.transform.parent = headPose.transform.parent;
266  while (cameraTemplate.transform.childCount > 0)
267  {
268  cameraTemplate.transform.GetChild(0).parent = placeholder.transform;
269  }
270  }
271 
272  // Instantiate left and right eye cameras from the camera template.
273  leftEye = Instantiate(cameraTemplate.gameObject, headPose.transform.position, headPose.transform.rotation, headPose.transform);
275  eyeCameras[AREyes.EYE_LEFT] = leftEye.GetComponent<Camera>();
276 
277  rightEye = Instantiate(cameraTemplate.gameObject, headPose.transform.position, headPose.transform.rotation, headPose.transform);
279  eyeCameras[AREyes.EYE_RIGHT] = rightEye.GetComponent<Camera>();
280 
281  var splitStereoCamerasLeft = leftEye.GetComponents<SplitStereoCamera>();
282  for (int i = 0; i < splitStereoCamerasLeft.Length; i++)
283  {
284  Destroy(splitStereoCamerasLeft[i]);
285  }
286 
287  var splitStereoCamerasRight = rightEye.GetComponents<SplitStereoCamera>();
288  for (int i = 0; i < splitStereoCamerasRight.Length; i++)
289  {
290  Destroy(splitStereoCamerasRight[i]);
291  }
292 
293 
294  if (!cloneCameraTemplateChildren)
295  {
296  // Reclaim the head pose camera's children from the placeholder/babysitter GameObject
297  while (placeholder.transform.childCount > 0)
298  {
299  placeholder.transform.GetChild(0).parent = cameraTemplate.transform;
300  }
301  Destroy(placeholder);
302  }
303  }
bool cloneCameraTemplateChildren
Whether or not the camera template's child gameobjects should be cloned during eye camera instantiati...

References TiltFive.SplitStereoCamera.cameraTemplate, TiltFive.GlassesSettings.cloneCameraTemplateChildren, TiltFive.SplitStereoCamera.eyeCameras, TiltFive.SplitStereoCamera.headPose, TiltFive.SplitStereoCamera.LEFT_EYE_CAMERA_NAME, TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.RIGHT_EYE_CAMERA_NAME, and TiltFive.SplitStereoCamera.rightEye.

Referenced by TiltFive.SplitStereoCamera.Initialize().

◆ OnDisable()

void TiltFive.SplitStereoCamera.OnDisable ( )
private

Definition at line 406 of file SplitStereoCamera.cs.

407  {
409  {
410  leftEye.SetActive(false);
411  rightEye.SetActive(false);
412  leftEyeCamera.enabled = false;
413  rightEyeCamera.enabled = false;
414  }
415 
416  if(presentStereoImagesCoroutine != null)
417  {
418  StopCoroutine(presentStereoImagesCoroutine);
419  }
420 #if TILT_FIVE_SRP
421  RenderPipelineManager.beginFrameRendering -= OnBeginFrameRendering;
422  RenderPipelineManager.endFrameRendering -= OnEndFrameRendering;
423 #endif
424  }

References TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.leftEyeCamera, TiltFive.SplitStereoCamera.presentStereoImagesCoroutine, TiltFive.SplitStereoCamera.rightEye, TiltFive.SplitStereoCamera.rightEyeCamera, and TiltFive.SplitStereoCamera.startedMirroringToOnscreenPreview.

◆ OnEnable()

void TiltFive.SplitStereoCamera.OnEnable ( )
private

Definition at line 388 of file SplitStereoCamera.cs.

389  {
390  leftEye.SetActive(true);
391  rightEye.SetActive(true);
392  leftEyeCamera.enabled = true;
393  rightEyeCamera.enabled = true;
395  StartCoroutine(presentStereoImagesCoroutine);
396 
397 #if TILT_FIVE_SRP
398  if(Application.isPlaying)
399  {
400  RenderPipelineManager.beginFrameRendering += OnBeginFrameRendering;
401  RenderPipelineManager.endFrameRendering += OnEndFrameRendering;
402  }
403 #endif
404  }
IEnumerator PresentStereoImagesCoroutine()

References TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.leftEyeCamera, TiltFive.SplitStereoCamera.presentStereoImagesCoroutine, TiltFive.SplitStereoCamera.PresentStereoImagesCoroutine(), TiltFive.SplitStereoCamera.rightEye, and TiltFive.SplitStereoCamera.rightEyeCamera.

◆ OnPreRender()

void TiltFive.SplitStereoCamera.OnPreRender ( )
private

Configure rendering parameters for the upcoming frame.

Definition at line 447 of file SplitStereoCamera.cs.

448  {
450 
451  if(!UseSpectatorCamera)
452  {
453  return;
454  }
455 
456  spectatorCamera.targetTexture = null;
457 
458  /* If the screen mirror mode changes, junk data will be displayed
459  * in the black bars unless we clear the screen buffer.
460  *
461  * This has to be done before we adjust the headpose camera rect,
462  * since GL.Clear's effect is limited by the active viewport.
463  *
464  * We also must ensure that we call GL.Clear once as soon as we begin mirroring to the screen.
465  * See Gerrit #3013 for additional detail, but in short, there's an implicit mirror mode transition
466  * at the moment we begin mirroring to the onscreen preview that isn't captured by comparing
467  * glassesMirrorMode against previousMirrorMode, and if we don't check for it using the
468  * startedMirroringToOnscreenPreview flag, junk data could fill the letterboxing/pillarboxing.*/
470  {
471  // Before calling GL.Clear(), we need to reset the viewport.
472  // Otherwise, we may not clear the entire screen in some cases.
473  GL.Viewport(spectatorCamera.pixelRect);
474  GL.Clear(true, true, Color.black);
477  }
478 
480  {
481  return;
482  }
483 
484  spectatorCamera.cullingMask = 0; // Cull all layers, render nothing.
485  spectatorCamera.fieldOfView = glassesSettings.fieldOfView;
486  spectatorCamera.nearClipPlane = glassesSettings.nearClipPlane / scaleToUGBD_UWRLD;
487  spectatorCamera.farClipPlane = glassesSettings.farClipPlane / scaleToUGBD_UWRLD;
488 
489  // Lock the aspect ratio and add pillarboxing/letterboxing as needed.
490  float screenRatio = Screen.width / (float)Screen.height;
491  float targetRatio = glassesMirrorMode == GlassesMirrorMode.Stereoscopic
492  ? DisplaySettings.stereoWidthToHeightRatio
493  : DisplaySettings.monoWidthToHeightRatio;
494 
495  if(screenRatio > targetRatio) {
496  // Screen or window is wider than the target: pillarbox.
497  float normalizedWidth = targetRatio / screenRatio;
498  float barThickness = (1f - normalizedWidth) / 2f;
499  spectatorCamera.rect = new Rect(barThickness, 0, normalizedWidth, 1);
500  }
501  else {
502  // Screen or window is narrower than the target: letterbox.
503  float normalizedHeight = screenRatio / targetRatio;
504  float barThickness = (1f - normalizedHeight) / 2f;
505  spectatorCamera.rect = new Rect(0, barThickness, 1, normalizedHeight);
506  }
507  }
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
GlassesMirrorMode previousMirrorMode
GlassesMirrorMode glassesMirrorMode
float scaleToUGBD_UWRLD
The uniform scale factor that takes points from the Unity world-space to the game board reference fra...
void ValidateNativeTexturePointers()
Determines whether the left/right texture handles are still valid, and resets them if needed

References TiltFive.GlassesSettings.farClipPlane, TiltFive.GlassesSettings.fieldOfView, TiltFive.SplitStereoCamera.glassesMirrorMode, TiltFive.DisplaySettings.monoWidthToHeightRatio, TiltFive.GlassesSettings.nearClipPlane, TiltFive.SplitStereoCamera.previousMirrorMode, TiltFive.SplitStereoCamera.scaleToUGBD_UWRLD, TiltFive.SplitStereoCamera.spectatorCamera, TiltFive.SplitStereoCamera.splitStereoTextures, TiltFive.SplitStereoCamera.startedMirroringToOnscreenPreview, TiltFive.DisplaySettings.stereoWidthToHeightRatio, and TiltFive.SplitStereoTextures.ValidateNativeTexturePointers().

◆ OnRenderImage()

void TiltFive.SplitStereoCamera.OnRenderImage ( RenderTexture  src,
RenderTexture  dst 
)
private

Apply post-processing effects to the final image before it is presented.

Parameters
srcThe source render texture.
dstThe destination render texture.

Definition at line 578 of file SplitStereoCamera.cs.

579  {
580  // If we're not supposed to spectate due to the spectated player being set to None
581  // or to a player that isn't connected, have the first SplitStereoCamera attached to
582  // the SpectatorCamera perform a blit.
583  // TODO: Consider adding a spectator setting to define fallback behavior when the specified player isn't connected.
584  // The current behavior is indistinguishable from the PlayerIndex.None case, and perhaps it'd be desirable
585  // to spectate the next available player instead, if there is one?
586  if (spectatorSettings.spectatedPlayer == PlayerIndex.None || !Player.IsConnected(spectatorSettings.spectatedPlayer))
587  {
588  var splitStereoCameras = spectatorCamera.GetComponents<SplitStereoCamera>();
589  if(splitStereoCameras != null && splitStereoCameras.Length > 0 // These two checks should be redundant
590  && splitStereoCameras[0].Equals(this)) // This is the important one
591  {
592  Graphics.Blit(src, null as RenderTexture);
593  return;
594  }
595  // Any SplitStereoCameras that call OnRenderImage after the first one should return, otherwise they'll clear the screen
596  return;
597  }
598 
599  if(!UseSpectatorCamera)
600  {
601  return;
602  }
603 
605  {
607 
608  var previewTex = glassesMirrorMode == GlassesMirrorMode.Stereoscopic
611 
612  // Blitting is required when overriding OnRenderImage().
613  // Setting the blit destination to null is the same as blitting to the screen backbuffer.
614  // This will effectively render previewTex to the screen.
615  Graphics.Blit(previewTex,
616  null as RenderTexture,
617  Vector2.one,
618  Vector2.zero);
619  }
620  else Graphics.Blit(src, null as RenderTexture);
621 
622  // We're done with our letterboxing/pillarboxing now that we've blitted to the screen.
623  // If the SplitStereoCamera gets disabled next frame, ensure that the original behavior returns.
624  spectatorSettings.ResetSpectatorCamera();
625  }
PlayerIndex spectatedPlayer
The player that will have their perspective mirrored on screen.
void SubmitPreviewTextures(GlassesMirrorMode glassesMirrorMode)
Copies frame data from the HDR input textures to the onscreen preview textures.
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)

References TiltFive.SplitStereoCamera.glassesMirrorMode, TiltFive.Player.IsConnected(), TiltFive.SplitStereoTextures.MonoPreviewTex, TiltFive.SpectatorSettings.spectatedPlayer, TiltFive.SplitStereoCamera.spectatorCamera, TiltFive.SplitStereoCamera.splitStereoTextures, TiltFive.SplitStereoTextures.StereoPreviewTex, and TiltFive.SplitStereoTextures.SubmitPreviewTextures().

◆ OnValidate()

void TiltFive.SplitStereoCamera.OnValidate ( )
private

EDITOR-ONLY

Definition at line 704 of file SplitStereoCamera.cs.

705  {
706 
707 #if UNITY_EDITOR
708  if (false == UnityEditor.EditorApplication.isPlaying)
709  return;
710 #endif
711  if (null == spectatorCamera)
712  return;
713 
714  if (null != leftEye && null != rightEye)
715  ShowHideCameras();
716 
718  SyncTransform();
719  }

References TiltFive.SplitStereoCamera.cameraTemplate, TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.rightEye, TiltFive.SplitStereoCamera.ShowHideCameras(), TiltFive.SplitStereoCamera.spectatorCamera, TiltFive.SplitStereoCamera.SyncFields(), and TiltFive.SplitStereoCamera.SyncTransform().

◆ PresentStereoImages()

void TiltFive.SplitStereoCamera.PresentStereoImages ( )
private

Definition at line 641 of file SplitStereoCamera.cs.

642  {
643  splitStereoTextures.GetNativeTexturePointers(out var leftTexHandle, out var rightTexHandle);
644 
645  var leftTargetTex = splitStereoTextures.LeftTexture_GLS;
646  var rightTargetTex = splitStereoTextures.RightTexture_GLS;
647 
648  bool isSrgb = leftTargetTex.sRGB;
649 
650  Vector3 posOfULVC_UWRLD = leftEyeCamera.transform.position;
651  Quaternion rotToUWRLD_ULVC = leftEyeCamera.transform.rotation;
652  Vector3 posOfURVC_UWRLD = rightEyeCamera.transform.position;
653  Quaternion rotToUWRLD_URVC = rightEyeCamera.transform.rotation;
654 
655  Vector3 posOfULVC_UGBD = rotToUGBD_UWRLD * (scaleToUGBD_UWRLD * (posOfULVC_UWRLD - posUGBD_UWRLD));
656  Quaternion rotToUGBD_ULVC = rotToUGBD_UWRLD * rotToUWRLD_ULVC;
657 
658  Vector3 posOfURVC_UGBD = rotToUGBD_UWRLD * (scaleToUGBD_UWRLD * (posOfURVC_UWRLD - posUGBD_UWRLD));
659  Quaternion rotToUGBD_URVC = rotToUGBD_UWRLD * rotToUWRLD_URVC;
660 
661 
662  Display.PresentStereoImages(glassesHandle,
663  leftTexHandle, rightTexHandle,
664  leftTargetTex.width, rightTargetTex.height,
665  isSrgb,
666  glassesSettings.fieldOfView,
667  DisplaySettings.monoWidthToHeightRatio,
668  rotToUGBD_ULVC,
669  posOfULVC_UGBD,
670  rotToUGBD_URVC,
671  posOfURVC_UGBD);
672  }
Quaternion rotToUGBD_UWRLD
The rotation taking points from the Unity world-space reference frame to the game board reference fra...
Vector3 posUGBD_UWRLD
The position of the game board reference frame w.r.t. the Unity world-space reference frame.
void GetNativeTexturePointers(out IntPtr leftTexHandle, out IntPtr rightTexHandle)
Acquires the native output textures upon startup or invalidaiton.

References TiltFive.GlassesSettings.fieldOfView, TiltFive.SplitStereoTextures.GetNativeTexturePointers(), TiltFive.SplitStereoCamera.leftEyeCamera, TiltFive.SplitStereoTextures.LeftTexture_GLS, TiltFive.DisplaySettings.monoWidthToHeightRatio, TiltFive.SplitStereoCamera.posUGBD_UWRLD, TiltFive.Display.PresentStereoImages(), TiltFive.SplitStereoCamera.rightEyeCamera, TiltFive.SplitStereoTextures.RightTexture_GLS, TiltFive.SplitStereoCamera.rotToUGBD_UWRLD, TiltFive.SplitStereoCamera.scaleToUGBD_UWRLD, and TiltFive.SplitStereoCamera.splitStereoTextures.

Referenced by TiltFive.SplitStereoCamera.PresentStereoImagesCoroutine().

◆ PresentStereoImagesCoroutine()

IEnumerator TiltFive.SplitStereoCamera.PresentStereoImagesCoroutine ( )
private

Definition at line 627 of file SplitStereoCamera.cs.

628  {
629  // WaitForEndOfFrame() will let us wait until the last possible moment to send frames to the glasses.
630  // This allows the results of rendering, postprocessing, and even GUI to be displayed.
631  var cachedWaitForEndOfFrame = new WaitForEndOfFrame();
632 
633  while (enabled)
634  {
635  yield return cachedWaitForEndOfFrame;
636 
638  }
639  }

References TiltFive.SplitStereoCamera.PresentStereoImages().

Referenced by TiltFive.SplitStereoCamera.OnEnable().

◆ ShowHideCameras()

void TiltFive.SplitStereoCamera.ShowHideCameras ( )
private

Show/hide to the eye camerasin the hierarchy.

Definition at line 724 of file SplitStereoCamera.cs.

725  {
726  if (showCameras)
727  {
728  leftEye.hideFlags = HideFlags.None;
729  rightEye.hideFlags = HideFlags.None;
730  }
731  else
732  {
733  leftEye.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
734  rightEye.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
735  }
736  }
bool showCameras
In-editor toggle for displaying the eye cameras in the runtime Hierarchy.

References TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.rightEye, and TiltFive.SplitStereoCamera.showCameras.

Referenced by TiltFive.SplitStereoCamera.Initialize(), and TiltFive.SplitStereoCamera.OnValidate().

◆ SyncFields()

void TiltFive.SplitStereoCamera.SyncFields ( Camera  theCamera)
private

Syncs the Cameras' fields to the input parameter.

Parameters
theCameraThe camera to read from.

Definition at line 678 of file SplitStereoCamera.cs.

679  {
680  if(theCamera == null)
681  {
682  return;
683  }
684  if(leftEyeCamera != null)
685  {
686  leftEyeCamera.fieldOfView = theCamera.fieldOfView;
687  leftEyeCamera.nearClipPlane = theCamera.nearClipPlane;
688  leftEyeCamera.farClipPlane = theCamera.farClipPlane;
689  leftEyeCamera.aspect = DisplaySettings.monoWidthToHeightRatio;
690  }
691  if(rightEyeCamera != null)
692  {
693  rightEyeCamera.fieldOfView = theCamera.fieldOfView;
694  rightEyeCamera.nearClipPlane = theCamera.nearClipPlane;
695  rightEyeCamera.farClipPlane = theCamera.farClipPlane;
696  rightEyeCamera.aspect = DisplaySettings.monoWidthToHeightRatio;
697 
698  }
699  }

References TiltFive.SplitStereoCamera.leftEyeCamera, TiltFive.DisplaySettings.monoWidthToHeightRatio, and TiltFive.SplitStereoCamera.rightEyeCamera.

Referenced by TiltFive.SplitStereoCamera.Initialize(), and TiltFive.SplitStereoCamera.OnValidate().

◆ SyncTransform()

void TiltFive.SplitStereoCamera.SyncTransform ( )
private

EDITOR-ONLY: Syncs the eye Cameras' transform to the Head Pose when tracking is not available.

Definition at line 356 of file SplitStereoCamera.cs.

357  {
358 
359 #if UNITY_EDITOR
360  // We move the eye Cameras in the Editor to emulate head pose and eye movement.
361  // In builds, we only set the camera transforms with Glasses tracking data.
362 
363  if (null == cameraTemplate)
364  return;
365 
366  if (!Glasses.updated)
367  {
368  GameObject pose = headPose;
369  // left eye copy and adjust
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;
375  leftEye.transform.Translate(-leftEye.transform.right.normalized * (cameraTemplate.stereoSeparation * 0.5f));
376 
377  //right eye copy and adjust
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;
382  rightEye.transform.localScale = headPose.transform.localScale;
383  rightEye.transform.Translate(rightEye.transform.right.normalized * (cameraTemplate.stereoSeparation * 0.5f));
384  }
385 #endif
386  }

References TiltFive.SplitStereoCamera.cameraTemplate, TiltFive.SplitStereoCamera.headPose, TiltFive.SplitStereoCamera.leftEye, TiltFive.SplitStereoCamera.rightEye, and TiltFive.Glasses.updated.

Referenced by TiltFive.SplitStereoCamera.Initialize(), and TiltFive.SplitStereoCamera.OnValidate().

Member Data Documentation

◆ displayBlitShader

Material TiltFive.SplitStereoCamera.displayBlitShader
private

The Material used to store/reference the shader.

Definition at line 155 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.Initialize().

◆ eyeCameras

Dictionary<AREyes, Camera> TiltFive.SplitStereoCamera.eyeCameras
private
Initial value:
= new Dictionary<AREyes, Camera>()
{
{ AREyes.EYE_LEFT, null },
{ AREyes.EYE_RIGHT, null }
}

The Camera objects.

Definition at line 128 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.GenerateEyeCameras(), and TiltFive.SplitStereoCamera.InstantiateEyeCameras().

◆ headPose

GameObject TiltFive.SplitStereoCamera.headPose = null

◆ LEFT_EYE_CAMERA_NAME

const string TiltFive.SplitStereoCamera.LEFT_EYE_CAMERA_NAME = "Left Eye Camera"
staticprivate

The name assigned to the dynamically created camera used for rendering the left eye.

Definition at line 112 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.GenerateEyeCameras(), and TiltFive.SplitStereoCamera.InstantiateEyeCameras().

◆ leftEye

GameObject TiltFive.SplitStereoCamera.leftEye
private

◆ posUGBD_UWRLD

Vector3 TiltFive.SplitStereoCamera.posUGBD_UWRLD = Vector3.zero

The position of the game board reference frame w.r.t. the Unity world-space reference frame.

Definition at line 138 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.PresentStereoImages(), and TiltFive.Glasses.GlassesCore.Update().

◆ presentStereoImagesCoroutine

IEnumerator TiltFive.SplitStereoCamera.presentStereoImagesCoroutine
private

◆ previousMirrorMode

GlassesMirrorMode TiltFive.SplitStereoCamera.previousMirrorMode = GlassesMirrorMode.LeftEye
private

Definition at line 158 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.OnPreRender().

◆ RIGHT_EYE_CAMERA_NAME

const string TiltFive.SplitStereoCamera.RIGHT_EYE_CAMERA_NAME = "Right Eye Camera"
staticprivate

The name assigned to the dynamically created camera used for rendering the right eye.

Definition at line 119 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.GenerateEyeCameras(), and TiltFive.SplitStereoCamera.InstantiateEyeCameras().

◆ rightEye

GameObject TiltFive.SplitStereoCamera.rightEye
private

◆ rotToUGBD_UWRLD

Quaternion TiltFive.SplitStereoCamera.rotToUGBD_UWRLD = Quaternion.identity

The rotation taking points from the Unity world-space reference frame to the game board reference frame.

Definition at line 144 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.PresentStereoImages(), and TiltFive.Glasses.GlassesCore.Update().

◆ scaleToUGBD_UWRLD

float TiltFive.SplitStereoCamera.scaleToUGBD_UWRLD = 1.0f

The uniform scale factor that takes points from the Unity world-space to the game board reference frame.

Definition at line 150 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.OnPreRender(), TiltFive.SplitStereoCamera.PresentStereoImages(), and TiltFive.Glasses.GlassesCore.Update().

◆ SHADER_DISPLAY_BLIT

const string TiltFive.SplitStereoCamera.SHADER_DISPLAY_BLIT = "Tilt Five/Simple Blend Shader"
staticprivate

The name of the custom shader that blits the rendertextures to the backbuffer.

Definition at line 153 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.Initialize().

◆ showCameras

bool TiltFive.SplitStereoCamera.showCameras = true

In-editor toggle for displaying the eye cameras in the runtime Hierarchy.

Definition at line 126 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.ShowHideCameras().

◆ splitStereoTextures

SplitStereoTextures TiltFive.SplitStereoCamera.splitStereoTextures = new SplitStereoTextures()
private

◆ startedMirroringToOnscreenPreview

bool TiltFive.SplitStereoCamera.startedMirroringToOnscreenPreview = false
private

◆ useSpectatorCamera

bool TiltFive.SplitStereoCamera.useSpectatorCamera
private

Definition at line 93 of file SplitStereoCamera.cs.

Referenced by TiltFive.SplitStereoCamera.Awake().

Property Documentation

◆ aspectRatio

float TiltFive.SplitStereoCamera.aspectRatio
getset

The Cameras' aspect ratio property.

Definition at line 191 of file SplitStereoCamera.cs.

192  {
193  get { return spectatorCamera.aspect; }
194  set { spectatorCamera.aspect = value; }
195  }

◆ cameraTemplate

Camera TiltFive.SplitStereoCamera.cameraTemplate
get

◆ farClipPlane

float TiltFive.SplitStereoCamera.farClipPlane
getset

The Cameras' far clip plane property.

Definition at line 183 of file SplitStereoCamera.cs.

184  {
185  get { return spectatorCamera.farClipPlane; }
186  set { rightEyeCamera.farClipPlane = leftEyeCamera.farClipPlane = spectatorCamera.farClipPlane = value; }
187  }

◆ fieldOfView

float TiltFive.SplitStereoCamera.fieldOfView
getset

The Cameras' field of view property.

Definition at line 167 of file SplitStereoCamera.cs.

168  {
169  get { return spectatorCamera.fieldOfView; }
170  set { rightEyeCamera.fieldOfView = leftEyeCamera.fieldOfView = spectatorCamera.fieldOfView = value; }
171  }

◆ glassesMirrorMode

GlassesMirrorMode TiltFive.SplitStereoCamera.glassesMirrorMode
getprivate

◆ leftEyeCamera

Camera TiltFive.SplitStereoCamera.leftEyeCamera
get

◆ nearClipPlane

float TiltFive.SplitStereoCamera.nearClipPlane
getset

The Cameras' near clip plane property.

Definition at line 175 of file SplitStereoCamera.cs.

176  {
177  get { return spectatorCamera.nearClipPlane; }
178  set { rightEyeCamera.nearClipPlane = leftEyeCamera.nearClipPlane = spectatorCamera.nearClipPlane = value; }
179  }

◆ rightEyeCamera

Camera TiltFive.SplitStereoCamera.rightEyeCamera
get

◆ spectatorCamera

Camera TiltFive.SplitStereoCamera.spectatorCamera
getprivate

The documentation for this class was generated from the following file: